p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

aspx thread: How to access controls within a DataGrid?


Message #1 by "Lars Tengstedt" <Lars.Tengstedt@e...> on Tue, 30 Jul 2002 09:27:41 +0200
Hi

 

I am having trouble accessing a DropDownList which is located with a
DataGrid :(

 

This is the code in my .aspx file:

 

<asp:DataGrid id=AccountList runat="server" OnEditCommand="EditAccount">

  <Columns>

    <asp:TemplateColumn HeaderText="Customer">

      <ItemTemplate>

         <asp:Label Runat=server Text='<% # DataBinder.Eval
(Container.DataItem, "Customer") %>' ID="Label1"></asp:Label>

      </ItemTemplate>

      <EditItemTemplate>

         <asp:DropDownList runat="server" id="EditCustomer"/>

      </EditItemTemplate>

    </asp:TemplateColumn>

  </Columns>

</asp:DataGrid>

 

In my .aspx.cs file I haved tried the following within the EditAccount
method:

 

EditAccount(...)

{

  AccountList.EditItemIndex = e.Item.ItemIndex;

  AccountList.DataBind();

  foreach(string customer in allCustomers)

    ((DropDownList) e.Item.Cells[1].Controls[0]).Items.Add(customer);

}

 

I also tried:

 

EditAccount(...)

{

  AccountList.EditItemIndex = e.Item.ItemIndex;

  AccountList.DataBind();

  foreach(string customer in allCustomers)

    ((DropDownList)
e.Item.FindControl["EditCustomer"]).Items.Add(customer);

}

 

Can anyone help me on this?

 

Kind regards and thanx in advance,

Lars Tengstedt

Edlund A/S

Denmark

 



  Return to Index