Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > radiobuttonlist get selected value

Reply
Thread Tools

radiobuttonlist get selected value

 
 
juststarter
Guest
Posts: n/a
 
      10-25-2005
Hello,
I have an aspx file where i've put a placeholder element. On load i create
dynamically a 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 the submit button a sub is run. My problem is that i can
not get the selected items in the radiobuttonlists.This is caused cos in the
page_load i call the sub that dinamically recreates the table described above
and so all values are reset (there is a rdb.item(0).selected=true line in my
code. If i try to remove it, the radiobuttons keep their values or not,after
each submit, without a pattern!). I've also tried to keep the values in a
collection, instasiated in the page_load but i couldn't do so cos the table
(that contains the checkboxes and radiobuttonlists) is not recognized at the
beggining of the page_load (i guess it's not an object yet cos the sub that
creates all that is at the end of page_load)....
Anyway...any ideas on how to get the selected item ? ? ? ?
thx a lot
theodore

 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      10-25-2005
juststarter wrote:
> Hello,
> I have an aspx file where i've put a placeholder element.


There was no way for you to know it, but this is a classic asp newsgroup.
While you may be lucky enough to find a dotnet-knowledgeable person here who
can answer your question, you can eliminate the luck factor by posting your
question to a group where those dotnet-knowledgeable people hang out. I
suggest microsoft.public.dotnet.framework.aspnet.

> On load i
> create dynamically a table


Is this an html table or a datagrid?

> 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 the submit
> button a sub is run. My problem is that i can not get the selected
> items in the radiobuttonlists.This is caused cos in the page_load i
> call the sub that dinamically recreates the table described above and
> so all values are reset (there is a rdb.item(0).selected=true line in
> my code. If i try to remove it, the radiobuttons keep their values or
> not,after each submit, without a pattern!). I've also tried to keep
> the values in a collection, instasiated in the page_load but i
> couldn't do so cos the table (that contains the checkboxes and
> radiobuttonlists) is not recognized at the beggining of the page_load
> (i guess it's not an object yet cos the sub that creates all that is
> at the end of page_load)....
> Anyway...any ideas on how to get the selected item ? ? ? ?
> thx a lot
> theodore


I think the answer is that you need to create these checkboxes in either the
page_init event, or in the ItemCreated event if you are creating a datagrid
instead of an html table. But you should ask in the aspnet group to be sure.

Bob Barrows
PS. It never hurts to show a little code ...

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
 
 
 
juststarter
Guest
Posts: n/a
 
      10-25-2005
Bob, thx for your time
I'll take your advice and post the message to the correspondent newsgroup (i
didn't understand this was for not.net.asp )

I tried to use the page_init event but it seems not to run at all (i'm sure
i'm doing something wrong.....)
Nevertheless,i send u a piece of my code...just in case.
The table i am creating is an html one.

In html code
--------------------
<asplaceholder id="plh1" runat="server"> </asplaceholder>

in vb code
--------------------
1. create the (html) table through code

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim ID as integer = Request("ID")
call addControlsInPlaceholder()
End Sub


sub addControlsInPlaceholder
'create the table
dim oTable as new table
oTable.id="oTable"
oTable.GridLines=GridLines.None


'first add the titles of each column
dim lb1 as new label
dim lb2 as new label

dim cell1 as new TableHeaderCell
dim cell2 as new TableHeaderCell

cell1.width=unit.pixel(180)
cell2.width=unit.pixel(120)

dim row1 as new tablerow

lb1.text= Category"
lb2.text= "isDisplayed"

'add labels to cells
Cell1.controls.add(lb1)
Cell2.controls.add(lb2)

'add (header) cells to row
Row1.cells.add(Cell1)
Row1.cells.add(Cell2)
'add header row to table
otable.rows.add(Row1)

'fill the chkboxlist/radiobuttonlist(s) with items
Dim id As String
Dim subcListItem,subcListItem1,subcListItem2 As ListItem

Dim myConnection As New OdbcConnection(Application("strConnect"))
dim strSQL as string

strSQL = " SELECT ctg_id, ctg_name FROM categories ORDER BY ctg_id"
Dim myCommand As New OdbcCommand(strSQL, myConnection)
myConnection.Open()
Dim myReader As OdbcDataReader = myCommand.ExecuteReader()

while myReader.Read()
'create new Row for the table
dim oRow as new tableRow
'create 2 cells for the row
dim oCell1 as new tableCell
dim oCell2 as new tableCell


oCell1.width=unit.pixel(180)
oCell2.width=unit.pixel(120)

'create checkbox and add it cell1 (the first cell of each row)
dim chkboxlist as new checkbox
chkboxlist.id = "categories_" & myReader.Item("ctg_id").ToString
chkboxlist.text=myReader.Item("ctg_name").ToString


oCell1.controls.add(chkboxlist)

'create radiobuttonlist and add it cell2 (the second cell of each row)
dim rdbDisplayed as new radiobuttonlist
rdbDisplayed.RepeatDirection=repeatdirection.Horiz ontal
rdbDisplayed.id="cs_isDisplayed_" & myReader.Item("ctg_id").ToString

'add items in radiobuttonlists
subcListItem1 = New ListItem
subcListItem1.Text = "yes"
subcListItem1.Value = "1"
rdbDisplayed.Items.Add(subcListItem1)

subcListItem2 = New ListItem
subcListItem2.Text = "no"
subcListItem2.Value = "0"
rdbDisplayed.Items.Add(subcListItem2)
rdbDisplayed.items(0).selected=true

oCell2.controls.add(rdbDisplayed)


'add cells to row
oRow.cells.add(oCell1)
oRow.cells.add(oCell2)

'add row to table
otable.rows.add(oRow)
'increase counter i, to create new row
i = i +1

end while
'add table to placeholder
plh1.controls.add(oTable)

myCommand.dispose
myConnection.close

end sub


3. when the submit button is pressed ,i try something like

private sub submit_pressed

dim otable as new table
dim tr as new tablerow
dim tc as new tablecell
dim chk as checkbox
dim i,displayed as int16
dim rdbDisplayed,rdbAdult as radiobuttonlist

otable = ctype((plh1.controls(0)),table) 'plh1 is the placeholder in the
html code

for i = 1 to otable.rows.count-1

tr = otable.controls(i)
tc = tr.controls(0)
'tc.control(0) is a checkbox
chk = tc.controls(0)

'table cell
tc = tr.controls(1)
'tc.ctontrol(1) is a radiobuttonlist
rdbDisplayed = tc.controls(0)
'********************************
'the following always returns item(0) cos addControlsInPlaceholder has
already run before submit_pressed is engaged
displayed = rdbDisplayed.selecteditem.value
'********************************
if chk.checked = true then
'show displayed
end if

next

end sub



 
Reply With Quote
 
Jevon
Guest
Posts: n/a
 
      10-25-2005
How are you trying to use Page_Init? To clarify what Bob said, it is here
you should be calling addControlsInPlaceholder, and not in Page_Load.

This page: http://www.15seconds.com/issue/020102.htm and the pages linked to
on this page: http://weblogs.asp.net/eporter/archi.../15/10109.aspx
might aid your understanding.

Jevon


"juststarter" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Bob, thx for your time
> I'll take your advice and post the message to the correspondent newsgroup
> (i
> didn't understand this was for not.net.asp )
>
> I tried to use the page_init event but it seems not to run at all (i'm
> sure
> i'm doing something wrong.....)
> Nevertheless,i send u a piece of my code...just in case.
> The table i am creating is an html one.
>
> In html code
> --------------------
> <asplaceholder id="plh1" runat="server"> </asplaceholder>
>
> in vb code
> --------------------
> 1. create the (html) table through code
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs)
> Dim ID as integer = Request("ID")
> call addControlsInPlaceholder()
> End Sub
>
>
> sub addControlsInPlaceholder
> 'create the table
> dim oTable as new table
> oTable.id="oTable"
> oTable.GridLines=GridLines.None
>
>
> 'first add the titles of each column
> dim lb1 as new label
> dim lb2 as new label
>
> dim cell1 as new TableHeaderCell
> dim cell2 as new TableHeaderCell
>
> cell1.width=unit.pixel(180)
> cell2.width=unit.pixel(120)
>
> dim row1 as new tablerow
>
> lb1.text= Category"
> lb2.text= "isDisplayed"
>
> 'add labels to cells
> Cell1.controls.add(lb1)
> Cell2.controls.add(lb2)
>
> 'add (header) cells to row
> Row1.cells.add(Cell1)
> Row1.cells.add(Cell2)
> 'add header row to table
> otable.rows.add(Row1)
>
> 'fill the chkboxlist/radiobuttonlist(s) with items
> Dim id As String
> Dim subcListItem,subcListItem1,subcListItem2 As ListItem
>
> Dim myConnection As New OdbcConnection(Application("strConnect"))
> dim strSQL as string
>
> strSQL = " SELECT ctg_id, ctg_name FROM categories ORDER BY ctg_id"
> Dim myCommand As New OdbcCommand(strSQL, myConnection)
> myConnection.Open()
> Dim myReader As OdbcDataReader = myCommand.ExecuteReader()
>
> while myReader.Read()
> 'create new Row for the table
> dim oRow as new tableRow
> 'create 2 cells for the row
> dim oCell1 as new tableCell
> dim oCell2 as new tableCell
>
>
> oCell1.width=unit.pixel(180)
> oCell2.width=unit.pixel(120)
>
> 'create checkbox and add it cell1 (the first cell of each row)
> dim chkboxlist as new checkbox
> chkboxlist.id = "categories_" & myReader.Item("ctg_id").ToString
> chkboxlist.text=myReader.Item("ctg_name").ToString
>
>
> oCell1.controls.add(chkboxlist)
>
> 'create radiobuttonlist and add it cell2 (the second cell of each row)
> dim rdbDisplayed as new radiobuttonlist
> rdbDisplayed.RepeatDirection=repeatdirection.Horiz ontal
> rdbDisplayed.id="cs_isDisplayed_" & myReader.Item("ctg_id").ToString
>
> 'add items in radiobuttonlists
> subcListItem1 = New ListItem
> subcListItem1.Text = "yes"
> subcListItem1.Value = "1"
> rdbDisplayed.Items.Add(subcListItem1)
>
> subcListItem2 = New ListItem
> subcListItem2.Text = "no"
> subcListItem2.Value = "0"
> rdbDisplayed.Items.Add(subcListItem2)
> rdbDisplayed.items(0).selected=true
>
> oCell2.controls.add(rdbDisplayed)
>
>
> 'add cells to row
> oRow.cells.add(oCell1)
> oRow.cells.add(oCell2)
>
> 'add row to table
> otable.rows.add(oRow)
> 'increase counter i, to create new row
> i = i +1
>
> end while
> 'add table to placeholder
> plh1.controls.add(oTable)
>
> myCommand.dispose
> myConnection.close
>
> end sub
>
>
> 3. when the submit button is pressed ,i try something like
>
> private sub submit_pressed
>
> dim otable as new table
> dim tr as new tablerow
> dim tc as new tablecell
> dim chk as checkbox
> dim i,displayed as int16
> dim rdbDisplayed,rdbAdult as radiobuttonlist
>
> otable = ctype((plh1.controls(0)),table) 'plh1 is the placeholder in the
> html code
>
> for i = 1 to otable.rows.count-1
>
> tr = otable.controls(i)
> tc = tr.controls(0)
> 'tc.control(0) is a checkbox
> chk = tc.controls(0)
>
> 'table cell
> tc = tr.controls(1)
> 'tc.ctontrol(1) is a radiobuttonlist
> rdbDisplayed = tc.controls(0)
> '********************************
> 'the following always returns item(0) cos addControlsInPlaceholder has
> already run before submit_pressed is engaged
> displayed = rdbDisplayed.selecteditem.value
> '********************************
> if chk.checked = true then
> 'show displayed
> end if
>
> next
>
> end sub
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get the selected item in RadioButtonList‎, that is in ajax tab container samin Software 0 12-13-2010 02:28 PM
Get the index of the selected button in radiobuttonlist svein.erik.storkas@gmail.com ASP .Net 6 11-05-2008 05:00 AM
AJAX extended radiobuttonlist unselects selected value in popup SAL ASP .Net 6 09-19-2008 03:44 AM
radiobuttonlist get selected item =?Utf-8?B?anVzdHN0YXJ0ZXI=?= ASP .Net 4 10-26-2005 05:30 PM
Get RadioButtonList's selected value in js mg ASP .Net 2 01-05-2004 11:47 AM



Advertisments