asp.net - Gridview RowCommand not working -
i having problems trying rowcommand event fire in gridview. followed code example msdnet cannot figure out why not working. code below. thank you.
<asp:gridview id="gridviewproducts" runat="server" autogeneratecolumns="false" backcolor="white" bordercolor="#999999" borderstyle="solid" borderwidth="1px" cellpadding="5" cellspacing="1" datakeynames="pkey" datasourceid="sqldatasourceproducts" forecolor="black" gridlines="vertical"> <footerstyle backcolor="#cccccc" /> <pagersettings pagebuttoncount="20" /> <columns> <asp:boundfield datafield="product" headertext="product" > <headerstyle horizontalalign="left" /> <itemstyle horizontalalign="left" /> </asp:boundfield> <asp:templatefield headertext="interest"> <itemtemplate> <asp:dropdownlist id="ddlproductinterest" runat="server" selectedvalue='<%# bind("productinterest") %>'> <asp:listitem></asp:listitem> <asp:listitem>low</asp:listitem> <asp:listitem>medium</asp:listitem> <asp:listitem>high</asp:listitem> <asp:listitem>none</asp:listitem> </asp:dropdownlist> </itemtemplate> </asp:templatefield> <asp:templatefield headertext=""> <itemtemplate> <asp:button runat="server" id="testbutton" text="button" commandname="test" commandargument="<%# ctype(container, gridviewrow).rowindex %>" /> </itemtemplate> <headerstyle horizontalalign="center" /> <itemstyle horizontalalign="center" /> </asp:templatefield> </columns> <pagerstyle backcolor="#999999" forecolor="black" horizontalalign="center" /> <selectedrowstyle backcolor="#000099" font-bold="true" forecolor="white" /> <headerstyle backcolor="silver" font-bold="true" forecolor="black" /> <alternatingrowstyle backcolor="#cccccc" /> </asp:gridview> ++code behind +++ sub gridviewproducts_rowcommand(byval sender object, byval e gridviewcommandeventargs) if e.commandname = "test" dim index = convert.toint32(e.commandargument) dim row = gridviewproducts.rows(index) dim mystring string = row.cells(0).text strsql = "insert tblclosedproducts (" & _ "product, closedby, dateclosed " & _ ") values (" & _ "@product, @closedby, @dateclosed " & _ ")" dim myparameters1 sqlparameter() = { _ new sqlparameter("@product", sqldbtype.varchar), _ new sqlparameter("@closedby", sqldbtype.varchar), _ new sqlparameter("@dateclosed", sqldbtype.smalldatetime) _ } myparameters1(0).value = row.cells(0).text myparameters1(1).value = getinfo.getfullname(ucase(right(httpcontext.current.user.identity.name.tostring(), 4))) myparameters1(2).value = dateadd("h", -1, now()) objdata.sqlexecutenonquery(strsql, commandtype.text, myparameters1) end if end sub
your gridview doesnt have event wired in markup.
try adding in onrowcommand="gridviewproducts_rowcommand"
looks this:
<asp:gridview id="gridviewproducts" runat="server" autogeneratecolumns="false" backcolor="white" bordercolor="#999999" borderstyle="solid" borderwidth="1px" cellpadding="5" cellspacing="1" datakeynames="pkey" datasourceid="sqldatasourceproducts" forecolor="black" gridlines="vertical" onrowcommand="gridviewproducts_rowcommand">
Comments
Post a Comment