<asp:DropDownList> (Dinamically select item?)

  • Thread starter Thread starter John Smith
  • Start date Start date
J

John Smith

I have this DataGrid:

<asp:datagrid id="dg1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn HeaderText="SM">
<ItemTemplate>
<asp:Label id="Label2" runat="server" Text='<%#
Container.DataItem("SM") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="ddlSM" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="ddlSM_SelectedIndexChanged">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

Inside which event it would be the best to set DropDownList's "Selected"
property?
 
I usually create a function that sets after it is populated. The Page_Load()
is fine (with !Page.IsPostBack() for normal ops where the data does not
change after population). Your app may not give you that option.

--
Gregory A. Beamer

*************************************************
Think Outside the Box!
*************************************************
 
John,
Typically this would be done in the ItemDataBound event, which fires as each
row is databound. You can gain acess to the control and set such properties
there.

Loads of example code can be found on this with a simple search on
DataGrid ItemDataBound DropDownList

Peter
 
Back
Top