Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics 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 October 13th, 2006, 08:31 AM
Registered User
 
Join Date: Sep 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default populate a DropDownList in a TemplateColumn of a G

Hi,

Here is an example of an asp.net 2.0 GridView's templated column that contains a dropdownlist control.

aspx page...
<asp:GridView ID="gv1" AutoGenerateColumns="false"
runat="server" OnRowCreated="gv1_RowCreated">
<Columns>
<asp:BoundField HeaderText="Type" DataField="Type" />
<asp:TemplateField HeaderText="Categories">
<ItemTemplate>
<asp:DropDownList ID="ddlCategories"
AutoPostBack="true" runat="server"
OnSelectedIndexChanged="ddlCategories_SelectedInde xChanged">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>


code behind...

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// populate grid
this.gv1.DataSource = <<whatever>>;
this.gv1.DataBind();
}
}

protected void gv1_RowCreated(object sender,
GridViewRowEventArgs e)
{
if (!IsPostBack)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Bind drop down
DropDownList ddl =
(DropDownList)e.Row.FindControl("ddlCategories");
ddl.DataSource = <<whatever>>
ddl.DataBind();
}
}
}

protected void ddlCategories_SelectedIndexChanged(object sender,
EventArgs e)
{
// event fired on change of ddl value
}

Last edited by aidoco; May 1st, 2012 at 01:58 AM.. Reason: Answered Question




Similar Threads
Thread Thread Starter Forum Replies Last Post
Datagrid Templatecolumn with Hyperlink ~Bean~ ASP.NET 1.0 and 1.1 Basics 0 July 18th, 2005 10:02 AM
TemplateColumn - Question vox Classic ASP Professional 1 June 6th, 2005 07:18 AM
switch of the edit in templatecolumn? Raif ASP.NET 1.0 and 1.1 Professional 5 August 4th, 2004 03:51 PM
Right align text in labels in a templatecolumn texasraven ASP.NET 1.x and 2.0 Application Design 1 August 27th, 2003 08:44 AM





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