Monday, March 14, 2016

GridView Row Command

GridviewRowCommand is very useful event of Gridview. User can delete,view details or something else need to do with the selected Item Row within the gridview.

before need to do with rowCommand event, Grid should contain the item template with rowIndex item

<asp:Label id="lnkDocNo" runat="server" Text='<%# Container.DataItemIndex + 1 %>' ></asp:Label>

<asp:LinkButton id="lnkDocNo" runat="server" Text='<%# Eval("DocNo")%>' CommandName ="V" CommandArgument="<%# ((GridViewRow)Container).RowIndex%>"></asp:LinkButton>

on row command property of gridview

event handler of GridView is powerful property of gridview to do various action or to play with data .

protected void onRowCommand(object sender, GridViewCommandEventArgs e)
    {
        int rowIndex = Convert.ToInt16(e.CommandArgument);
        LinkButton lnkDocNo = (LinkButton)GridView.Rows[rowIndex].FindControl("lnkDocNo");

        if (e.CommandName == "V")
        {
           //do the Action with the Data here.
        }
    }

No comments:

Post a Comment