Solved

Populating a DropDownList

Posted on 2008-10-21
5
423 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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.…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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