Accessing dropdown list values inside of a repeater

J

Jeff

After I bind the repeater control in the form_load event, it builds
multiple lines based on the number of rows in the dataset.

In the repeater control, I have a textbox and a dropdown list box. I
have tied the "SelectedIndexChanged" to it. At runtime - after I
change the dropdown box selection, I'm only able to view the values of
the controls within that one repeater instance.

After the dropdown selection is changed, I need to increment through
all of the controls within all of the repeater instances.

heres an example of what I'm using to get to the controls values:
*********CODE*******
For Each ctl In objRepeaterItem.Controls
If ctl.GetType().ToString().Equals("System.Web.UI.WebControls.DropDownList")
_
And ctl.ID = "ddlScore" Then
sTemp = objDL.SelectedValue

End If
Next
********END CODE********

Can anyone help me go through all of the instances of the repeater
item when a dropdown selection has been modified?

Thanks in advance!
Jeff
 
J

Jeff

I found out a little more on this. In my repeater, I have the dropdown as previously mentioned and I have a text box. When the dropdown selection has been changed, I am able to loop through all of the repeater instances to view the content of the text boxes using this code:
For i = 0 To QAScoreRepeater.Items.Count - 1
Dim MyT As TextBox = QAScoreRepeater.Items(i).FindControl("txbScore")
Dim myString As String = MyT.Text
Next
When I try using this code also to view the selection box item, I continually get an Object reference not set to an instance of an object Error.
For i = 0 To QAScoreRepeater.Items.Count - 1
Dim MyString2 As String = CType(QAScoreRepeater.Items(i).FindControl("ddlScore"), DropDownList).SelectedItem.Value
Next

I've also tried this:
Dim MyDropDown As DropDownList = QAScoreRepeater.Items(i).FindControl("ddlScore")
Dim MyString as String = MyDropDown.SelectedValue

Again, same error.
I do have all of the above controls dimensioned in the code behind.

Any ideas would be greatly appreciated!
Jeff
 
A

Alessandro Zifiglio

Dim MyDropDown As DropDownList
MyDropDown = QAScoreRepeater.Items(i).FindControl("ddlScore")
If not MyDropDown is Nothing then
Dim MyString as String = MyDropDown.SelectedValue
End if


Jeff said:
I found out a little more on this. In my repeater, I have the dropdown as
previously mentioned and I have a text box. When the dropdown selection has
been changed, I am able to loop through all of the repeater instances to
view the content of the text boxes using this code:
For i = 0 To QAScoreRepeater.Items.Count - 1
Dim MyT As TextBox = QAScoreRepeater.Items(i).FindControl("txbScore")
Dim myString As String = MyT.Text
Next
When I try using this code also to view the selection box item, I
continually get an Object reference not set to an instance of an object
Error.
 
J

Jeff

Thank you for your response. That of course does solve the problem of the object not being found, but I need to get the value from the dropdown's in each of the repeater instances. Each of the dropdowns does have a selected value by default - I need to get it.

Am I heading in the right direction? Or not?
 
A

Alessandro Zifiglio

Forgot to mention, try to do this on the itemdatabound method for your
repeater --that is one possible reason why your dropdown is turning empty.
Though i had metioned this in my earlier post ;P


Jeff said:
Thank you for your response. That of course does solve the problem of the
object not being found, but I need to get the value from the dropdown's in
each of the repeater instances. Each of the dropdowns does have a selected
value by default - I need to get it.
 
J

Jeff

Thanks a lot Alessandro! Using a combonation of your idea and the SelectedIndexChanged event, I'm now able to keep a running total of the selection box entries.

thanks again. Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top