D
Diane
Hi-
I've been struggling with this problem and none of the fixes posted
seem to help out at all. Yet, it seems like such a simple problem...
I have a DataGrid, and load it up with data on page load. In my
EditCommand event handler I set the editItemindex. All good. Except,
the user needs to click twice to get the DataGrid to become editable.
It's obvious to me (perhaps worngly) that ASP.NET is storing the data
form my grid in the viewstate, and setting up the datagrid BEFORE the
Edit button event. That's why the grid appears editable the next page
load.
So, how do I refresh the grid to show the editability? Predictably,
calling DataBind makes all the data go away... String the data set in
the session seems redundantg, since the page is definitely storing the
data for me in the viewstate. Not that I can get to it...
Any ideas?
Diane
<PRE>
private void Page_Load(object sender, System.EventArgs e)
{
if (this.IsPostBack == false)
{
sqlConnection1.ConnectionString = "..pubs..";
string query = "SELECT * FROM stores";
this.sqlDataAdapter1.SelectCommand.CommandText = query;
this.sqlDataAdapter1.SelectCommand.Connection =
sqlConnection1;
this.sqlConnection1.Open();
this.sqlDataAdapter1.Fill(this.dataSet1, "storesAll");
this.DataGrid1.DataSource =
this.dataSet1.Tables["storesAll"];
this.DataGrid1.DataBind();
this.sqlConnection1.Close();
}
}
private void DataGrid1_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.DataGrid1.EditItemIndex = e.Item.ItemIndex;
}
I've been struggling with this problem and none of the fixes posted
seem to help out at all. Yet, it seems like such a simple problem...
I have a DataGrid, and load it up with data on page load. In my
EditCommand event handler I set the editItemindex. All good. Except,
the user needs to click twice to get the DataGrid to become editable.
It's obvious to me (perhaps worngly) that ASP.NET is storing the data
form my grid in the viewstate, and setting up the datagrid BEFORE the
Edit button event. That's why the grid appears editable the next page
load.
So, how do I refresh the grid to show the editability? Predictably,
calling DataBind makes all the data go away... String the data set in
the session seems redundantg, since the page is definitely storing the
data for me in the viewstate. Not that I can get to it...
Any ideas?
Diane
<PRE>
private void Page_Load(object sender, System.EventArgs e)
{
if (this.IsPostBack == false)
{
sqlConnection1.ConnectionString = "..pubs..";
string query = "SELECT * FROM stores";
this.sqlDataAdapter1.SelectCommand.CommandText = query;
this.sqlDataAdapter1.SelectCommand.Connection =
sqlConnection1;
this.sqlConnection1.Open();
this.sqlDataAdapter1.Fill(this.dataSet1, "storesAll");
this.DataGrid1.DataSource =
this.dataSet1.Tables["storesAll"];
this.DataGrid1.DataBind();
this.sqlConnection1.Close();
}
}
private void DataGrid1_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.DataGrid1.EditItemIndex = e.Item.ItemIndex;
}