简体   繁体   中英

how to get values from gridview in asp.net web forms?

hello all i am new to asp.net and i want to get values from grid view when i click on Edit or Delete or and i don't know how to do it i am sending data table to show table data and i don't want to use SQL Data Source from Visual tool box.

     protected void dgv1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Edit")
        {
            int rowindex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex;
            dgv1.EditIndex = rowindex;
            dgv1.DataBind();
        }
    }
}

Try this:

LinkButton lnkBtn = (LinkButton)e.CommandSource;    // the button
GridViewRow gvRow = (GridViewRow)lnkBtn.Parent.Parent;    // the row

You may also get the data key index by adding DataKeyNames="MyTableKeyID" to the <asp:GridView /> tab, then

string selectedKeyIndex = this.GridView1.DataKeys[myRow.RowIndex]["MyTableKeyID"].ToString();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM