c# - Unable to cast object of type System.Web.UI.WebControls.Label to type System.IConvertible -


this gridview 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>                 &nbsp;|                     <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" />     <sortedascendingheaderstyle backcolor="gray" />     <sorteddescendingcellstyle backcolor="#cac9c9" />     <sorteddescendingheaderstyle backcolor="#383838" /> </asp:gridview> 

this c# code:

protected void lnkbtnedit_click(object sender, eventargs e) {     gridviewrow gridviewrow = (gridviewrow)(sender 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, have tried changing line

int codelabel =convert.toint32(code_label); 

to

int codelabel =convert.toint32(code_label.text); 

this removes error no data of employee carried page edit_employee.aspx when edit button clicked in gridview appreciated. in advance.

i know want redirect user edit employee page employee code. suggest use anchor tag instead of linkbutton. try below code easy integrate , prevent server request , response.

your edit link button:

<asp:linkbutton id="lnkbtnedit" runat="server" onclick="lnkbtnedit_click">                 edit</asp:linkbutton> 

replace this:

<a href='<%# "forms/new_employee/employees/edit_employee.aspx?selected_employee=" + eval("[employee code]") %>'>edit</a> 

what did here, have passed employee code in query string instead of session, can retrieve query string variable in edit_employee page using below code:

int liemployeecode = convert.toint32(request.querystring["selected_employee"]); 

please let me know if have questions.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -