Hello.
I am wondering how I can edit a selected row (by a link button) by showing the cell values in textboxes.
I have this code so far.ASP.NET-----------------
<!--Invisible textboxes for editing-->
<div id="div1" runat="server" visible="false">
<table cellpadding="2" cellspacing="1" class="cont-table">
<tr>
<td class="header" style="width:150px;">Leave Type</td>
<td class="cont" style="padding:5px; width:300px;">
<asp:Textbox ID="txtLeaveType" runat="server" AutoPostBack="false" Font-Size="12px" Enabled="False" Width="290px">
</asp:Textbox>
</td>
<td class="header" style="width:150px;"> Application Date</td>
<td class="cont" style="padding:5px;">
<asp:TextBox ID="txtEffAppDate" runat="server" Font-Size="12px" Enabled="False" Width="150"></asp:TextBox>
</td>
</tr>
</table>
<!--grid view-->
<asp:GridView ID="EmpLeaveAppGV1" CssClass="datagrid gridfont" runat="server" AutoGenerateColumns="False" GridLines="none"
CellPadding="4" ForeColor="#333333" EmptyDataText= "No current record found in the database." Width="868px" OnRowCommand="GridViewRowCommand"><%--OnRowDeleting="EmpLeaveAppGV1_SelectedIndexChanged"--%>
<SelectedRowStyle BackColor="#CCCCCC" Font-Bold="True" ForeColor="#333333" />
<Columns>
<asp:TemplateField HeaderStyle-BorderStyle="None" ItemStyle-Width="45" ItemStyle-CssClass="right-shadow" ItemStyle-HorizontalAlign="Center">
<Itemtemplate>
<asp:LinkButton ID ="lbtnEmpHist" ToolTip="Edit" CssClass="edit-item" runat="server" CommandName="EditPending" ForeColor="Blue"></asp:LinkButton>
<asp:LinkButton ID="lbtnEmpStatus" ToolTip="Delete" CssClass="delete-item" runat="server" CommandName="Delete" ForeColor="Aquamarine"></asp:LinkButton>
</Itemtemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Employee Name" HeaderStyle-HorizontalAlign="left" HeaderStyle-BorderStyle="None" ItemStyle-HorizontalAlign="left" ItemStyle-Width="160">
<ItemTemplate>
<asp:Label ID="lblEmpNameFull" runat="server" Text='<%# Bind("EmpNameFull") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
-----------------
C# Code Behind
------------
protected void GridViewRowCommand(Object sender, GridViewCommandEventArgs e)
{
if (e.CommandName=="EditPending")
{
int LeaveTranID = Convert.ToInt32(e.CommandArgument);
int rowindex = EmpLeaveAppGV1.SelectedIndex;
Label lblLeaveType = (Label)(EmpLeaveAppGV1).Rows[rowindex].FindControl("lblLeaveType");
txtLeaveType.Text = lblLeaveType.Text;
div1.Visible = true;
}
}
------------
And can someone explain to me what this line of code can do? plss make it specific, I cant understand the .Parent.Parent
using (GridViewRow row = (GridViewRow)((LinkButton)sender).Parent.Parent)
i just found this on the internet..
Any help would be so much appreciated.
Thanks and have a nice day!