|
 |
aspx_beginners thread: Create RadioButtonList
Message #1 by "Lena" <lena_nyman@h...> on Thu, 7 Mar 2002 17:34:52 +0100
|
|
This is a multi-part message in MIME format.
------=_NextPart_000_0005_01C1C5FE.63402DC0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi
I would like some help to know how to create a
RadioButtonList.
I am getting my values from a xml-file using
this expression.
while objIterator.MoveNext()
myVar =3D objIterator.Current.Value
end while
I can get the values I want but I want to create a
RadioButtonList connected to them.
Grateful of all help.
Lena
Message #2 by "Dan McKinnon" <mddonna@q...> on Wed, 13 Mar 2002 02:19:10
|
|
> I would like some help to know how to create a
> RadioButtonList.
> I am getting my values from a xml-file using
> this expression.
>
> while objIterator.MoveNext()
> myVar =3D objIterator.Current.Value
> end while
>
> I can get the values I want but I want to create a
> RadioButtonList connected to them.
Hi Lena,
It used to discourage me when I would post a message and no one answered
it. I don't know how much value my answer will be to you, but maybe you
can use something. What I can give you are some bits and pieces. I am a
newcomer to .NET, and not all that great a coder anyway.
The first thing, I don't know about:
while objIterator.MoveNext()
myVar = objIterator.Current.Value
End While
as a valid xml reader, but I will take your word for it. Does it move
among nodes? Wouldn't this change the value in myVar with every loop? I
would want to code this as:
Do While objIterator.MoveNext()
myVar += objIterator.Current.Value & ";"
counter++
Loop
That way you are stuffing all these values into a variable and, for lack
of any other strategy, I would put this myVar variable into an array:
Dim myArray(counter - 1) As String
myArray = split(myVar, ";")
Then you might be able to bind this array to the RadioButtonList control.
Or maybe not, but I don't see why not because in "Beginning ASP.NET using
VB.NET" I saw this:
Colorlist.DataSource = arrColors ' colorlist is a dropdown list control
Page.Databind() ' and you are binding it here, though why not
colorlist.databind() ?
If you or anyone else can correct my concepts or code, please have at it.
Dan
Message #3 by "Dan McKinnon" <mddonna@q...> on Wed, 13 Mar 2002 09:56:15
|
|
Hi again -
Got a chance to play with this a bit. This works for me:
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Page Language="VB" Debug="true" %>
<script language="VB" runat="server" >
Sub Page_Load()
Dim objDataSet As New DataSet()
objDataSet.ReadXML(Server.MapPath("bookstore.xml"))
radiolist1.DataSource = objDataSet.Tables(0).Defaultview
radioList1.DataValueField="ISBN"
radioList1.DataTextField="Title"
radiolist1.DataBind()
End Sub
</script>
<html>
<head><title>Populating a Radio Button List from an xml File</title>
</head>
<body>
<form runat="server">
<asp:radiobuttonlist id="RadioList1" runat="server"></asp:radiobuttonlist>
</form>
</body>
</html>
It lacks a way to submit the data. And it might have liabilities I don't
know about. I just kept experimenting until it worked.
HTH,
Dan
Message #4 by "lena nyman" <lena_nyman@h...> on Wed, 13 Mar 2002 10:11:06 +0000
|
|
>From: "Dan McKinnon" <mddonna@q...>
>Reply-To: "aspx_beginners" <aspx_beginners@p...>
>To: "aspx_beginners" <aspx_beginners@p...>
>Subject: [aspx_beginners] Re: Create RadioButtonList
>Date: Wed, 13 Mar 2002 09:56:15
>
>Hi again -
>
>Got a chance to play with this a bit. This works for me:
>
><%@ Import Namespace="System" %>
><%@ Import Namespace="System.Data" %>
><%@ Page Language="VB" Debug="true" %>
>
><script language="VB" runat="server" >
>Sub Page_Load()
>
>Dim objDataSet As New DataSet()
>objDataSet.ReadXML(Server.MapPath("bookstore.xml"))
>
>radiolist1.DataSource = objDataSet.Tables(0).Defaultview
>radioList1.DataValueField="ISBN"
>radioList1.DataTextField="Title"
>radiolist1.DataBind()
>
>End Sub
></script>
>
><html>
><head><title>Populating a Radio Button List from an xml File</title>
></head>
><body>
><form runat="server">
><asp:radiobuttonlist id="RadioList1" runat="server"></asp:radiobuttonlist>
></form>
></body>
></html>
>
>It lacks a way to submit the data. And it might have liabilities I don't
>know about. I just kept experimenting until it worked.
>HTH,
>Dan
>$subst('Email.Unsub').
Thank's for your suggestion, but I have a very complex
xml-file with many attributes so I can't figure out how many
tables I would have to use.
I have managed to create the radiobuttonlist like this:
dim objIterator as XPathNodeIterator = objNav.Select("//something/@name")
dim myArray as New ArrayList()
while objIterator.MoveNext()
strOutput = objIterator.Current.Value
myArray.Add(strOutput)
end while
radio1.DataSource=myArray
radio1.DataBind()
in a form I have put RadioButtonList radio1
but when I try to get SelectedIndex the value is always -1
Lena
_________________________________________________________________
Hämta MSN Explorer kostnadsfritt på http://explorer.msn.se/intl.asp
Message #5 by "Dan McKinnon" <mddonna@q...> on Thu, 14 Mar 2002 00:27:15
|
|
Hi Lena -
I read your last post. You are operating at a higher level than I am and
I don't know how to help you. I wouldn't be at all afraid to post this
question on one of the more advanced aspx forums.
Dan
Message #6 by "Ken Schaefer" <ken@a...> on Thu, 14 Mar 2002 15:20:58 +1100
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "lena nyman" <lena_nyman@h...>
Subject: [aspx_beginners] Re: Create RadioButtonList
: Thank's for your suggestion, but I have a very complex
: xml-file with many attributes so I can't figure out how many
: tables I would have to use.
: I have managed to create the radiobuttonlist like this:
:
: dim objIterator as XPathNodeIterator = objNav.Select("//something/@name")
:
: dim myArray as New ArrayList()
: while objIterator.MoveNext()
: strOutput = objIterator.Current.Value
: myArray.Add(strOutput)
: end while
:
: radio1.DataSource=myArray
: radio1.DataBind()
:
: in a form I have put RadioButtonList radio1
:
: but when I try to get SelectedIndex the value is always -1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Can you show us the code you are using (eg both the form, and how you are
getting the selectedindex?
I just whipped this up quickly in VS.Net (so apologies for the inane
variables names etc), and it seems to work fine using an ArrayList as the
datasource of a RadioButtonList.
Cheers
Ken
<%@ Page Language="vb"%>
<script runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
If not isPostBack() then
Dim arrList as New ArrayList()
arrList.Add("red")
arrList.Add("blue")
arrList.Add("green")
RadioButtonList1.DataSource = arrList
RadioButtonList1.DataBind
End If
End Sub
Private Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As EventArgs)
lblMessage.Text = "You selected index: " &
radioButtonList1.SelectedIndex.ToString & _
" and item " & radioButtonList1.SelectedItem.ToString
End Sub
</script>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>Test Page 3</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:radiobuttonlist id=RadioButtonList1 runat="server"
autopostback="True"
onselectedindexchanged="RadioButtonList1_SelectedIndexChanged" /><br>
<hr align="center" width="95%" size="1">
<asp:label id=lblMessage runat="server" />
</form>
</body>
</html>
Message #7 by "lena nyman" <lena_nyman@h...> on Thu, 14 Mar 2002 08:10:42 +0000
|
|
>From: "Ken Schaefer" <ken@a...>
>Reply-To: "aspx_beginners" <aspx_beginners@p...>
>To: "aspx_beginners" <aspx_beginners@p...>
>Subject: [aspx_beginners] Re: Create RadioButtonList
>Date: Thu, 14 Mar 2002 15:20:58 +1100
>
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>From: "lena nyman" <lena_nyman@h...>
>Subject: [aspx_beginners] Re: Create RadioButtonList
>
>
>: Thank's for your suggestion, but I have a very complex
>: xml-file with many attributes so I can't figure out how many
>: tables I would have to use.
>: I have managed to create the radiobuttonlist like this:
>:
>: dim objIterator as XPathNodeIterator = objNav.Select("//something/@name")
>:
>: dim myArray as New ArrayList()
>: while objIterator.MoveNext()
>: strOutput = objIterator.Current.Value
>: myArray.Add(strOutput)
>: end while
>:
>: radio1.DataSource=myArray
>: radio1.DataBind()
>:
>: in a form I have put RadioButtonList radio1
>:
>: but when I try to get SelectedIndex the value is always -1
>
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>Can you show us the code you are using (eg both the form, and how you are
>getting the selectedindex?
>I just whipped this up quickly in VS.Net (so apologies for the inane
>variables names etc), and it seems to work fine using an ArrayList as the
>datasource of a RadioButtonList.
>
>Cheers
>Ken
>
><%@ Page Language="vb"%>
><script runat="server">
>Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
>System.EventArgs)
>
> If not isPostBack() then
> Dim arrList as New ArrayList()
> arrList.Add("red")
> arrList.Add("blue")
> arrList.Add("green")
> RadioButtonList1.DataSource = arrList
> RadioButtonList1.DataBind
> End If
>End Sub
>
>Private Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As Object,
>ByVal e As EventArgs)
> lblMessage.Text = "You selected index: " &
>radioButtonList1.SelectedIndex.ToString & _
> " and item " & radioButtonList1.SelectedItem.ToString
>End Sub
></script>
>
><!doctype html public "-//w3c//dtd html 4.0 transitional//en">
><html>
> <head>
> <title>Test Page 3</title>
> </head>
> <body>
> <form id="Form1" method="post" runat="server">
> <asp:radiobuttonlist id=RadioButtonList1 runat="server"
>autopostback="True"
>onselectedindexchanged="RadioButtonList1_SelectedIndexChanged" /><br>
> <hr align="center" width="95%" size="1">
> <asp:label id=lblMessage runat="server" />
> </form>
> </body>
></html>
>
>
>$subst('Email.Unsub').
Thank you very much Ken.
It worked. What I hadn't done before was using the
if not page.ispostback. When I did it worked allright.
Thanks again!
Lena
_________________________________________________________________
Kom med i världens största e-posttjänst; MSN Hotmail.
http://www.hotmail.com/sv
|
|
 |