asp.net - How to get the data of a specific row on a GridView on behind code and pass it to another webform -
asp.net - How to get the data of a specific row on a GridView on behind code and pass it to another webform -
i have code show below. click edit button , in code behind row number how values of fields? want pass info of fields page ? , best way pass values of fields webform : "secondpage.aspx?id=" + id or using session or there improve way?
.aspx code
<asp:gridview id="gridview1" runat="server" allowpaging="true" autogeneratecolumns="false" pagesize="100"> <columns> <asp:templatefield headertext="edit"> <itemtemplate> <asp:hyperlink id="hyperlink1" runat="server" navigateurl='<%# "vformreport2.aspx?id=" & ctype(databinder.eval(container.dataitem, "fldemployeeid"), string)%>' text="edit" /> </itemtemplate> </asp:templatefield> <asp:boundfield datafield="fldemployeeid" headertext="employeeid" /> <asp:boundfield datafield="fldabsentdate" headertext="absentdate" /> <asp:boundfield datafield="fldabsentcode" headertext="absentcode" /> <asp:boundfield datafield="fldruleviolationwarningtype" headertext="rule violation warning" /> <asp:boundfield datafield="fldruleviolationissuedate" headertext="rule violation issue date" /> <asp:boundfield datafield="fldloaenddate" headertext="loa end date" /> </columns>
.cs code
protected sub page_load(byval sender object, byval e system.eventargs) handles me.load if sds2.text = "0" dim sqldatasource1 sqldatasource = new sqldatasource() sqldatasource1.id = "sqldatasource1" page.controls.add(sqldatasource1) sqldatasource1.connectionstring = "your string here " 'sqldatasource1.selectcommand = "select * [tblabsences] [fldemployeeid]=38" sqldatasource1.selectcommand = "select * [tblabsences] order [fldemployeeid], [fldabsentdate], [fldabsentcode]" gridview1.datasource = sqldatasource1 gridview1.databind() else dim sqldatasource2 sqldatasource = new sqldatasource() sqldatasource2.id = "sqldatasource2" page.controls.add(sqldatasource2) sqldatasource2.connectionstring = "your string here" sqldatasource2.selectcommand = "select * [tblabsences] [fldabsentdate] between '7-03-2014' , '8-21-2014' order [fldemployeeid]" 'sqldatasource2.selectcommand = "select * [tblabsences] order [fldemployeeid], [fldabsentdate], [fldabsentcode]"; gridview1.datasource = sqldatasource2 gridview1.databind() sqldatasource2click = true end if end sub protected sub gridview1_pageindexchanging(byval sender object, byval e gridviewpageeventargs) handles gridview1.pageindexchanging gridview1.pageindex = e.newpageindex gridview1.databind() end sub protected sub button1_click(sender object, e eventargs) handles button1.click dim int integer = 0 session("counter") = convert.tostring(int) if session("counter") = "0" gridview1.pageindex = 0 end if sds2.text = "1" dim sqldatasource2 sqldatasource = new sqldatasource() sqldatasource2.id = "sqldatasource2" page.controls.add(sqldatasource2) sqldatasource2.connectionstring = "your string here" sqldatasource2.selectcommand = "select * [tblabsences] [fldabsentdate] between '7-03-2014' , '8-21-2014' order [fldemployeeid]" 'sqldatasource2.selectcommand = "select * [tblabsences] order [fldemployeeid], [fldabsentdate], [fldabsentcode]"; gridview1.datasource = sqldatasource2 gridview1.databind() end sub
ok, want edit employee record. i'm assuming gridview subset of employee data, want retrieve entire record in form redirect to, need pass fldemployeeid. alter edit command hyperlink pass fldemployeeid form:-
<asp:templatefield headertext="edit"> <itemtemplate> <asp:hyperlink runat="server" navigateurl='<%# "vformreport2.aspx?id=" & ctype(databinder.eval(container.dataitem, "fldemployeeid"), string)%>' text="edit" /> </itemtemplate> </asp:templatefield>
there no need rowindex or code-behind (which vb, way). using hyperlink lot quicker postback row command.
asp.net vb.net gridview webforms
Comments
Post a Comment