how to get selected values ( vb.net )

  • Thread starter Thread starter krzysiek
  • Start date Start date
K

krzysiek

hello,
i have several radiolists and checkboxlist that are generated dinamicly
based on datasource. So frankly speaking i don't know names and number of
that web controls cose they are always different.
How can i retreive selected values from those controls ?
 
Thanks a lot for your advise Saravana, however i have little bit different
case.
I have 3 types of webcontrols that are nested in DataList.

**************************
<asp:DataList OnItemDataBound="odp_bound" id="pytania_list" runat="server"
Width="100%" >
<ItemTemplate>
<table width="100%" >
</asp:CheckBoxList>
<asp:TextBox id="TextBox1" runat="server"
visible="false"></asp:TextBox>
<asp:RadioButtonList id="RadioButtonList1"
runat="server"></asp:RadioButtonList>
</td></tr>
</table></ItemTemplate></asp:DataList>
**************************
when DataList is bound it trrigers proc. "odp_bound" which drowing controls
based on database data.

**************************
sub odp_bound(s As Object, e As DataListItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then
If Not e.Item.DataItem Is Nothing Then

select case e.Item.DataItem("rodzaj")
case="4"

dim radio as RadioButtonList =
e.Item.Findcontrol("RadioButtonList1")

Dim dr As DataRowView = CType(e.Item.DataItem,
DataRowView)
dim dv as Dataview
dv=dr.CreateChildView("PytaniaOdpowiedzi")
radio.DataSource = dv
radio.DataTextField="tresc"
radio.DataBind()
(.....)
***************

after postback i should get valuses of all previously generated controls
but i dont know how to loop through those controls..
Your LoopingControls sub looks fine but i don't know what event can run
it..

thanks 4 any advise :-)
 
You could, do something like this in your page load

If Page.IsPostBack Then
Dim li As ListItem
Dim oControl As Control

For Each li in pytania_list.Items
For Each oControl In li.Controls
If TypeOf Control Is RadioButtonList Then
' Do Something.
End If
Next
Next

End If


Hope this helps,

Joel Cade, MCSD
Fig Tree Solutions, LLC
http://www.figtreesolutions.com
 
Hello Joel,
Thanks 4 your support. Your code looks pretty simple that's why i deployed
it immediatelly but :-( i didn't mention that my DataList "pytania_list" is
also nested in another master DataList which is called "ankieta_list". So
following your e.g. i wrote:

Dim li As ListItem
Dim oControl As Control
dim ankieta_list as DataList = Findcontrol("ankieta_list")
Dim item As DataListItem

For Each item in ankieta_list.Items
For Each oControl In item.Controls
If TypeOf oControl Is DataList Then

dim pytania_list as DataList = oControl
Dim pyt_item As DataListItem
Dim ctrl As Control
For Each pyt_item in
pytania_list.Items

For Each ctrl In
pyt_item.Controls

If TypeOf ctrl Is
TextBox Then

do somth...
end if
next
next
End If
next
Next


.... and it works !! :-)

Thanks a lot Joel !!
 
Back
Top