asp.net - how to get item template value on asp datagridview -
i got datagridview :
<asp:gridview id="gvdata" runat="server" allowpaging="true" autogeneratecolumns="false" cellpadding="4" datakeynames="inquiryid" font-size="11px" forecolor="black" pagesize="20" width="100%" style="text-align: center" cssclass="zebra" alternatingrowstyle-cssclass="even"> <alternatingrowstyle cssclass="even" /> <columns> <asp:templatefield> <itemstyle horizontalalign="center" width="100px" /> <footerstyle horizontalalign="left" /> <itemtemplate> <asp:imagebutton id="imgbtn" imageurl="~/edit.jpg" runat="server" width="25" height="25" onclick="imgbtn_click" /> </itemtemplate> <edititemtemplate> </edititemtemplate> <footertemplate> </footertemplate> </asp:templatefield> <asp:templatefield headertext="no account"> <itemstyle horizontalalign="center" width="100px" /> <footerstyle horizontalalign="left" /> <itemtemplate> <asp:label id="lblnoaccount0" runat="server" text='<%# bind("inquiryaccount") %>'></asp:label> </itemtemplate> <edititemtemplate> </edititemtemplate> <footertemplate> </footertemplate> </asp:templatefield> <asp:templatefield headertext="language"> <itemstyle horizontalalign="center" width="50px" /> <footerstyle horizontalalign="left" /> <itemtemplate> <asp:label id="lblslottime" runat="server" text='<%# bind("inquirylang") %>'></asp:label> </itemtemplate> </asp:templatefield> <asp:templatefield headertext="amount"> <itemstyle horizontalalign="center" width="20px" /> <footerstyle horizontalalign="left" /> <itemtemplate> <asp:label id="lblinquiryamount" runat="server" text='<%# bind("inquiryamount") %>'></asp:label> </itemtemplate> </asp:templatefield> <asp:templatefield headertext="response"> <itemstyle horizontalalign="center" width="70px" /> <footerstyle horizontalalign="center" /> <itemtemplate> <asp:label id="lblresponse" runat="server" text='<%# bind("inquiryresponse") %>'></asp:label> </itemtemplate> </asp:templatefield> </columns> </asp:gridview> and want row value clicking image button, here's code :
protected sub imgbtn_click(byval sender object, byval e imageclickeventargs) dim btndetails imagebutton = trycast(sender, imagebutton) dim gvrow gridviewrow = directcast(btndetails.namingcontainer, gridviewrow) lblid.text = gvdata.datakeys(gvrow.rowindex).value.tostring() lblusername.text = gvrow.cells(1).text txtfname.text = gvrow.cells(2).text txtlname.text = gvrow.cells(3).text txtcity.text = gvrow.cells(4).text txtdesg.text = gvrow.cells(5).text me.pnlgrid_modalpopupextender.show() end sub but when debug it, gvdata.datakeys(gvrow.rowindex).value.tostring() value, others value give me empty string. whats wrong code??
you can use findcontrol method find control defined in template.
ie.
dim lblnoaccount0 label = directcast(gvrow.findcontrol("lblnoaccount0"), label) then can value of label expected.
lblusername.text = lblnoaccount0.text
Comments
Post a Comment