Showing posts with label CommandName. Show all posts
Showing posts with label CommandName. Show all posts

Sunday, June 01, 2008

GridView Row Delete

How do retrieve the DataKey value from the Gridview ?
Please ensure your Gridview had DataKeyName properites setting.
OnRowCommand[ I set DeleMe method] event of the Gridview assign your method name.
This method takes Object and GridViewRowCommand as parameter to perform the task.
Example,If you want to delete a selected row from the Gridview,add the Linkbutton and text the "Remove" and its CommandName must be non than "Delete" and its CommandArgument,you can assign the primary key column value as <%#Eval("ecode")%>.
This LinkButton should be resides under Gridview's TemplateField and ItemTemplate.

My code goes like this..
protected void DeleMe(object sender, GridViewCommandEventArgs g)
{
if (g.CommandName == "Remove")
{
string ecode = g.CommandArgument.ToString();

Response.Write(ecode);
}


}