473,748 Members | 2,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

radiobuttonlist get selected item

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 the submit button a sub (submit_pressed ) is run. My
problem is that i can not get the selected items in the radiobuttonlist s.This
is caused cos in the page_load event i call the sub that dynamically
recreates the table described above and so all values are reset (there is a
rdb.item(0).sel ected=true line in my
code. If i try to remove that line of code, the radiobuttons keep their
values or not,after each submit, without a pattern (at least not one that i
can see)!). 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 radiobuttonlist s) 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

here is a portion of the code
in vb code
--------------------
1. create the (html) table through code

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s)
Dim ID as integer = Request("ID")
call addControlsInPl aceholder()
End Sub
sub addControlsInPl aceholder
'create the table
dim oTable as new table
oTable.id="oTab le"
oTable.GridLine s=GridLines.Non e
'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=uni t.pixel(180)
cell2.width=uni t.pixel(120)

dim row1 as new tablerow

lb1.text= Category"
lb2.text= "isDisplaye d"

'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,su bcListItem1,sub cListItem2 As ListItem

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

strSQL = " SELECT ctg_id, ctg_name FROM categories ORDER BY ctg_id"
Dim myCommand As New OdbcCommand(str SQL, myConnection)
myConnection.Op en()
Dim myReader As OdbcDataReader = myCommand.Execu teReader()

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=un it.pixel(180)
oCell2.width=un it.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").ToStri ng
chkboxlist.text =myReader.Item( "ctg_name").ToS tring
oCell1.controls .add(chkboxlist )

'create radiobuttonlist and add it cell2 (the second cell of each row)
dim rdbDisplayed as new radiobuttonlist
rdbDisplayed.Re peatDirection=r epeatdirection. Horizontal
rdbDisplayed.id ="cs_isDisplaye d_" & myReader.Item(" ctg_id").ToStri ng

'add items in radiobuttonlist s
subcListItem1 = New ListItem
subcListItem1.T ext = "yes"
subcListItem1.V alue = "1"
rdbDisplayed.It ems.Add(subcLis tItem1)

subcListItem2 = New ListItem
subcListItem2.T ext = "no"
subcListItem2.V alue = "0"
rdbDisplayed.It ems.Add(subcLis tItem2)
rdbDisplayed.it ems(0).selected =true

oCell2.controls .add(rdbDisplay ed)
'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.a dd(oTable)

myCommand.dispo se
myConnection.cl ose

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,rd bAdult as radiobuttonlist

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

for i = 1 to otable.rows.cou nt-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(0) is a radiobuttonlist
rdbDisplayed = tc.controls(0)

'************** **************
'the following line always returns item(0) cos the sub
addControlsInPl aceholder has already run (it's called in the page_load event)
before the submit_pressed is called
displayed = rdbDisplayed.se lecteditem.valu e
'************** ***************

if chk.checked = true then
'show displayed
end if

next

end sub
Nov 19 '05 #1
4 4000
Remove the bind from your Page_Load and put into its own routine. Only call
from Page_Load if it is not a Postback. If you need to rebind, do it from
your button click after you retrieve values. Ordering of events is fixed, so
you have to be flexible.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************** ************
Think Outside the Box!
*************** ************
"juststarte r" wrote:
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 the submit button a sub (submit_pressed ) is run. My
problem is that i can not get the selected items in the radiobuttonlist s.This
is caused cos in the page_load event i call the sub that dynamically
recreates the table described above and so all values are reset (there is a
rdb.item(0).sel ected=true line in my
code. If i try to remove that line of code, the radiobuttons keep their
values or not,after each submit, without a pattern (at least not one that i
can see)!). 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 radiobuttonlist s) 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

here is a portion of the code
in vb code
--------------------
1. create the (html) table through code

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s)
Dim ID as integer = Request("ID")
call addControlsInPl aceholder()
End Sub
sub addControlsInPl aceholder
'create the table
dim oTable as new table
oTable.id="oTab le"
oTable.GridLine s=GridLines.Non e
'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=uni t.pixel(180)
cell2.width=uni t.pixel(120)

dim row1 as new tablerow

lb1.text= Category"
lb2.text= "isDisplaye d"

'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,su bcListItem1,sub cListItem2 As ListItem

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

strSQL = " SELECT ctg_id, ctg_name FROM categories ORDER BY ctg_id"
Dim myCommand As New OdbcCommand(str SQL, myConnection)
myConnection.Op en()
Dim myReader As OdbcDataReader = myCommand.Execu teReader()

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=un it.pixel(180)
oCell2.width=un it.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").ToStri ng
chkboxlist.text =myReader.Item( "ctg_name").ToS tring
oCell1.controls .add(chkboxlist )

'create radiobuttonlist and add it cell2 (the second cell of each row)
dim rdbDisplayed as new radiobuttonlist
rdbDisplayed.Re peatDirection=r epeatdirection. Horizontal
rdbDisplayed.id ="cs_isDisplaye d_" & myReader.Item(" ctg_id").ToStri ng

'add items in radiobuttonlist s
subcListItem1 = New ListItem
subcListItem1.T ext = "yes"
subcListItem1.V alue = "1"
rdbDisplayed.It ems.Add(subcLis tItem1)

subcListItem2 = New ListItem
subcListItem2.T ext = "no"
subcListItem2.V alue = "0"
rdbDisplayed.It ems.Add(subcLis tItem2)
rdbDisplayed.it ems(0).selected =true

oCell2.controls .add(rdbDisplay ed)
'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.a dd(oTable)

myCommand.dispo se
myConnection.cl ose

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,rd bAdult as radiobuttonlist

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

for i = 1 to otable.rows.cou nt-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(0) is a radiobuttonlist
rdbDisplayed = tc.controls(0)

'************** **************
'the following line always returns item(0) cos the sub
addControlsInPl aceholder has already run (it's called in the page_load event)
before the submit_pressed is called
displayed = rdbDisplayed.se lecteditem.valu e
'************** ***************

if chk.checked = true then
'show displayed
end if

next

end sub

Nov 19 '05 #2
juststarter,

I have some example code on using dynamic controls on my website:
http://www.aboutfortunate.com?page=codelibrary if you go to the given page
and use the search box there to search for "dynamic" you'll get all the
examples in the search results. There are only about 3 or 4 and I think that
it would benefit you to take a look at them.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"juststarte r" <ju*********@di scussions.micro soft.com> wrote in message
news:78******** *************** ***********@mic rosoft.com...
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 the submit button a sub (submit_pressed ) is run. My
problem is that i can not get the selected items in the
radiobuttonlist s.This
is caused cos in the page_load event i call the sub that dynamically
recreates the table described above and so all values are reset (there is
a
rdb.item(0).sel ected=true line in my
code. If i try to remove that line of code, the radiobuttons keep their
values or not,after each submit, without a pattern (at least not one that
i
can see)!). 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 radiobuttonlist s) 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

here is a portion of the code
in vb code
--------------------
1. create the (html) table through code

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s)
Dim ID as integer = Request("ID")
call addControlsInPl aceholder()
End Sub
sub addControlsInPl aceholder
'create the table
dim oTable as new table
oTable.id="oTab le"
oTable.GridLine s=GridLines.Non e
'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=uni t.pixel(180)
cell2.width=uni t.pixel(120)

dim row1 as new tablerow

lb1.text= Category"
lb2.text= "isDisplaye d"

'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,su bcListItem1,sub cListItem2 As ListItem

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

strSQL = " SELECT ctg_id, ctg_name FROM categories ORDER BY ctg_id"
Dim myCommand As New OdbcCommand(str SQL, myConnection)
myConnection.Op en()
Dim myReader As OdbcDataReader = myCommand.Execu teReader()

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=un it.pixel(180)
oCell2.width=un it.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").ToStri ng
chkboxlist.text =myReader.Item( "ctg_name").ToS tring
oCell1.controls .add(chkboxlist )

'create radiobuttonlist and add it cell2 (the second cell of each row)
dim rdbDisplayed as new radiobuttonlist
rdbDisplayed.Re peatDirection=r epeatdirection. Horizontal
rdbDisplayed.id ="cs_isDisplaye d_" & myReader.Item(" ctg_id").ToStri ng

'add items in radiobuttonlist s
subcListItem1 = New ListItem
subcListItem1.T ext = "yes"
subcListItem1.V alue = "1"
rdbDisplayed.It ems.Add(subcLis tItem1)

subcListItem2 = New ListItem
subcListItem2.T ext = "no"
subcListItem2.V alue = "0"
rdbDisplayed.It ems.Add(subcLis tItem2)
rdbDisplayed.it ems(0).selected =true

oCell2.controls .add(rdbDisplay ed)
'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.a dd(oTable)

myCommand.dispo se
myConnection.cl ose

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,rd bAdult as radiobuttonlist

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

for i = 1 to otable.rows.cou nt-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(0) is a radiobuttonlist
rdbDisplayed = tc.controls(0)

'************** **************
'the following line always returns item(0) cos the sub
addControlsInPl aceholder has already run (it's called in the page_load
event)
before the submit_pressed is called
displayed = rdbDisplayed.se lecteditem.valu e
'************** ***************

if chk.checked = true then
'show displayed
end if

next

end sub

Nov 19 '05 #3
Thx both for your help,
what i did is the following :
in page_load event i added:

if not page.ispostback then
call addControlsInPl aceholder()
end if

in the submit_pressed sub i added the following line in the end of the sub
(so that i recreate the html table after i save the values of the
radiobuttonlist :
call addControlsInPl aceholder()

the problem is that the line (in the submit_pressed sub) :
otable = ctype((plh1.con trols(0)),table )
is returning an error because plh1 doesn't have any controls any more.

Doesn't the placeholder retain the controls added to it, after the postback
is done, or am i missing something?

theodore

"Cowboy (Gregory A. Beamer) - MVP" wrote:
Remove the bind from your Page_Load and put into its own routine. Only call
from Page_Load if it is not a Postback. If you need to rebind, do it from
your button click after you retrieve values. Ordering of events is fixed, so
you have to be flexible.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************** ************
Think Outside the Box!
*************** ************
"juststarte r" wrote:
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 the submit button a sub (submit_pressed ) is run. My
problem is that i can not get the selected items in the radiobuttonlist s.This
is caused cos in the page_load event i call the sub that dynamically
recreates the table described above and so all values are reset (there is a
rdb.item(0).sel ected=true line in my
code. If i try to remove that line of code, the radiobuttons keep their
values or not,after each submit, without a pattern (at least not one that i
can see)!). 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 radiobuttonlist s) 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

here is a portion of the code
in vb code
--------------------
1. create the (html) table through code

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s)
Dim ID as integer = Request("ID")
call addControlsInPl aceholder()
End Sub
sub addControlsInPl aceholder
'create the table
dim oTable as new table
oTable.id="oTab le"
oTable.GridLine s=GridLines.Non e
'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=uni t.pixel(180)
cell2.width=uni t.pixel(120)

dim row1 as new tablerow

lb1.text= Category"
lb2.text= "isDisplaye d"

'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,su bcListItem1,sub cListItem2 As ListItem

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

strSQL = " SELECT ctg_id, ctg_name FROM categories ORDER BY ctg_id"
Dim myCommand As New OdbcCommand(str SQL, myConnection)
myConnection.Op en()
Dim myReader As OdbcDataReader = myCommand.Execu teReader()

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=un it.pixel(180)
oCell2.width=un it.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").ToStri ng
chkboxlist.text =myReader.Item( "ctg_name").ToS tring
oCell1.controls .add(chkboxlist )

'create radiobuttonlist and add it cell2 (the second cell of each row)
dim rdbDisplayed as new radiobuttonlist
rdbDisplayed.Re peatDirection=r epeatdirection. Horizontal
rdbDisplayed.id ="cs_isDisplaye d_" & myReader.Item(" ctg_id").ToStri ng

'add items in radiobuttonlist s
subcListItem1 = New ListItem
subcListItem1.T ext = "yes"
subcListItem1.V alue = "1"
rdbDisplayed.It ems.Add(subcLis tItem1)

subcListItem2 = New ListItem
subcListItem2.T ext = "no"
subcListItem2.V alue = "0"
rdbDisplayed.It ems.Add(subcLis tItem2)
rdbDisplayed.it ems(0).selected =true

oCell2.controls .add(rdbDisplay ed)
'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.a dd(oTable)

myCommand.dispo se
myConnection.cl ose

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,rd bAdult as radiobuttonlist

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

for i = 1 to otable.rows.cou nt-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(0) is a radiobuttonlist
rdbDisplayed = tc.controls(0)

'************** **************
'the following line always returns item(0) cos the sub
addControlsInPl aceholder has already run (it's called in the page_load event)
before the submit_pressed is called
displayed = rdbDisplayed.se lecteditem.valu e
'************** ***************

if chk.checked = true then
'show displayed
end if

next

end sub

Nov 19 '05 #4
juststarter,

No you have to recreate any controls added dynamically to a page upon each
page load.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"juststarte r" <ju*********@di scussions.micro soft.com> wrote in message
news:ED******** *************** ***********@mic rosoft.com...
Thx both for your help,
what i did is the following :
in page_load event i added:

if not page.ispostback then
call addControlsInPl aceholder()
end if

in the submit_pressed sub i added the following line in the end of the sub
(so that i recreate the html table after i save the values of the
radiobuttonlist :
call addControlsInPl aceholder()

the problem is that the line (in the submit_pressed sub) :
otable = ctype((plh1.con trols(0)),table )
is returning an error because plh1 doesn't have any controls any more.

Doesn't the placeholder retain the controls added to it, after the
postback
is done, or am i missing something?

theodore

"Cowboy (Gregory A. Beamer) - MVP" wrote:
Remove the bind from your Page_Load and put into its own routine. Only
call
from Page_Load if it is not a Postback. If you need to rebind, do it from
your button click after you retrieve values. Ordering of events is fixed,
so
you have to be flexible.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************** ************
Think Outside the Box!
*************** ************
"juststarte r" wrote:
> 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 the submit button a sub (submit_pressed ) is run.
> My
> problem is that i can not get the selected items in the
> radiobuttonlist s.This
> is caused cos in the page_load event i call the sub that dynamically
> recreates the table described above and so all values are reset (there
> is a
> rdb.item(0).sel ected=true line in my
> code. If i try to remove that line of code, the radiobuttons keep their
> values or not,after each submit, without a pattern (at least not one
> that i
> can see)!). 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 radiobuttonlist s) 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
>
> here is a portion of the code
> in vb code
> --------------------
> 1. create the (html) table through code
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArg s)
> Dim ID as integer = Request("ID")
> call addControlsInPl aceholder()
> End Sub
>
>
> sub addControlsInPl aceholder
> 'create the table
> dim oTable as new table
> oTable.id="oTab le"
> oTable.GridLine s=GridLines.Non e
>
>
> '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=uni t.pixel(180)
> cell2.width=uni t.pixel(120)
>
> dim row1 as new tablerow
>
> lb1.text= Category"
> lb2.text= "isDisplaye d"
>
> '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,su bcListItem1,sub cListItem2 As ListItem
>
> Dim myConnection As New OdbcConnection( Application("st rConnect"))
> dim strSQL as string
>
> strSQL = " SELECT ctg_id, ctg_name FROM categories ORDER BY ctg_id"
> Dim myCommand As New OdbcCommand(str SQL, myConnection)
> myConnection.Op en()
> Dim myReader As OdbcDataReader = myCommand.Execu teReader()
>
> 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=un it.pixel(180)
> oCell2.width=un it.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").ToStri ng
> chkboxlist.text =myReader.Item( "ctg_name").ToS tring
>
>
> oCell1.controls .add(chkboxlist )
>
> 'create radiobuttonlist and add it cell2 (the second cell of each row)
> dim rdbDisplayed as new radiobuttonlist
> rdbDisplayed.Re peatDirection=r epeatdirection. Horizontal
> rdbDisplayed.id ="cs_isDisplaye d_" & myReader.Item(" ctg_id").ToStri ng
>
> 'add items in radiobuttonlist s
> subcListItem1 = New ListItem
> subcListItem1.T ext = "yes"
> subcListItem1.V alue = "1"
> rdbDisplayed.It ems.Add(subcLis tItem1)
>
> subcListItem2 = New ListItem
> subcListItem2.T ext = "no"
> subcListItem2.V alue = "0"
> rdbDisplayed.It ems.Add(subcLis tItem2)
> rdbDisplayed.it ems(0).selected =true
>
> oCell2.controls .add(rdbDisplay ed)
>
>
> '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.a dd(oTable)
>
> myCommand.dispo se
> myConnection.cl ose
>
> 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,rd bAdult as radiobuttonlist
>
> 'plh1 is the placeholder in the html code
> otable = ctype((plh1.con trols(0)),table )
>
> for i = 1 to otable.rows.cou nt-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(0) is a radiobuttonlist
> rdbDisplayed = tc.controls(0)
>
> '************** **************
> 'the following line always returns item(0) cos the sub
> addControlsInPl aceholder has already run (it's called in the page_load
> event)
> before the submit_pressed is called
> displayed = rdbDisplayed.se lecteditem.valu e
> '************** ***************
>
> if chk.checked = true then
> 'show displayed
> end if
>
> next
>
> end sub

Nov 19 '05 #5

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

Similar topics

3
4330
by: juststarter | last post by:
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...
3
9007
by: William LaMartin | last post by:
If I create a RadioButtonList with, say, two items, then after the page loads and I select one of the items and then click on a button whose click event contains some code to display the RadioButtonlList's selected value, there is nothing. On a postback, with the dynamically created button list visible on the page and the first item selected, if I try some code like "If Me.RadioButtonList1.Items(0).Selected = True Then.......", then I...
5
5511
by: DotNetGruven | last post by:
Anyone have any pointers on how to set the Value and Selected attributes in a ListItem in a RadioButtonList that is in a DataGrid? Here's what I have ------DataGrid------ -- BoundColumn 0 -- -- BoundColumn 1 -- -- BoundColumn 2 -- -- TemplateColumn 4 -- -- RadioButtonList --
4
9662
by: Emil | last post by:
Can somebody tell me what would be the syntax for having an if statement and setting the selected index of a radiobuttonlist? This is my first project using ASP.net and I use C#. I have a repeater with like a table layout and in the last column I want to have three radio buttons (for each row in repeater). The value of the radio button should be calculated from a value from the dataset. How can I do that? When I try to use a variable...
3
1417
by: Mark Broadbent | last post by:
try as I might (and using different properties) this control always seems to be returning the first element of the control as the "selected" item even though I am selecting the second element. All I need it the index number to reference a particular row num of a dataset. I only just noticed this today but it if I cant determine the selected radiobuttonlist item then it reders this control useless. Hope someone can help? --
0
1974
by: Luis Esteban Valencia | last post by:
http://www.codeproject.com/aspnet/DataGridCCEvents.asp#xx1009236xx Read this first and see if you can help me have tried but the Intelisense of the radiobuttonlist doestn have the event selectedindexchanged? I have a datagrrid with an itemtemplate, inside this itemtemplate thre is a radiobuttonlist with 3 options. There is also a label to the side of this radiobuttonlist.
0
1275
by: Hugo Flores | last post by:
Hi, Here's the situation: I create a table on run time(Page_Init) I add a textbox to the first row I add a RadioButtonList in that same row The problem is that when I try to get the values that the user selected from the RadioButtonList I always end up getting the first item selected. At first my code had the first item selected by default, so I
0
1026
by: dougloj | last post by:
Hi, I have two RadioButtonLists on a.aspx page. Let's call them ListA and ListB. Each list has 3 list items. After any postback, the first list item of ListB always ends up being selected, regardless of which item in the list was selected before the postback. For example, if I select the third item of ListB and a postback occurs for whatever reason, the first item in ListB always ends up being selected after the postback. The item in...
6
2641
by: SAL | last post by:
hello, I'm using a radiobuttonlist in an updatepanel in an item template in a Gridview control. I'm populating the radiobuttonlist in the RowDataBound event. I have the control toolkit registered in the page and I've got code to get the selected value from it in the Radiobuttonlist_SelectedIndexChanged event. The code in there is: Protected Sub rblFMSValue_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
0
8984
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9530
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9363
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9312
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9238
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6793
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2775
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.