troubleshooting Question

Unable to get commandname in rowcommand,need to update using button in gridview control ,

Avatar of Rajar Ahmed
Rajar AhmedFlag for India asked on
.NET ProgrammingASP.NETVisual Basic.NET
6 Comments1 Solution703 ViewsLast Modified:
i need to simply update the table in database , with 1 and 0 respectively , but am not able to get the commandname in the rowcommand , when tested using msgbox commandname value returns null ...plz help me out..

<asp:Gridview id="gridview1" AutoGenerateColumns="false" BorderColor="#BCE9FE" align="center" DataKeyNames="id" AllowPaging="true" PageSize="20"  BorderStyle="Solid" BorderWidth="1px">
<asp:BoundField DataField="status" />
        <asp:TemplateField HeaderText="Show/Hide">
                   <asp:Button ID="btn_show"  runat="server" CommandArgument='<%# Eval("id") %>' />
Protected Sub gridview1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridview1.RowDataBound
 If e.Row.Cells(0).Text = "1" Then
                    btn_show.CommandName = "hide"
                    btn_show.CommandName = "show"
                End If
end if 
end if 
Protected Sub gridview1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gridview1.RowCommand
        MsgBox(e.CommandName) ' This Returns Nulll 
        If e.CommandName = "show" Then
            Dim Index As Integer = Convert.ToInt32(e.CommandArgument)
            cmd.commandtext="update test1 set status=1 where id=" + index
            cmd.commandtext="update test1 set status=0 where id=" + index
        End If
    End Sub

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros