Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 16th, 2004, 10:06 PM
Registered User
 
Join Date: Jun 2004
Location: , , .
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...
  #2 (permalink)  
Old June 16th, 2004, 10:14 PM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
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.
======================================
  #3 (permalink)  
Old June 16th, 2004, 10:20 PM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
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.
======================================
  #4 (permalink)  
Old June 16th, 2004, 10:50 PM
Registered User
 
Join Date: Jun 2004
Location: , , .
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...
  #5 (permalink)  
Old June 16th, 2004, 11:13 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,413
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.
  #6 (permalink)  
Old June 17th, 2004, 12:10 AM
Registered User
 
Join Date: Jun 2004
Location: , , .
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?
  #7 (permalink)  
Old June 17th, 2004, 03:55 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik Send a message via Skype™ to melvik
Default

I guess using DataGrid will be much easy!

Always:),
Hovik Melkomian.
  #8 (permalink)  
Old June 17th, 2004, 02:04 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,413
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>" />
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 08:11 AM
DropDown Within Repeater ninel ASP.NET 2.0 Basics 14 May 29th, 2008 01:10 PM
Repeater collie VB.NET 2002/2003 Basics 1 December 2nd, 2003 05:30 PM



All times are GMT -4. The time now is 05:00 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.