Hi Anthony,
Does the solution in my prior post meet your requirements?
It's possible to actually get the selected value by group name. But we need
to set the value attribution for every RadioButton. For example:
RadioFrom.Attributes .Add("value",RadioFrom.Text); Then, we add these radio
buttons to the table using the method in your first post.
Then, we can get the selected radio value using Request.Form["groupname
"].ToString () in code behind.
If we want to loop through each of the radio control in the User Control or
the page to check which radio button was checked using client side script,
we can do that like this:
1. Set the id for each radio control, something like: radio1,
radio2,¡¡
2. Set the same "groupname" for each radio control.
3. The client side script may like this:
<script language="javascript">
function checkradios(){
for(i=1;i<n;i++)
if(document.all("radio"+i).checked)
alert(document.all("radio"+i).value);
}
</script>
Does this answer your question? Please let me know if you need more
information.
Best regards,
Lewis
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "Anthony Williams" <
[email protected]>
| References: <
[email protected]>
<
[email protected]>
<
[email protected]>
<
[email protected]>
<
[email protected]>
| Subject: Re: Retrieving checked RadioButton controls which were added to
a Table control
| Date: Wed, 10 Sep 2003 12:37:07 +0100
| Lines: 353
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#
[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: host81-137-71-124.in-addr.btopenworld.com 81.137.71.124
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:14530
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
| Lewis,
|
| Sorry for the long answer, but basically, I thought it best to explain
| exactly what I'm doing here.
|
| I have created a user control which contains a calendar control and this
| free busy list which I'm creating. The date, as selected by the calendar
| control sets a DateTime variable on the page to the current date. The
| Free/Busy list then displays times from midnight on that day to midnight
the
| following day - a 24-hour block of 6-minute intervals.
|
| Ideally, I'd like to generate a table with 4 cells, like so:
|
| [Time] [Fr] [To] [Free/Busy]
| 00:00 () ()
| 00:06 () ()
| 00:12 () ()
| ..... () ()
| 23:48 () ()
| 23:54 () ()
| 00:00 () ()
|
| Cell [Time] would contain the time, cells [Fr(om)] and [To] would contain
a
| RadioButton control, the value of which would be the Date and Time passed,
| so that the end-user can select a "From" time and a "To" time. Cell
| [Free/Busy] just contains information which is returned by a stored
| procedure, which is the source for the information.
|
| So, my questions are:
|
| 1.
| Since I have set all of the radiobutton controls to have the same
GroupName
| (either "TimeFrom" or "TimeTo") is it possible to find out the control
name
| of the radiobutton checked in each group - a function that you could pass
| the GroupName to which would return either the name of the checked
| radiobutton control (great) or the value of the checked radiobutton
control
| (even better).
|
| Even if a function has to be written (I'm thinking something along the
lines
| of CheckedRadioButton(ByVal GroupName As String) As RadioButton) it's got
to
| be better than the current state of affairs

) Any help you can offer in
| terms of writing such a function would be greatly appreciated - I presume
it
| would have something to do with looping through each of the controls in
the
| User Control or the page with the GroupName as given, and then checking to
| see if ThatRadioButton.Checked is True...
|
| (PS - something like that should be added to the next point release, or
| definately ASP.NET v2.0)
|
| 2.
| Failing that, is there a way of creating a radiobutton list, and then
taking
| the rows that are generated by said radiobutton list, and adding them to a
| table that already exists - either a System.Web.UI.WebControls.Table or a
| System.Web.UI.HtmlControls.HtmlTable - and still be able to query the
| RadioButtonList.SelectedValue value?
|
| 3.
| Failing both of the above, what would you suggest?

)
|
|
| Cheers Lewis,
| Anth
|
|
|
| | > Hi Anthony,
| >
| > I need more information to resolve the questions mentioned in the last
| > paragraph of your post.
| >
| > What do you mean about putting the generated radiobutton list into a
| table?
| > Do you mean you want to put a radiobuttonlist control to a TableCell, or
| do
| > you mean you want to put each radio control in the radiobuttonlist to
each
| > TableCell of a Table column?
| >
| > Thanks a lot.
| >
| > Lewis
| >
| > --------------------
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| > | From: (e-mail address removed) (Lewis Wang [MSFT])
| > | Organization: Microsoft
| > | Date: Tue, 09 Sep 2003 15:08:10 GMT
| > | Subject: Re: Retrieving checked RadioButton controls which were added
to
| > a Table control
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
| > | MIME-Version: 1.0
| > | Content-Type: text/plain
| > | Content-Transfer-Encoding: 7bit
| > |
| > | Hi Anthony,
| > |
| > | It's possible to actually get the selected value by group name. But we
| > need
| > | to set the value attribution for every RadioButton. For example:
| > |
| > | RadioFrom.Attributes .Add("value",RadioFrom.Text);
| > |
| > | Then, we can get the selected value using Request.Form
| > | ["TimeFrom"].ToString () in code behind.
| > |
| > | Hope this helps.
| > |
| > | Best regards,
| > | Lewis
| > | This posting is provided "AS IS" with no warranties, and confers no
| > rights.
| > |
| > | --------------------
| > | | From: "Anthony Williams" <
[email protected]>
| > | | References: <
[email protected]>
| > | <
[email protected]>
| > | | Subject: Re: Retrieving checked RadioButton controls which were
added
| > to
| > | a Table control
| > | | Date: Tue, 9 Sep 2003 09:23:01 +0100
| > | | Lines: 184
| > | | X-Priority: 3
| > | | X-MSMail-Priority: Normal
| > | | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | | Message-ID: <
[email protected]>
| > | | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| > | | NNTP-Posting-Host: host81-137-71-124.in-addr.btopenworld.com
| > 81.137.71.124
| > | | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| > | | Xref: cpmsftngxa06.phx.gbl
| > | microsoft.public.dotnet.framework.aspnet.webcontrols:14497
| > | | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
| > | |
| > | | Lewis,
| > | |
| > | | Thanks for the reply - not only did you manage to answer one
question,
| > but
| > | | you also tackled another which I was about to post to a different
| group
| > -
| > | | namely how do I manually populate a dataset - hehe. Thanks for the
| > reply,
| > | | but...
| > | |
| > | | Because I've already manually populated a table with radiobutton
| > controls,
| > | | I'm wondering whether or not it's possible to actually get the
| selected
| > | | value by group name - the reason I ask this specifically, is because
| > I've
| > | | got a table with three columns - a radiobutton list won't allow me
to
| > keep
| > | | my format in this way (will it?)
| > | |
| > | | Is there either a way to put the generated radiobutton list into a
| table
| > | | that already exists, or - possibly - add each of the radiobutton
| > controls
| > | | not only to the table, but also to a radiobutton list?
| > | |
| > | | Cheers,
| > | | Anthony
| > | |
| > | |
| > | | | > | | > Hi Anthony,
| > | | >
| > | | > You can put the 240 ShortTimeStrings in a DataSet/DataTable and
bind
| > it
| > | to
| > | | > a RadioButtonList. Then we can get the selected radio text by "
| > | | > RadioButtonList1.SelectedItem.ToString ()". Here is a code snippet
| for
| > | | > demonstration, you may modify it to meet your requirements.
| > | | >
| > | | > protected DataSet GetSource()
| > | | > {
| > | | > . .
| > | | > if(Session["ds"]!=null)return (DataSet)Session["ds"];
| > | | > DataSet ds=new DataSet();
| > | | > DataTable newtable=new DataTable ();
| > | | > DataColumn cc1 = new
| > | DataColumn("From",Type.GetType("System.String"),"");
| > | | > DataColumn cc2 = new DataColumn("To",
| > Type.GetType("System.String"),"");
| > | | > DataColumn cc3 = new DataColumn("Job",
| > | Type.GetType("System.String"),"");
| > | | > newtable.Columns.Add(cc1);
| > | | > newtable.Columns.Add(cc2);
| > | | > newtable.Columns.Add(cc3);
| > | | > for(int i=0; i<240;i++)
| > | | > {
| > | | > DataRow dr=newtable.NewRow ();
| > | | > dr["From"]=CurTime.AddMinutes(i * 6).ToShortTimeString();
| > | | > dr["To"]=CurTime.AddMinutes(i * 6).ToShortTimeString();
| > | | > dr["Job"]="";
| > | | > newtable.Rows .Add(dr);
| > | | > }
| > | | > ds.Tables .Add (newtable);
| > | | > Session["ds"]=ds;
| > | | >
| > | | > return ds;
| > | | > }
| > | | >
| > | | > private void Page_Load(object sender, System.EventArgs e)
| > | | > {
| > | | > if(!this.IsPostBack)
| > | | > {
| > | | > DataSet ds=GetSource();
| > | | > RadioButtonList1.DataSource =ds;
| > | | > RadioButtonList1.DataTextField ="From";
| > | | > RadioButtonList1.DataBind ();
| > | | > . . .
| > | | > }
| > | | > }
| > | | >
| > | | > private void Button1_Click(object sender, System.EventArgs e)
| > | | > {
| > | | > Response.Write ("From:" + RadioButtonList1.SelectedItem.ToString
| ());
| > | | > . . .
| > | | > }
| > | | >
| > | | > Does this answer your question? Please let me know if you need
more
| > | | > information. Thanks.
| > | | >
| > | | > Best regards,
| > | | > Lewis
| > | | > This posting is provided "AS IS" with no warranties, and confers
no
| > | | rights.
| > | | >
| > | | > --------------------
| > | | > | From: "Anthony Williams" <
[email protected]>
| > | | > | Subject: Retrieving checked RadioButton controls which were
added
| > to a
| > | | > Table control
| > | | > | Date: Mon, 8 Sep 2003 12:28:26 +0100
| > | | > | Lines: 73
| > | | > | X-Priority: 3
| > | | > | X-MSMail-Priority: Normal
| > | | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | | > | Message-ID: <
[email protected]>
| > | | > | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| > | | > | NNTP-Posting-Host: host81-137-71-124.in-addr.btopenworld.com
| > | | 81.137.71.124
| > | | > | Path:
| cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| > | | > | Xref: cpmsftngxa06.phx.gbl
| > | | > microsoft.public.dotnet.framework.aspnet.webcontrols:14469
| > | | > | X-Tomcat-NG:
microsoft.public.dotnet.framework.aspnet.webcontrols
| > | | > |
| > | | > | Hi gang,
| > | | > |
| > | | > | I've created and populated a huge table, with 240 rows, with
three
| > | cells
| > | | > per
| > | | > | row. There are 240 RadioButton controls for "TimeFrom", and 240
| > | | > RadioButton
| > | | > | controls for "TimeTo".
| > | | > |
| > | | > | RadioButtons appearing in cell 1 have a GroupName of "TimeFrom"
| and
| > | | those
| > | | > | appearing in cell 2 have a GroupName of "TimeTo". The table
| appears
| > | | > | correctly (the code at the bottom of this post will generate it
| for
| > | you
| > | | if
| > | | > | you create yourself a Table with ID "TSTable".
| > | | > |
| > | | > | My problem, for those of you falling asleep by now, is that I
| > haven't
| > | | the
| > | | > | faintest idea of how to retrieve the "TimeFrom" and "TimeTo"
| > selected
| > | | > | values. I can put a kludge together that will use
| Request.Form(...)
| > | but
| > | | I
| > | | > | was rather hoping that there'd be a .NET way.
| > | | > |
| > | | > | Any help would be greatly appreciated.
| > | | > |
| > | | > | Cheers,
| > | | > | Tone
| > | | > |
| > | | > |
| > | | > | ' ---------- Begin Create Table Code ----------
| > | | > | Dim CurTime As New DateTime(Now.Year, Now.Month, Now.Day, 0, 0,
0)
| > | | > |
| > | | > | For i As Integer = 0 To 240 ' 24 hours in 240 six-minute (1/10
hr)
| > | | > | increments
| > | | > |
| > | | > | Dim Row As New TableRow
| > | | > | Dim CellFrom As New TableCell
| > | | > | Dim CellTo As New TableCell
| > | | > | Dim CellJob As New TableCell
| > | | > |
| > | | > | CellFrom.Width = Unit.Pixel(60)
| > | | > | CellTo.Width = Unit.Pixel(60)
| > | | > |
| > | | > | ' Create a radio button control which will select the From
| > time...
| > | | > | Dim RadioFrom As New RadioButton
| > | | > | RadioFrom.GroupName = "TimeFrom"
| > | | > | RadioFrom.EnableViewState = True
| > | | > | RadioFrom.Text = CurTime.AddMinutes(i * 6).ToShortTimeString
| > | | > |
| > | | > | ' ...then add it to the "From" cell we just created
| > | | > | CellFrom.Controls.Add(RadioFrom)
| > | | > |
| > | | > | ' And the same for selecting the To time...
| > | | > | Dim RadioTo As New RadioButton
| > | | > | RadioTo.GroupName = "TimeTo"
| > | | > | RadioTo.EnableViewState = True
| > | | > | RadioTo.Text = CurTime.AddMinutes(i * 6).ToShortTimeString
| > | | > |
| > | | > | ' ...then add it to the "To" cell
| > | | > | CellTo.Controls.Add(RadioTo)
| > | | > |
| > | | > | With Row.Cells
| > | | > | .Add(CellFrom)
| > | | > | .Add(CellTo)
| > | | > | .Add(CellJob)
| > | | > | End With
| > | | > |
| > | | > | RadioFrom.Dispose()
| > | | > | RadioTo.Dispose()
| > | | > |
| > | | > | CellFrom.Dispose()
| > | | > | CellTo.Dispose()
| > | | > | CellJob.Dispose()
| > | | > |
| > | | > | Row.Dispose()
| > | | > |
| > | | > | Next
| > | | > | ' ---------- End Create Table Code ----------
| > | | > |
| > | | > |
| > | | > |
| > | | >
| > | |
| > | |
| > | |
| > |
| >
|
|
|