<asp:DropDownList> (Dinamically select item?)

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?
 
C

Cowboy \(Gregory A. Beamer\)

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!
*************************************************
 
G

Guest

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
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top