MSSexpert
asked on
Gridview Control Edit Mode requires Pressing Edit Button Twice
Hi all..
I have a GridView control in an ASP.NET 2.0 page. I added a column that
contains edit, update, cancel buttons. Because I did that, I had to handle
RowEditing event or an exception was thrown.
Well... this is the body of the RowEditing event:
protected void gvParametros_RowEditing(ob ject sender, GridViewEditEventArgs
e)
{
gvParametros.EditIndex = e.NewEditIndex;
}
The fact is that when page is loaded and I click the edit link, page is
refreshed but GridView doesn't enter edit mode. When I press edit link
again, GridView enters edit mode.
any help to solve this behavior would be greatly appreciated
I have a GridView control in an ASP.NET 2.0 page. I added a column that
contains edit, update, cancel buttons. Because I did that, I had to handle
RowEditing event or an exception was thrown.
Well... this is the body of the RowEditing event:
protected void gvParametros_RowEditing(ob
e)
{
gvParametros.EditIndex = e.NewEditIndex;
}
The fact is that when page is loaded and I click the edit link, page is
refreshed but GridView doesn't enter edit mode. When I press edit link
again, GridView enters edit mode.
any help to solve this behavior would be greatly appreciated
ASKER
Yes, you'd think that that is how it would work (rebinding).I am a total newbie at C#/ASP.Net BTW so be gentle with me.
I tried as you suggested and it calls "Page_PreRender" and the Gridview disappears from the screen when it exits the Page_PreRender Event. The Page.IsPostBack property is true.
protected void Page_PreRender(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
}
}
// Editing mode
protected void GridView1_RowEditing(objec t sender, GridViewEditEventArgs e)
{
GridView1.DataBind();
GridView1.EditIndex = e.NewEditIndex;
}
private void BindData()
{
GridView1.DataSource = dataExp;
GridView1.DataMember = "EXPENSE";
GridView1.DataBind();
}
I tried as you suggested and it calls "Page_PreRender" and the Gridview disappears from the screen when it exits the Page_PreRender Event. The Page.IsPostBack property is true.
protected void Page_PreRender(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
}
}
// Editing mode
protected void GridView1_RowEditing(objec
{
GridView1.DataBind();
GridView1.EditIndex = e.NewEditIndex;
}
private void BindData()
{
GridView1.DataSource = dataExp;
GridView1.DataMember = "EXPENSE";
GridView1.DataBind();
}
protected void GridView1_RowEditing(objec t sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
BindData();
}
{
GridView1.EditIndex = e.NewEditIndex;
BindData();
}
ASKER
I changed the sequeence as suggested to:
protected void GridView1_RowEditing(objec t sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
BindData();
}
No change in result (i.e. Grid still dissapeared)
protected void GridView1_RowEditing(objec
{
GridView1.EditIndex = e.NewEditIndex;
BindData();
}
No change in result (i.e. Grid still dissapeared)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for that. The dataexp was being cleared so obviously things were a bit of a mess. I took a deep breath scrapped the entire class and rewrote the code and it worked first time. Thanks Again
protected void gvParametros_RowEditing(ob
e)
{
gvParametros.DataBind()
gvParametros.EditIndex = e.NewEditIndex;
}