Please I need help with a datagrid item on edit

G

Guest

Hi, I have been on this for hours and just cannot work it out.

I have a datagrid. I set the edititem index to a row to edit, that works.
However if i want to put a value into this textbox it wont let me. I just
cant find the control in the controlcollection for the cell. Is it because it
hasnt rendered yet? (very annoying as i have set the edititem to the index,
done my databound etc.) why doesnt it recognise the textbox? so:

dgThing.EditItemIndex = e.Item.ItemIndex;
get my source and do DataBind();
TextBox aBox = (TextBox)e.Item.Cells[2].Controls[0]; //i found this code in
msdn so i know its right
thisText.Text="set this text into the textbox";

Because i have to just work out the cells (there is not cell id) i have just
counted. I am def on the right one. The one before it has some text in it,
so i know where i am in the row. but it cant find the textbox control having
just gone into edit mode. Has anyone got round this somehow? Another thing,
why do I have to databind again. I only want to change one row yet i have to
go to my sql database and run a complicated query EVERY time to populate data
which was already there, just to get my item to go into edit mode! is this
the only way?
 
D

dan.c.roth

Hi

1) Remember to rebind the datagrid in the EditCommand:

DataBind()

2) In OnDataBoundEvent do the:

TextBox aBox = (TextBox)e.Item.Cells[2].Controls[0];
thisText.Text="set this text into the textbox";

Regards,

Daniel Roth
MCSD.NET
 
G

Guest

Hi Louise,

In this special situation, you should use

TextBox aBox = (TextBox)dgThing.Items[e.Item.ItemIndex].Cells[2].Controls[0];

to get reference of an ‘Edit’ item.

At this moment, e.Item is a normal datagrid item rather than an edit
datagrid item.

HTH

Elton Wang
(e-mail address removed)
 
G

Guest

Hi guys thanks for your responses i shall test them out later. Regarding the
first offering, I think I have already done that??

Elton W said:
Hi Louise,

In this special situation, you should use

TextBox aBox = (TextBox)dgThing.Items[e.Item.ItemIndex].Cells[2].Controls[0];

to get reference of an ‘Edit’ item.

At this moment, e.Item is a normal datagrid item rather than an edit
datagrid item.

HTH

Elton Wang
(e-mail address removed)



louise raisbeck said:
Hi, I have been on this for hours and just cannot work it out.

I have a datagrid. I set the edititem index to a row to edit, that works.
However if i want to put a value into this textbox it wont let me. I just
cant find the control in the controlcollection for the cell. Is it because it
hasnt rendered yet? (very annoying as i have set the edititem to the index,
done my databound etc.) why doesnt it recognise the textbox? so:

dgThing.EditItemIndex = e.Item.ItemIndex;
get my source and do DataBind();
TextBox aBox = (TextBox)e.Item.Cells[2].Controls[0]; //i found this code in
msdn so i know its right
thisText.Text="set this text into the textbox";

Because i have to just work out the cells (there is not cell id) i have just
counted. I am def on the right one. The one before it has some text in it,
so i know where i am in the row. but it cant find the textbox control having
just gone into edit mode. Has anyone got round this somehow? Another thing,
why do I have to databind again. I only want to change one row yet i have to
go to my sql database and run a complicated query EVERY time to populate data
which was already there, just to get my item to go into edit mode! is this
the only way?
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top