Solved

Populating a DropDownList

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

21 Experts available now in Live!

Get 1:1 Help Now