views:

260

answers:

1

I am trying to select a value from a drop down control before it was text box. I have given the same ID for drop down which was similar to the text box.

Below is the code:

  Do
      counter=counter+1
        tempPanelInputBox = form1.FindControl("txt_" + panelUsed + "_input" + counter.ToString())
    Loop untill counter=CounterEnd

and i want to change to get the selected value in the dropdown box.

+2  A: 

If you're sure it's a Dropdownlist, just do a cast:

DropDownList tempPanelInputBox = (DropDownList)form1.FindControl("txt_" + panelUsed + "_input" + counter.ToString());

int selValue = tempPanelInputBox.SelectedValue; //or whatever you want to do with the  selected value

EDIT: In VB:

Dim tempPanelInputBox As DropDownList
tempPanelInput = CType(form1.FindControl("txt_" + panelUsed + "_input" + counter.ToString()), DropDownList)

Then access tempPanelInput.SelectedValue and do with it whatever you want.

ristonj
When i paste ur code its givng error "Dropdown list is a type that cannot be used as an expression"
i am using VB can u rewrite to VB ???
Can you tag this as VB.NET please? Thanks.
ristonj
Retagged, just for you!
Wyatt Barnett