Change value of DataGrid columns

J

John Smith

I'm looking into this peace of code:

protected void DropDown_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList list = (DropDownList)sender;

TableCell cell = list.Parent as TableCell;
DataGridItem item = cell.Parent as DataGridItem;

int index = item.ItemIndex;
string content = item.Cells[0].Text;

Response.Write(
String.Format("Row {0} contains {1}", index, content)
);

}

can I do this:

item.Cells[0].Text = "Some text...";

I don't want only to change value in the grid (displayed value), but also in
the underlaying DataSource (which is of XML file type).
 
C

Curtis

This is too early in the page processing life cycle to change the cell
text. You'll have to change it in the Page.PreRender or later in the
page life cycle.

If you change the cell text, or pretty much any object in the datagrid,
at this point it is still "vulnerable" to changes being made to it by
the asp.net framework during round trip processing.

Curtis
 
J

John Smith

Will this line of the code:

item.Cells[0].Text = "Some text...";

change only DataGrid visual value or it will also change value in the
DataSource? How can I change value in DataSource?



Curtis said:
This is too early in the page processing life cycle to change the cell
text. You'll have to change it in the Page.PreRender or later in the
page life cycle.

If you change the cell text, or pretty much any object in the datagrid,
at this point it is still "vulnerable" to changes being made to it by
the asp.net framework during round trip processing.

Curtis

John said:
I'm looking into this peace of code:

protected void DropDown_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList list = (DropDownList)sender;

TableCell cell = list.Parent as TableCell;
DataGridItem item = cell.Parent as DataGridItem;

int index = item.ItemIndex;
string content = item.Cells[0].Text;

Response.Write(
String.Format("Row {0} contains {1}", index, content)
);

}

can I do this:

item.Cells[0].Text = "Some text...";

I don't want only to change value in the grid (displayed value), but also
in
the underlaying DataSource (which is of XML file type).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top