RadioButtonList, and more

N

news.iq.ca

Hello.

Although I am an experienced VB programmer, I am an ***absolute*** beginner
with ASP, net or otherwise, so my question might be silly....

I have written this code as an exercise (in notepad - I don't want to use
VSNet until I know ASP well enough):

<%@debug="true"%>
<%@ Import namespace="system.data"%>
<html>
<head><title>RadioButtonList.aspx</title></head>
<body>
<form id="RadioButtonList" runat="server">
<asp:label id="lblTitle1" text="Radio Button List - RGB created in
declaration." runat="server"/>
<br>
<asp:label id="lblTitle2" text="Radio Button List - 'Pink' and 'Indigo'
created with Items.Add in Page_Load." runat="server"/>
<br>
<asp:label id="lblTitle3" text="Radio Button List - 'Magenta' and 'Black'
created by binding to a data source." runat="server"/>
<asp:radiobuttonlist id="radFavColour1" Value="Blue" Tooltip="Unbound"
Enableviewstate="false" runat="server">
<asp:listitem text="Red" forecolor="Red" Backcolor = "Black" Value="R"/>
<asp:listitem text="Green" forecolor="Green" Value="G"/>
<asp:listitem text="Blue" Value="B"/>
</asp:radiobuttonlist>
<asp:radiobuttonlist id="radFavColour2" datatextformatstring="Bound item -
{0}" Tooltip="Bound" Enableviewstate="false" runat="server"/>
<p>
<asp:button text="Okay" accesskey="O" onclick="Button_Click"
runat="server"/>
<br>
<asp:label id="lblTitle4" runat="server"/>
<hr>
</form>
</body>
</html>

<script runat="server">
sub Page_load
dim dtblColours as new datatable
dim drowNewColour as datarow

if not ispostback then
radfavcolour1.items.add(new listitem("Pink", "P"))
radfavcolour1.items.add(new listitem("Indigo", "I"))

dtblcolours.columns.add(new datacolumn("Name", gettype(string)))
dtblcolours.columns.add(new datacolumn("Code", gettype(string)))

drowNewColour=dtblcolours.newrow()
drowNewColour("Name")="Magenta"
drowNewColour("Code")="M"
dtblcolours.rows.add(drowNewColour)

drowNewColour=dtblcolours.newrow()
drowNewColour("Name")="Yellow"
drowNewColour("Code")="Y"
dtblcolours.rows.add(drowNewColour)

radfavcolour2.datasource=dtblcolours
radfavcolour2.dataTextfield="Name"
radfavcolour2.dataValueField="Code"
radfavcolour2.databind()
end if
end sub

sub Button_Click(s as object, e as eventargs)

dim boolSelCount1 as boolean
dim boolSelCount2 as boolean
dim intCount as integer

for intcount=0 to radFavColour1.items.count-1
if radFavColour1.items(intcount).selected=True then
boolSelCount1=true
exit for
end if
next intcount

for intcount=0 to radFavColour2.items.count-1
if radFavColour2.items(intcount).selected=True then
boolSelCount2=true
exit for
end if
next intcount

if (boolSelCount1 and boolSelCount2)=true then
lbltitle4.text = "You have selected: <br><li>" &
radFavColour1.selecteditem.text & ", " & radFavColour1.selectedindex & ", "
& radFavColour1.selecteditem.value & "<br><li>" &
radFavColour2.selecteditem.text & ", " & radFavColour2.selectedindex & ", "
& radFavColour2.selecteditem.value

elseif boolSelCount1 =true then
lbltitle4.text = "You have selected: <br><li>" &
radFavColour1.selecteditem.text & ", " & radFavColour1.selectedindex & ", "
& radFavColour1.selecteditem.value

elseif boolSelCount2 =true then
lbltitle4.text = "You have selected: <br><li>" &
radFavColour2.selecteditem.text & ", " & radFavColour2.selectedindex & ", "
& radFavColour2.selecteditem.value

end if
end sub
</script>

Note - The whole thing with boolSelCount1 and boolSelCount2 is for avoiding
the "not an object" error.

Question 1: EnableViewState, at laest for the radiobuttonlists, behaves
strangely. Since I added Enableviewstate="false" to BOTH controls, when I
click on Okay the second buttonlist simply disappears !!! The first one
stays put, however. Is there any explanation to this ?

Question 2: Even for the first RadioButtonList, if I press F5 I expected it
to reload clean, without my previous selection, green, for instance. Still,
it loads the same - the only way to obtain a clean page again is to go into
the address bar and press Enter. Is this the way it should behave ? In this
case, what does F5 do ? Doesn't it reload the page ??? Even worse, say I
make a mod in the code - let's say I add an item in some list. I press F5 -
I can't see the new item. I press enter in the address box - the same
result. I navigate onto another page, I return - the same. Sometimes THE
ONLY WAY to see my mod is to close the browser and restart it. I'm
completely confused, especially because it doesn't happen always !

Question 3: In the help file I read that Forecolor is a property of almost
all controls, including this one. Still, specifying a forecolour doesn't do
anything. I tried that with a table, and it works fine. Where is the problem
? Is it on my side, or is there something wrong with the RadioButtonList ?

Thank you for reading my post.
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top