Solved

Populating a DropDownList

Posted on 2008-10-21
5
421 Views
Last Modified: 2013-11-07
I'm stumped...  I have a webpage with a DropDownList (A), and a repeater that contains DropDownList's (B), when the user clicks a button, the DropDownLists (B) are populated, with a selection of values based on DropDownList (A).

To make the interface a little bit slicker, I canged this so that DropDownList (A) had an AutoPostBack.  The weird part now is that with the AutoPostBack the DropDownLists (B) aren't populated, BUT the function is triggered (I can step through it, and there are no errors :-S).  Both the button and DropDownList use the exact same sub.

I've attached the snipped that populated the dropdownlist.
For Each item In excelRpts.Items

                ddExcelCasp.Items.Clear()

                CType(item.FindControl("ddExcelProp"), DropDownList).Items.Clear() 'it finds this no problem, and clears any previous values (tho there should never be any as the repeater is being rebound).
 

                For Each colNam In objDataSet.Tables(0).Columns 'this is a table of column headers from excel which I populate the dropdownlists with

                    CType(item.FindControl("ddExcelProp"), DropDownList).Items.Add(colNam.ColumnName) 'no error is thrown here and all appears to be well?!?!?!

                Next

            Next

Open in new window

0
Comment
Question by:dpwdc
  • 3
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
jinn_hnnl earned 500 total points
ID: 22767412
Ok, so you debugged and found that all adding step items have been triggered, but you see nothing as the output for all of these DDL B - ddExcelProp?

For better debugging put this:

Try

      Dim MyDDL = item.FindControl("ddExcelProp") As DropDownList
      For Each colNam In objDataSet.Tables(0).Columns
                    MyDDL.Items.Add(colNam.ColumnName)
      Next
Catch ...
End Try

I assum you will go through this several time, after the foreach done each time, try to watch if there is any item in MyDDL.Items

If there are, and when it renders to client out put, you see nothing. Then you might have been rebind those ddExcelProp after those adding step has been done. may be in PreRender (or any whereelse)

Check it again and tell us what you saw?
0
 
LVL 1

Author Comment

by:dpwdc
ID: 22767680
Yup there are items in MyDLL, but output shows nothing - tried adding databind to the ddList but still no luck.

I added a textbox with an autopostback as an experiment (to see if it was the autopost back causing the problem) and that worked perfectly - quite odd!
0
 
LVL 10

Assisted Solution

by:jinn_hnnl
jinn_hnnl earned 500 total points
ID: 22767722
ddExcelCasp.Items.Clear()
what's  that for?

The only problem I could think of now is: after you have added those items to your DDL, you rebind the DDL again which makes the adding non-sense.

put the protected Override void OnPrerender..
And check if at that moment your DDL still has items?

This is odd I agree

JINN
0
 
LVL 1

Author Comment

by:dpwdc
ID: 22767830
I've worked it out and come to a solution!

Rather than using the button / dropdown to trigger the additions of the items, why didnt i just use the repeaters "excelRpts.ItemDataBound"?!  Must not have had my head screwed on today.

I think the problem was that when the dropdown is changes, it causes the repeater to rebind (as the repeaters data source is dependant on the dropdownvalue!).

Thanks for the attention anyway!
0
 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 22767919
That's right,

Glad you work it out. My guess is also like yours, these ddl controls are rebind for some reason (and here your point is the repeater is rebind again - I think that's the right direction)

Just pay attention to the page life circle (it helps for future use), then you also find out what is going on in alot of cases, Page_Load is executed first then button click/selectedIndexChange  then PreRender ...

Thanks for the point

JINN
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now