Solved

Populating a DropDownList

Posted on 2008-10-21
5
425 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 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