473,573 Members | 3,075 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to get selected values ( vb.net )

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 ?
Nov 18 '05 #1
4 6538
You loop through each control in the page and check that control type. If it
is checkbox or radiobuttonlist then you can get the selected value of that
control. To know how to loop through controls in a page, check out this
article
http://www.extremeexperts.com/Net/Ar...hControls.aspx
"krzysiek" <kr**********@h otmail.com> wrote in message
news:cl******** ***@news2.ipart ners.pl...
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 ?

Nov 18 '05 #2
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_lis t" runat="server"
Width="100%" >
<ItemTemplate >
<table width="100%" >
<tr><td >
<asp:CheckBoxLi st id="box" runat="server"
</asp:CheckBoxLis t> <asp:TextBox id="TextBox1" runat="server"
visible="false" ></asp:TextBox>
<asp:RadioButto nList id="RadioButton List1"
runat="server"> </asp:RadioButton List>
</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 DataListItemEve ntArgs)
If e.Item.ItemType = ListItemType.It em Or _
e.Item.ItemType = ListItemType.Al ternatingItem Then
If Not e.Item.DataItem Is Nothing Then

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

dim radio as RadioButtonList =
e.Item.Findcont rol("RadioButto nList1")

Dim dr As DataRowView = CType(e.Item.Da taItem,
DataRowView)
dim dv as Dataview
dv=dr.CreateChi ldView("Pytania Odpowiedzi")
radio.DataSourc e = dv
radio.DataTextF ield="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 :-)


"Saravana" <sa******@sct.c o.in> wrote in message
news:3Z******** *********@news. cpqcorp.net... You loop through each control in the page and check that control type. If it is checkbox or radiobuttonlist then you can get the selected value of that
control. To know how to loop through controls in a page, check out this
article
http://www.extremeexperts.com/Net/Ar...hControls.aspx
"krzysiek" <kr**********@h otmail.com> wrote in message
news:cl******** ***@news2.ipart ners.pl...
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 ?


Nov 18 '05 #3
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.It ems
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

"krzysiek" wrote:
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_lis t" runat="server"
Width="100%" >
<ItemTemplate >
<table width="100%" >
<tr><td >
<asp:CheckBoxLi st id="box" runat="server"
</asp:CheckBoxLis t>

<asp:TextBox id="TextBox1" runat="server"
visible="false" ></asp:TextBox>
<asp:RadioButto nList id="RadioButton List1"
runat="server"> </asp:RadioButton List>
</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 DataListItemEve ntArgs)
If e.Item.ItemType = ListItemType.It em Or _
e.Item.ItemType = ListItemType.Al ternatingItem Then
If Not e.Item.DataItem Is Nothing Then

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

dim radio as RadioButtonList =
e.Item.Findcont rol("RadioButto nList1")

Dim dr As DataRowView = CType(e.Item.Da taItem,
DataRowView)
dim dv as Dataview
dv=dr.CreateChi ldView("Pytania Odpowiedzi")
radio.DataSourc e = dv
radio.DataTextF ield="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 :-)


"Saravana" <sa******@sct.c o.in> wrote in message
news:3Z******** *********@news. cpqcorp.net...
You loop through each control in the page and check that control type. If

it
is checkbox or radiobuttonlist then you can get the selected value of that
control. To know how to loop through controls in a page, check out this
article
http://www.extremeexperts.com/Net/Ar...hControls.aspx
"krzysiek" <kr**********@h otmail.com> wrote in message
news:cl******** ***@news2.ipart ners.pl...
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 ?



Nov 18 '05 #4
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_li st" is
also nested in another master DataList which is called "ankieta_li st". So
following your e.g. i wrote:

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

For Each item in ankieta_list.It ems
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.It ems

For Each ctrl In
pyt_item.Contro ls

If TypeOf ctrl Is
TextBox Then

do somth...
end if
next
next
End If
next
Next
.... and it works !! :-)

Thanks a lot Joel !!
"Joel Cade" <jo**@nospam.fi gtreesolutions. com> wrote in message
news:90******** *************** ***********@mic rosoft.com...
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.It ems
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

"krzysiek" wrote:
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_lis t" runat="server" Width="100%" >
<ItemTemplate >
<table width="100%" >
<tr><td >
<asp:CheckBoxLi st id="box" runat="server"
</asp:CheckBoxLis t>

<asp:TextBox id="TextBox1" runat="server"
visible="false" ></asp:TextBox>
<asp:RadioButto nList id="RadioButton List1"
runat="server"> </asp:RadioButton List>
</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 DataListItemEve ntArgs)
If e.Item.ItemType = ListItemType.It em Or _
e.Item.ItemType = ListItemType.Al ternatingItem Then
If Not e.Item.DataItem Is Nothing Then

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

dim radio as RadioButtonList =
e.Item.Findcont rol("RadioButto nList1")

Dim dr As DataRowView = CType(e.Item.Da taItem,
DataRowView)
dim dv as Dataview
dv=dr.CreateChi ldView("Pytania Odpowiedzi")
radio.DataSourc e = dv
radio.DataTextF ield="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 :-)


"Saravana" <sa******@sct.c o.in> wrote in message
news:3Z******** *********@news. cpqcorp.net...
You loop through each control in the page and check that control type. If
it
is checkbox or radiobuttonlist then you can get the selected value of
that control. To know how to loop through controls in a page, check out this article
http://www.extremeexperts.com/Net/Ar...hControls.aspx
"krzysiek" <kr**********@h otmail.com> wrote in message
news:cl******** ***@news2.ipart ners.pl...
> 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 ?
>
>


Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2826
by: Vipin Kedia | last post by:
Hi I have written a code for showing the list boxes as selected using a Listitem and the selected property of the items. Now I have 2 list boxes in my page. But it shows only the selected values of the last list box in both the list boxes. If i reverse the calls to the filllistbox methods it shows the value selected for the 1st list box in...
4
6293
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by the choice from the drop down box. Something like: <form name="populatefrm" id="contactfrm" method="post"
1
2754
by: smash2004 | last post by:
I want to keep selected values in select list when i click on another option...with a click on a mouse... if i have 3 options in select list and i click first option..it gets selected..if i then click on third option ..it gets selected but i want also the first option to stay selected when i click on option that is already selected, then...
5
2412
by: Elvis V. | last post by:
Good morning, I have a table with three fields, Buildings, Floors and Rooms. This is what I would like to do; in my form when I select Building1 in my drop down box for Buildings, when I go to the next drop down field which is Floors, all I would like to see is just the floors that belong to Building1 only and then once I have selected a...
2
5797
by: Stephen Miller | last post by:
When I dynamically populate a HtmlSelect combo box, the Value property consistently fails to return the item selected, defaulting instead to the first item in the list. For example: Protected WithEvents Fruits As System.Web.UI.HtmlControls.HtmlSelect Protected WithEvents Results As System.Web.UI.WebControls.Label Protected WithEvents...
4
3992
by: juststarter | last post by:
Hello, I have an aspx file where i've put a placeholder element. On load (page_load) i create dynamically an html table which contains a checkbox and a radiobuttonlist in each tablerow . The radiobuttonlist contains two items (yes,no). Both the checkboxes and the radiobuttonlist are NOT autopostbacked ( .autopostback = false). When i press...
2
2752
by: John | last post by:
I have a listbox that is databound when my form loads. A user can then select and option using a drop down box. When the user selects an option the corresponding items in the listbox gets selected. How can I show those selected items at the top of my listbox. The issue is when the user selects an item and it is in the middle of the list, the...
2
2025
by: mumbaimacro | last post by:
hi i have two combo boxes in a form with values from a table. i need a report to be opened by a button from the form ,The Report should show the values selected in the combo boxes in the form and also i am going to show some other values from tables in the report with that. example: form view: month: jan -->...
6
5840
by: yasodhai | last post by:
Hi, I used a dropdown control which is binded to a datagrid control. I passed the values to the dropdownlist from the database using a function as follows in the aspx itself. <asp:DropDownList ID="FldType_add" Runat="server" DataSource='< %#GetFieldType()%>' DataValueField="Type" DataTextField="Type" /> Oce the page is loaded all the...
9
9909
by: ajos | last post by:
Hello friends, After thinking about this for sometime, i decided to post this in the java forum. Well my problem here in detail is, i have 3 jsp pages where in a.jsp(for example) i have a combo box, based on the selection of the value in that combo box, b.jsp page gets populated with the value associated to a.jsp, and again based on the...
0
7686
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8014
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8060
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6407
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5581
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3731
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2197
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1297
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.