Introduction:
In this artcle we will discuss about how to edit gridview rows.
Main:
In Gridview,normally we used OnRowEditing Method for editing rows,
The Common syntax for editing gridview row is,
<asp:GridView OnRowEditing=”GridViewEditEventHandler” />
Add,one gridview with rowediting declaration,
<asp:gridview id=”SampleGridView”
datasourceid=”sample”
autogeneratecolumns=”true”
autogenerateeditbutton=”true”
allowpaging=”true”
datakeynames=”ID”
onrowediting=”GridView_RowEditing”
runat=”server”>
</asp:gridview>
In GridView_RowEditing method,
public void GridView_RowEditing(Object sender, GridViewEditEventArgs e)
{
String name = SampleGridView.Rows[e.NewEditIndex].Cells[6].Text;
//We allowed users to edit if the condition is true
if (name == “Jimmy”)
{
SampleGridView.EditIndex = e.NewEditIndex;
BindData();
}
else
{
e.cancel=true;
}
}
Conclusion:
Hope,this helps,
Happy Coding.
Well, I think that clears up a couple of issues for me personally. How about anybody else?