DataGrid Edit Problem - No value access?

M

_MC_

Hi,

I'm unable to access values in my Datagrid. Datagrid thinks it hase only 1
Cell. So here it is:

The Datagrid is binded in PageLoad, AutoGenerateColumns is false, Columns
are added on PageLoad like this:
BoundColumn Bound_Column = new BoundColumn();

Bound_Column.DataField = name; ( + HeaderText,
SortExpression, Visible)


DataGrid1.Columns.Add(Bound_Column);



DataGrid has all values. Then user edits one Row and clicks on 'Update'.
Eventhandler for Update is called. Now here is my real problem, i could not
access any row. Datagrid tells me that it as 15 Items (Page), but only 1
Cell (Edit Cell i think). I tried to access datarow via:

for (int i = 1; i < 15; i++) // We have 15 Rows... E. g. (as
e.Utem.Cells.Count is 1)

String columnContent = ((TextBox)e.Item.Cells.Controls[0]).Text;

This leads to an Out of Range Exceptions, as Datagrid has only How can i
access the value of the current row?

Thanks for your help,

_MC_
 
B

bpd

Hi,

I'm unable to access values in my Datagrid. Datagrid thinks it hase only 1
Cell. So here it is:

The Datagrid is binded in PageLoad, AutoGenerateColumns is false, Columns
are added on PageLoad like this:
BoundColumn Bound_Column = new BoundColumn();

Bound_Column.DataField = name; ( + HeaderText,
SortExpression, Visible)

DataGrid1.Columns.Add(Bound_Column);

DataGrid has all values. Then user edits one Row and clicks on 'Update'.
Eventhandler for Update is called. Now here is my real problem, i could not
access any row. Datagrid tells me that it as 15 Items (Page), but only 1
Cell (Edit Cell i think). I tried to access datarow via:

for (int i = 1; i < 15; i++) // We have 15 Rows... E. g. (as
e.Utem.Cells.Count is 1)

String columnContent = ((TextBox)e.Item.Cells.Controls[0]).Text;

This leads to an Out of Range Exceptions, as Datagrid has only How can i
access the value of the current row?

Thanks for your help,

_MC_


Are your cells editable (i.e. not set to ReadOnly)?
 
C

chanko

Hi,

I'm unable to access values in my Datagrid. Datagrid thinks it hase only 1
Cell. So here it is:

The Datagrid is binded in PageLoad, AutoGenerateColumns is false, Columns
are added on PageLoad like this:
BoundColumn Bound_Column = new BoundColumn();

Bound_Column.DataField = name; ( + HeaderText,
SortExpression, Visible)

DataGrid1.Columns.Add(Bound_Column);

DataGrid has all values. Then user edits one Row and clicks on 'Update'.
Eventhandler for Update is called. Now here is my real problem, i could not
access any row. Datagrid tells me that it as 15 Items (Page), but only 1
Cell (Edit Cell i think). I tried to access datarow via:

for (int i = 1; i < 15; i++) // We have 15 Rows... E. g. (as
e.Utem.Cells.Count is 1)

String columnContent = ((TextBox)e.Item.Cells.Controls[0]).Text;

This leads to an Out of Range Exceptions, as Datagrid has only How can i
access the value of the current row?

Thanks for your help,

_MC_


are you using a master page?
if so are you giving your master page an id?

i had a similar problem where i was losing the values of datakeys
within a gridview (on top of another weird treeview error)
and after many attempts at fixing it, i don't know why but i removed
the id i was assigning the master page and it worked. i placed the id
once again just to make sure and had the same error.
don't know what's causing it really but at least that solved my
problems

hope it helps
 
M

_MC_

Hi,

bdp: "Are your cells editable (i.e. not set to ReadOnly)?"

they are all editable. Even if they are not editable I should have
access on it, or?


chanko: we're currently using an master page, but what do you mean with
"if so are you giving your master page an id?"?


Thanks,


_MC_
 
M

_MC_

Hi,

some debug hours later...

User Html Code only contains javascript postback for Cell 0 (the static edit
Cell) on edit command, so we never get any information about the user
changed.

http://msdn2.microsoft.com/en-us/library/aa478966.aspx wrote:

"If you do find yourself in one of these scenarios, be aware that your
dynamic controls do not preserve themselves when the page is submitted."

That seems to be my problem, nevertheless there must be a chance to access
the changed values, musn't it? We only need those values, if datagrid does
not preserve values is irrelevant. We simple had to access those values.
It's no possible that all other column values are lost.

Note: If i manually add the columns in designer mode all here created
columns are present on update. However, we need to create the columns on
runtime as we have e. g. an drop down menue for table, etc so it's not
possible in my eyes to to this static.


Thanks for your help!


_MC_
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top