Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > .NET Framework 1.x
|
.NET Framework 1.x For discussing versions 1.0 and 1.1 of the Microsoft .NET Framework.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 1.x section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 24th, 2006, 06:18 AM
Authorized User
 
Join Date: Mar 2006
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to anup_daware Send a message via MSN to anup_daware Send a message via Yahoo to anup_daware
Default Populating Dropdownlist in Datagrid Dynamically

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

Best Regards,
Anup
&lt;Today is the first day of your rest of life.. Make most of it&gt;
__________________
--Everything you can imagine is real.--
 
Old March 27th, 2006, 03:38 PM
Authorized User
 
Join Date: Oct 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to evandro.paula
Default

1) First, you could delegate a event handler to the datagrid ItemCreated event:
dgData.ItemCreated+=new System.Web.UI.WebControls.DataGridItemEventHandler (this.DataGrid_ItemCreated);

2) Then, write a method that will be responsible for creating the dropdownlist you want. Finally, check if the e.Item is an "Item" or "AlternatingItem" and add the control in the cell you desire:
private void DataGrid_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
    if((e.Item.ItemType==System.Web.UI.WebControls.Lis tItemType.Item)||(e.Item.ItemType==System.Web.UI.W ebControls.ListItemType.AlternatingItem))
    {
        System.Web.UI.WebControls.DropDownList ddl=new System.Web.UI.WebControls.DropDownList();
...
...
        e.Item.Cells[2].Controls.Add(ddl);
    }
}

Important: e.Item is equivalent a line of the datagrid.

Regards.







Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically generated dropdownlist csun ASP.NET 1.0 and 1.1 Basics 3 April 8th, 2008 07:38 AM
Populating DropDownList from multiple sources hawkfb63 ASP.NET 2.0 Professional 2 February 14th, 2006 06:42 PM
populating a dropdownlist within a datagrid greenguitar General .NET 1 November 22nd, 2004 01:02 AM
Dynamically Populating Crystal Reports gpage Crystal Reports 0 November 17th, 2003 12:36 PM
Populating DropDownList [email protected] ASP.NET 1.0 and 1.1 Professional 1 November 14th, 2003 03:35 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.