Change value of DataGrid columns (2)

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).
 
J

John Smith

This is what I am trying now, but it doesn't work. I'm not sure even if
event triggers.

Public Sub DropDown_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged
Dim list As DropDownList = CType(sender, DropDownList)
Dim cell = CType(list.Parent, TableCell)
Dim item = CType(cell.Parent, DataGridItem)
Dim index = item.ItemIndex
DataGrid1.EditItemIndex = item.ItemIndex
Dim id As Integer = Convert.ToInt32(item.Cells(1).Text)
Dim ds As DataSet
ds = DataGrid1.DataSource
Dim RowUredi As DataRow
RowUredi = ds.Tables(0).Select("ID = '" + id.ToString + "'")(0)
RowUredi.Item(6) = "P"
RowUredi.AcceptChanges()
End Sub

What should I do?
 
E

Eliyahu Goldin

Only the visual value. You can refer to datasource as item.DataItem, but I
am not sure modifying the datasource from the grid events is a good idea.

Eliyahu

John Smith said:
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,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top