how to get selected values ( vb.net )

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 ?
 
S

Scott Mitchell [MVP]

krzysiek said:
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 ?

You'll either have to give some sort of name to these dynamically added
controls (like rad1, rad2, rad3, ...) or just recursively loop through
your Page's Controls collection. I discuss how to access dynamically
added controls in this article:

Working with Dynamically Created Controls
http://aspnet.4guysfromrolla.com/articles/082102-1.aspx

Happy Programming!

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 
K

krzysiek

Thanks a lot for your advise Scott, however i think i have little bit
complicated 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..


thanks 4 any advise :)
 
W

WALDO

This is just off the top of my head, but it should help.

[VB.Net]
Dim strKey As String
Dim strId As String
Dim strValue As String
Dim strSearch As String = Me.pytania_list.UniqueId
Dim hstCheckBoxValues As New HashTable
Dim hstRadioButtonValues As New HashTable

For Each strKey In Request.Form.Keys
If strKey.StartsWith(strSearch) Then
strId = Right(strKey, Len(strKey) - (Len(strSearch) + 1))
If strId <> Nothing Then
If strId.StartsWith("box:") Then
strId = Right(strId, Len(strId) - Len("box:"))
strValue = Request.Form(strKey)
hstCheckBoxValues.Add(strId, strValue)
ElseIf strId.StartsWith("RadioButtonList1:") Then
strId = Right(strId, Len("RadioButtonList1:"))
strValue = Request.Form(strKey)
hstRadioButtonValues.Add(strId, strValue)
End If
End If
End If
Next
 
K

krzysiek

Thank you waldo ;-)


WALDO said:
This is just off the top of my head, but it should help.

[VB.Net]
Dim strKey As String
Dim strId As String
Dim strValue As String
Dim strSearch As String = Me.pytania_list.UniqueId
Dim hstCheckBoxValues As New HashTable
Dim hstRadioButtonValues As New HashTable

For Each strKey In Request.Form.Keys
If strKey.StartsWith(strSearch) Then
strId = Right(strKey, Len(strKey) - (Len(strSearch) + 1))
If strId <> Nothing Then
If strId.StartsWith("box:") Then
strId = Right(strId, Len(strId) - Len("box:"))
strValue = Request.Form(strKey)
hstCheckBoxValues.Add(strId, strValue)
ElseIf strId.StartsWith("RadioButtonList1:") Then
strId = Right(strId, Len("RadioButtonList1:"))
strValue = Request.Form(strKey)
hstRadioButtonValues.Add(strId, strValue)
End If
End If
End If
Next


"krzysiek" <[email protected]> wrote in message
Thanks a lot for your advise Scott, however i think i have little bit
complicated 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: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..


thanks 4 any advise :)



number
of
 

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

Forum statistics

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

Latest Threads

Top