This is the grid view code
<asp:GridView ID="gvwSearch" runat="server" AutoGenerateColumns="False" BackColor="White"
BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" DataSourceID="SearchSqlDataSource"
ForeColor="Black" GridLines="Vertical" Width="100%" Visible="False" AllowSorting="True"
AllowPaging="True" OnSelectedIndexChanged="gvwSearch_SelectedIndexChanged" OnPageIndexChanging ="gvwSearch_PageIndexChanging">
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkbtnEdit" runat="server" OnClick="lnkbtnEdit_Click">Edit</asp:LinkButton>
|
<asp:LinkButton ID="nkbtnView" runat="server" OnClick="nkbtnView_Click">View</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Employee Code" SortExpression="Employee Code" >
<EditItemTemplate>
<asp:TextBox ID="TextBox1" DataField="EmployeeCode" runat="server" Text='<%# Bind("[Employee Code]") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblCode" DataField="EmployeeCode" runat="server" Text='<%# Bind("[Employee Code]") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Full Name" HeaderText="Full Name" SortExpression="Full Name" />
<asp:BoundField DataField="CPR" HeaderText="CPR" SortExpression="CPR" />
<asp:BoundField DataField="Department" HeaderText="Department" SortExpression="Department" />
<asp:BoundField DataField="Designation" HeaderText="Designation" SortExpression="Designation" />
<asp:BoundField DataField="Nationality" HeaderText="Nationality" SortExpression="Nationality" />
<asp:BoundField DataField="Grade" HeaderText="Grade" SortExpression="Grade" />
<asp:BoundField DataField="Joining Date" HeaderText="Joining Date" SortExpression="Joining Date" />
<asp:BoundField DataField="Local Phone" HeaderText="Local Phone" SortExpression="Local Phone" />
<asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
<asp:BoundField DataField="End of Service" HeaderText="End of Service" ReadOnly="True"
SortExpression="End of Service" />
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="Gray" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
<SortedAscendingCellStyle BackColor="#F1F1F1"></SortedAscendingCellStyle>
<SortedAscendingHeaderStyle BackColor="Gray"></SortedAscendingHeaderStyle>
<SortedDescendingCellStyle BackColor="#CAC9C9"></SortedDescendingCellStyle>
<SortedDescendingHeaderStyle BackColor="#383838"></SortedDescendingHeaderStyle>
</asp:GridView>
And this is C# Code
protected void lnkbtnEdit_Click(object sender, EventArgs e)
{
GridViewRow gridViewRow = (GridViewRow)(sender as Control).Parent.Parent;
int index = gridViewRow.RowIndex;
Label Code_Label = (Label)(gvwSearch.Rows[index].FindControl("lblCode"));
int CodeLabel =Convert.ToInt32(Code_Label);//At thiline error occurs.
New_Employee Selected_Employee = new New_Employee(CodeLabel);
Session["Selected_Employee"] = Selected_Employee;
Response.Redirect("~/Forms/New_Employee/Employees/Edit_Employee.aspx");
}
Yes, I have tried by changing this line
int CodeLabel =Convert.ToInt32(Code_Label);
To
int CodeLabel =Convert.ToInt32(Code_Label.Text);
This removes the error but no data of the employee is carried from this page to Edit_Employee.aspx When the Edit button clicked in the GridView
Any help would be appreciated. Thanks in Advance.