Reputation: 3
I am trying to create an editable DataGridView and I have enabled the "AutoGenerateEditButton
" to true but when i click the edit on the page it throws this excetion
"System.Web.HttpException: The GridView 'GridView1' fired event RowEditing which wasn't handled."
Any ideas why? The code that I am using is below
I would also like to know how i would be able to update the edited value into the datatable so its updated.
<asp:GridView ID="GridView1" runat="server" AutoGenerateEditButton="True" Width="1060px">
</asp:GridView>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
add();
}
}
private void add()
{
DataTable dt = new DataTable();
dt.Columns.Add("ab", typeof(string));
dt.Columns.Add("ac", typeof(string));
dt.Columns.Add("av", typeof(string));
dt.Columns.Add("ax", typeof(string));
DataRow row = dt.NewRow();
row["ac"] = "sndasbfb";
row["av"] = "sndasbfb";
row["av"] = "sndasbfb";
row["ax"] = "sndasbfb";
dt.Rows.Add(row);
GridView1.DataSource = dt;
GridView1.DataBind();
}
Upvotes: 0
Views: 635
Reputation: 2000
Add a onrowediting event..
<asp:GridView ID="GridView1" runat="server" AutoGenerateEditButton="True"
Width="1060px" Onrowediting="Gridview_rowediting">
</asp:GridView>
protected void Gridview_rowediting(object sender, GridViewEditEventArgs e)
{
}
TO update the gridview add onrowupdating event..
protected void Gridview_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
update();
}
private void update()
{
DataTable dt = new DataTable();
dt.Columns.Add("ab", typeof(string));
dt.Columns.Add("ac", typeof(string));
dt.Columns.Add("av", typeof(string));
dt.Columns.Add("ax", typeof(string));
DataRow row = dt.NewRow();
row["ac"] = "newvalue";
row["av"] = "newvalue";
row["av"] = "newvalue";
row["ax"] = "newvalue";
dt.Rows.Add(row);
GridView1.DataSource = dt;
GridView1.DataBind();
}
Upvotes: 1
Reputation: 17614
As the error suggesting you have not handled the OnRowEditing="GridViewEditEventHandler"
event.
Which get triggered if the default edit link
is click on the gridview
You will need to handle OnRowEditing
as follows
<asp:GridView ID="GridView1" runat="server" OnRowEditing="GridView1_RowEditing"
AutoGenerateEditButton="True" Width="1060px">
</asp:GridView>
and In the code behind you will have to handle this event as follow
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
// GridView1.SelectedIndex = e.NewEditIndex;
//do your stuff here
add();
}
Upvotes: 0
Reputation: 2343
You need to add an Event for the RowEditing
Look here for further information: http://forums.asp.net/p/1144799/1850877.aspx#1850877
gvSalesEventSearch.RowEditing += new GridViewEditEventHandler(gvSalesEventSearch_RowEditing);
void gvSalesEventSearch_RowEditing(object sender, GridViewEditEventArgs e)
{
}
Upvotes: 0