How can I put dropdown list in a datagrid while editing it?
Printable View
How can I put dropdown list in a datagrid while editing it?
Use a template column, here's an example where I use a hyperlink with a combobox for editing:
Code:<asp:TemplateColumn SortExpression="Submitter_ID" HeaderText="Sub Id">
<HeaderStyle Width="10%"></HeaderStyle>
<ItemStyle Width="10%"></ItemStyle>
<ItemTemplate>
<asp:Hyperlink runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Submitter_ID") %>' NavigateUrl='<%# "Submitter.aspx?id=" & DataBinder.Eval(Container.DataItem, "Submitter_ID") %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:dropdownlist runat="server" DataValueField="Submitter_ID" Width="100%" DataSource="<%# BindSubmitterIds() %>" SelectedIndex='<%# GetSubIdIndex(Container.DataItem("Submitter_ID")) %>' />
</EditItemTemplate>
</asp:TemplateColumn>
you missed off the ID.
To get the values of this you can then do something like:Code:<asp:dropdownlist id="ddl_Items"
or c#Code:For Each Item As DataGridItem In DataGrid1.Items
Dim ddl As DropDownList = Item.FindControl("ddl_Items")
Next
Hope that helps.Code:foreach(DataGridItem Item In DataGrid1)
{
DropDownList ddl = Item.FindControl("ddl_Items");
}
WOka
Oh, the DataGrid and DataGridItem objects can be found in the System.Web.UI.WebControls namesapce.
Woka