What is the structure hierarchy here?

D

Doru Roman

Hi,

To update the changes in the grid I use the structure taken from the Help
examples:

private void dgCompany_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

TextBox CompanyBox = (TextBox)e.Item.Cells[2].Controls[0];

I try to get the hierarchy starting at Item.Cells[2].Controls[0]



I could not find the Cells and then Controls collections inside the datagrid
class.

Can someone explain to me how I can get to the controls in the end, as
Controls[0] means Textbox, Controls[1] means Checkbox, or at least this is
what I presume.

Thanks,

Doru
 
T

Teemu Keiski

Hi,

if you have fixed set of controls there, it's lots easier to use FindControl
with the ID instead of trying to guess the control hierarchy. The index of
certain control can vary for example if there's a text (even space will do)
since such would be converted to a LiteralControl etc

For example if your control's ID is "CompanyBox":

TextBox CompanyBox = (TextBox)e.Item.FindControl("CompanyBox");
 
D

Doru Roman

Thanks Teemu for the reply.
I still don't understand how I can find out the ID of a TextBox inside of a
DataGrid when it's in the Edit mode.
 
T

Teemu Keiski

The ID you'd use is the one given to the TextBox in the Template.

Say you have

<EditItemTemplate>
<asp:TextBox ID="CompanyBox" runat="server" />
</EditItemTemplate>

Then this would work

TextBox CompanyBox = (TextBox)e.Item.FindControl("CompanyBox");

when running from EditCommand, or ItemCommand etc (e.Item.ItemType is then
EditItem)
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top