Wrox Programmer Forums
|
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 June 16th, 2004, 09:06 PM
Registered User
 
Join Date: Jun 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dropdown in Repeater

Hi All,
I am trying to put a dropdown list in a repeater. The dropdown list will be the same each time.

Is there a function in the repeater where I can load the dropdown after is is made? or how do i reference the dropdown in the codebehind?

Thanks...
 
Old June 16th, 2004, 09:14 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Kyle,
You can reference the controls of the repeater in the ItemCreated event of the dropdown list using the items FindControl method.
I recall having some trouble with it being databound, from memory I bound the dropdown in the ItemCreated event also.
There is a great 16 Part article at 4guysfromrolla.com about datagrids, most of it would also apply to repeaters I beleive and is worth a read.

http://aspnet.4guysfromrolla.com/articles/040502-1.aspx


======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
 
Old June 16th, 2004, 09:20 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Sorry Kyle,

Just looked at some code.
I used the ItemDataBound Event previously.
Here is my c# code.


private void utilList_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
        {
            DropDownList DDLCreated;
            if((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                DDLCreated = ((DropDownList) e.Item.FindControl("DDLUtilType"));
                //DLLCreated.DataSource = monthArray;

                if (Conn.State != ConnectionState.Open){Conn.Open();}
                //Conn.Open();
                AdptUtils = new SqlDataAdapter();
                AdptUtils.SelectCommand = new SqlCommand("select * from utilCodeType order by utilCode",Conn);
                dsUtils.Clear();
                AdptUtils.Fill(dsUtils);
                Conn.Close();

                DDLCreated.DataSource = dsUtils.DefaultView;
                DDLCreated.DataTextField = "utilCode";
                DDLCreated.DataValueField = "utilCode";
                DDLCreated.DataBind();
                //((TextBox) e.Item.FindControl("TBCurrVal")).Text = "HI";
                foreach(ListItem codeType in DDLCreated.Items)
                {
                    //codeType.Selected = true;
                    //((TextBox) e.Item.FindControl("TBCurrVal")).Text = "Hi";
                    if ( codeType.Text.Trim().Equals(((TextBox) e.Item.FindControl("TBCurrVal")).Text))
                    {

                        codeType.Selected = true;
                    }
                }
            }

        }

======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
 
Old June 16th, 2004, 09:50 PM
Registered User
 
Join Date: Jun 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I read through the 4 guys and looked at your code. I'm still having problems. I guess My first question would be do i have to "bind" the data because the dropdown list will have the same exact text for each repeat.

I'm really lost...
 
Old June 16th, 2004, 10:13 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

If the source for the drop down items is dynamic, then you need to bind each occurrance of the drop down in the repeater. However, you could optimize the code so that you don't call the data source every time. Call it once, and store the object that contains the data so it can be reused for each repeater item.
 
Old June 16th, 2004, 11:10 PM
Registered User
 
Join Date: Jun 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Right now I'm just trying to get a dropdown list to show up that is NOT bound to anything. I get them to show up, but I cannot figure out how to populate them... The following lines are when I view the html source:

<select name="AcctRepeater:_ctl1:ddlMenu" id="AcctRepeater__ctl1_ddlMenu">
<select name="AcctRepeater:_ctl3:ddlMenu" id="AcctRepeater__ctl3_ddlMenu">

Can someone help me populate the ddlMenu's?
 
Old June 17th, 2004, 02:55 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

I guess using DataGrid will be much easy!

Always:),
Hovik Melkomian.
 
Old June 17th, 2004, 01:04 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

melvik-
I'm not sure how a datagrid would fix this.

kylem-
Take a look at this sample.

http://www.geekdork.com/samples/complexDatagrid.aspx

It explains how to do a slightly more complicated binding within a datagrid but it shows how you can bind a control that will be repeated within any repeating control (repeater, datalist or datagrid). The key is the binding syntax within the control:

<asp:dropdownlist runat="server" datasource='<%# <datasource object> %>' datatextfield="<textfield>" datavaluefield="<valuefield>" />





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dropdown in repeater (Moved From C# Forum) rodmcleay ASP.NET 1.0 and 1.1 Basics 14 June 20th, 2008 07:11 AM
DropDown Within Repeater ninel ASP.NET 2.0 Basics 14 May 29th, 2008 12:10 PM
Repeater collie VB.NET 2002/2003 Basics 1 December 2nd, 2003 05:30 PM





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