473,473 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Please I need help with a datagrid item on edit

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?
Nov 19 '05 #1
3 1387
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

Nov 19 '05 #2
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
el********@hotmail.com

"louise raisbeck" wrote:
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?

Nov 19 '05 #3
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" wrote:
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
el********@hotmail.com

"louise raisbeck" wrote:
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?

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: shamila | last post by:
</asp:label><asp:datagrid id="DataGrid3" runat="server" cssclass="DataGrid" showfooter="True" onupdatecommand="DataGrid3_Update"ondeletecommand="DataGrid3_Delete" oneditcommand="DataGrid3_Edit"...
0
by: Steve | last post by:
I have a datagrid that is created at run time DataGrid dgG = new DataGrid(); BoundColumn bcB; dgG.CellPadding = 5; dgG.CellSpacing = 0; dgG.GridLines = GridLines.Both; dgG.CssClass =...
0
by: Colin Ramsay | last post by:
Hi all, I don't normally post swathes of code like this but I am truly banging my head off my desk here... I've dynamically created a datagrid within a usercontrol. There are two columns...
12
by: Daniel Walzenbach | last post by:
Hi, I want to display a Label in a DataGrid according to some condition. I therefore check whether the condition is true in the ItemDateBound EventHandler of the DataGrid. Unfortunately the...
1
by: Anna | last post by:
I have a simple DataGrid that displays a list of characteristics and allows you to edit a description for each characteristic. The query that feeds this involves a join, as the characteristics and...
10
by: Terry Olsen | last post by:
I've got a datagrid set up to display data. I've also got an Edit,Update,Cancel column set up to allow editing of data. I've got a DropDownList (ID="ddl3")in the EditItemTemplate for a certain...
0
by: Daniel Doyle | last post by:
Hello and apologies in advance for the amount of code in this post. I've also sent this message to the Sharepoint group, but thought that ASP.NET developers may also be able to help, even though...
0
by: Chris | last post by:
I've been searching all over and think I am close, but keep getting the error "Index out of range" when trying to reference a nested datagrid when an OnEditCommand event is raised. When the...
0
by: hanusoft | last post by:
This is an example of editing in DataGrid and Default Paging http://www.hanusoftware.com Html Design Code : - <asp:DataGrid id="DataGrid1" DataKeyField="id" runat="server" Height="224px"...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.