views:

138

answers:

2

Hi,

I have an asp.net c# web app with a gridview inside it. I wanted to handle gridview_rowediting, so this is what I have so far:

    protected void grid_RowEditing(object sender, GridViewEditEventArgs e)
    {
        grid.EditIndex = e.NewEditIndex;
        grid.DataBind();
    }

The grid displays search results from a database on the web page. I thought this would work, but what this does is it shows me the EmptyDataText and if I click the search button again, it then shows me the row in the 'edit mode'. Why does it do this? please help Thank you.

+1  A: 

What is calling the Row Edit? If it is something like a Button, just set its CommandName to Edit. You do not need to handle Row Editing unless you are doing something other than setting the edit index.

Matthew Jones
A: 

Don't forget to assign data source to your grid before binding it :

protected void grid_RowEditing(object sender, GridViewEditEventArgs e)
{
    grid.EditIndex = e.NewEditIndex;
    grid.DataSource = GetDataSource();
    grid.DataBind();
}
Canavar