M
Martin Schmid
I am trying to implement sorting and editing on a datagrid that has it's
source as a DataView. I can sort by selecting the column headers, and I can
edit using. However, If I sort, then edit, the table reverts to the
original 'sorting', and selects the 'wrong' row for editing... I.e. if my
datagrid is as follows:
A
W
E
D
I select the column to sort, it becomes:
A
D
E
W
However, when I select the 'D' row for editing, the table reverts to the
original 'AWED' order, and the 'W' row is selected for editing.
The code below may provide some insight:
//Walkthrough: Using a DataGrid Web Control to Read and Write Data
private void DataGrid1_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
dataView.Sort=e.SortExpression;
DataGrid1.DataBind();
}
private void DataGrid1_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = e.Item.ItemIndex;
DataGrid1.DataBind();
}
private void DataGrid1_CancelCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex =-1;
DataGrid1.DataBind();
}
private void Page_Load(object sender, System.EventArgs e)
{
sqlConnection = (SqlConnection)Session["sqlConnection"];
sqlDataAdapter = (SqlDataAdapter)Session["sqlDataAdapter"];
// Put user code to initialize the page here
sqlDataAdapter.Fill(dsProjMilestones);
if (!IsPostBack)
{
DataGrid1.DataBind();
}
}
Thanks for any help.
source as a DataView. I can sort by selecting the column headers, and I can
edit using. However, If I sort, then edit, the table reverts to the
original 'sorting', and selects the 'wrong' row for editing... I.e. if my
datagrid is as follows:
A
W
E
D
I select the column to sort, it becomes:
A
D
E
W
However, when I select the 'D' row for editing, the table reverts to the
original 'AWED' order, and the 'W' row is selected for editing.
The code below may provide some insight:
//Walkthrough: Using a DataGrid Web Control to Read and Write Data
private void DataGrid1_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
dataView.Sort=e.SortExpression;
DataGrid1.DataBind();
}
private void DataGrid1_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = e.Item.ItemIndex;
DataGrid1.DataBind();
}
private void DataGrid1_CancelCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex =-1;
DataGrid1.DataBind();
}
private void Page_Load(object sender, System.EventArgs e)
{
sqlConnection = (SqlConnection)Session["sqlConnection"];
sqlDataAdapter = (SqlDataAdapter)Session["sqlDataAdapter"];
// Put user code to initialize the page here
sqlDataAdapter.Fill(dsProjMilestones);
if (!IsPostBack)
{
DataGrid1.DataBind();
}
}
Thanks for any help.