Solved

Populating a DropDownList

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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

830 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