Forum guidelines
AuthorQuestion
How to Populate Dropdownlist in Datagrid Dynamically?
Posted By anup daware on 24 Mar 2006

Hi group,

I am using a Datagrid with Dropdown, and the values which I have to show in drop are derived from output of a query so I cant use DataSource directly to populate the Dropdown and cant even hardcoad the Listitems in dropdown.
These populated entries are also supposed to be used in an Insert Query.

This is how I have added the dropdown in Datagrid,

<asp:TemplateColumn HeaderText="MTD">
           <ItemTemplate>       <asp:DropDownList id="list" AutoPostBack="True" runat="server"  
                 Width="150px">' DataTextField="X_VALUE">
 </asp:DropDownList>
            </ItemTemplate>
</asp:TemplateColumn>


Please suggest me how to do this dynamically or is there any other way to do this?
(I am using ASP.NET 1.1)

Thanks and Regards,
Anup


-- The trouble with the rat race is that even if you win, you're still a rat --
AuthorReply
Re: How to Populate Dropdownlist in Datagrid Dynam
Posted By Chiew Boon Tan on 25 Mar 2006  
I assume that every dropdown box in each row of data grid will be bind with different values. If that is the case, you may try to make use of the ItemBound event:

private void ItemBound(object sender, DataGridItemEventArgs e) {
if ( e.Item.ItemType == ListItemType.Item )
{
//find the dropdownlist in your datagrid
DropDownList item = e.Item.FindControl("yourlistID") as DropDownList;
//do what ever you need to add the items in your dropdown list.below
}
}
Note that this may not be the most efficient way.


SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.