Retrieving checked RadioButton controls which were added to a Table control

  • Thread starter Anthony Williams
  • Start date
A

Anthony Williams

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 ----------
 
L

Lewis Wang [MSFT]

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 ----------
|
|
|
 
A

Anthony Williams

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


Lewis Wang said:
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 ----------
|
|
|
 
L

Lewis Wang [MSFT]

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 ----------
| > |
| > |
| > |
| >
|
|
|
 
L

Lewis Wang [MSFT]

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 ----------
| | > |
| | > |
| | > |
| | >
| |
| |
| |
|
 
A

Anthony Williams

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 :eek:) 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? :eek:)


Cheers Lewis,
Anth



Lewis Wang said:
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 ----------
| | > |
| | > |
| | > |
| | >
| |
| |
| |
|
 
L

Lewis Wang [MSFT]

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 :eek:) 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? :eek:)
|
|
| 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 ----------
| > | | > |
| > | | > |
| > | | > |
| > | | >
| > | |
| > | |
| > | |
| > |
| >
|
|
|
 
A

Anthony Williams

Lewis,

In answer to your first question, yes and no. It does meet the requirements
in some ways (in that I can get the values specified) but it doesn't allow
me to get the name of the control that was selected using code behind
techniques - as I mentioned in my previous post, I'd like to be able to
build a function which would return a reference to the RadioButton control
which has a specified GroupName and is checked.

Is there a way of iterating through each of the controls (of a given type)
in the user control, page or whatever container?

Cheers,
Anthony

Lewis Wang said:
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 :eek:) 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? :eek:)
|
|
| 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 ----------
| > | | > |
| > | | > |
| > | | > |
| > | | >
| > | |
| > | |
| > | |
| > |
| >
|
|
|
 
F

Felix Wu [MSFT]

Hi Anthony ,

This is actually a known issue that radio buttons in the ItemTemplate are
not mutually exclusive:

BUG: Radio Buttons Are Not Mutually Exclusive When Used in a Repeater
Server Control
http://support.microsoft.com/?scid=kb;en-us;Q316495

We can workaround this by using either client side script or handling the
CheckedChanged event on the server side. Here is the way to handle the
CheckedChanged event. Please note that this method requires more postback
than client side script does:

1. We can use a Datagrid's to display the rows as Lewis suggested.

2. Create a ItemTemplate column and add a RadioButton to the column. Bind
the RadioButton appropriately.

3. Open the ASPX view of the page, add "OnCheckedChanged" attribute to the
<asp:RadioButton> element, and make it point to a public handler method
defined in the code behind file. Here is a code snippet for example:

In ASPX file
==========
<asp:TemplateColumn HeaderText="RadioCol">
<ItemTemplate>
<asp:RadioButton id="RadioButton4" AutoPostBack="True"
OnCheckedChanged="RadioButton4_CheckedChanged" runat="server"
GroupName="DtFrom"></asp:RadioButton>
</ItemTemplate>
</asp:TemplateColumn>


In the code behind file
===================
public void RadioButton4_CheckedChanged(object sender, System.EventArgs e)
{
RadioButton rb=(RadioButton)sender;
Response.Write(rb.ClientID.ToString()); //This line is just for test
purpose.
for (int i =0 ; i <DataGrid1.Items.Count; i++)
{
((RadioButton)DataGrid1.Items.Controls[0].Controls[1]).Checked= false;
}
// check the selected radio button
rb.Checked= true;
}

To get the selected RadioButton when you submit the page, I think you can
try the FindCotrol method.

Regards,

Felix Wu
=======
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: Thu, 11 Sep 2003 12:31:57 +0100
Lines: 483
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:14563
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols

Lewis,

In answer to your first question, yes and no. It does meet the requirements
in some ways (in that I can get the values specified) but it doesn't allow
me to get the name of the control that was selected using code behind
techniques - as I mentioned in my previous post, I'd like to be able to
build a function which would return a reference to the RadioButton control
which has a specified GroupName and is checked.

Is there a way of iterating through each of the controls (of a given type)
in the user control, page or whatever container?

Cheers,
Anthony

Lewis Wang said:
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 :eek:) 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? :eek:)
|
|
| 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 ----------
| > | | > |
| > | | > |
| > | | > |
| > | | >
| > | |
| > | |
| > | |
| > |
| >
|
|
|
 
F

Felix Wu [MSFT]

Hi Anthony ,

You could also handle the submit button's server-side click event and
iterate the rows of the table to find out the selected radio button.

Regards,

Felix Wu
=======
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
X-Tomcat-ID: 10015629
References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<#[email protected]>
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
From: (e-mail address removed) (Felix Wu [MSFT])
Organization: Microsoft
Date: Mon, 15 Sep 2003 07:22:46 GMT
Subject: Re: Retrieving checked RadioButton controls which were added to a Table control
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
Message-ID: <#72#[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
Lines: 508
Path: cpmsftngxa07.phx.gbl
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet.webcontrols:14596
NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122

Hi Anthony ,

This is actually a known issue that radio buttons in the ItemTemplate are
not mutually exclusive:

BUG: Radio Buttons Are Not Mutually Exclusive When Used in a Repeater
Server Control
http://support.microsoft.com/?scid=kb;en-us;Q316495

We can workaround this by using either client side script or handling the
CheckedChanged event on the server side. Here is the way to handle the
CheckedChanged event. Please note that this method requires more postback
than client side script does:

1. We can use a Datagrid's to display the rows as Lewis suggested.

2. Create a ItemTemplate column and add a RadioButton to the column. Bind
the RadioButton appropriately.

3. Open the ASPX view of the page, add "OnCheckedChanged" attribute to the
<asp:RadioButton> element, and make it point to a public handler method
defined in the code behind file. Here is a code snippet for example:

In ASPX file
==========
<asp:TemplateColumn HeaderText="RadioCol">
<ItemTemplate>
<asp:RadioButton id="RadioButton4" AutoPostBack="True"
OnCheckedChanged="RadioButton4_CheckedChanged" runat="server"
GroupName="DtFrom"></asp:RadioButton>
</ItemTemplate>
</asp:TemplateColumn>


In the code behind file
===================
public void RadioButton4_CheckedChanged(object sender, System.EventArgs e)
{
RadioButton rb=(RadioButton)sender;
Response.Write(rb.ClientID.ToString()); //This line is just for test
purpose.
for (int i =0 ; i <DataGrid1.Items.Count; i++)
{
((RadioButton)DataGrid1.Items.Controls[0].Controls[1]).Checked= false;
}
// check the selected radio button
rb.Checked= true;
}

To get the selected RadioButton when you submit the page, I think you can
try the FindCotrol method.

Regards,

Felix Wu
=======
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: Thu, 11 Sep 2003 12:31:57 +0100
Lines: 483
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:14563
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols

Lewis,

In answer to your first question, yes and no. It does meet the requirements
in some ways (in that I can get the values specified) but it doesn't allow
me to get the name of the control that was selected using code behind
techniques - as I mentioned in my previous post, I'd like to be able to
build a function which would return a reference to the RadioButton control
which has a specified GroupName and is checked.

Is there a way of iterating through each of the controls (of a given type)
in the user control, page or whatever container?

Cheers,
Anthony

Lewis Wang said:
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 :eek:) 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? :eek:)
|
|
| 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 ----------
| > | | > |
| > | | > |
| > | | > |
| > | | >
| > | |
| > | |
| > | |
| > |
| >
|
|
|
 
A

Anthony Williams

Felix,

I was just evaluating all the ways that you guys have suggested, and that
seems to be the best. I was trying to find out the control name by getting
Request.Form(...) but that didn't seem to work, so I'll be using the method
you just suggested.

Many thanks to both yourself and Lewis!

Cheers,
Anth


Felix Wu said:
Hi Anthony ,

You could also handle the submit button's server-side click event and
iterate the rows of the table to find out the selected radio button.

Regards,

Felix Wu
=======
This posting is provided "AS IS" with no warranties, and confers no rights.<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<#[email protected]>
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
From: (e-mail address removed) (Felix Wu [MSFT])
Organization: Microsoft
Date: Mon, 15 Sep 2003 07:22:46 GMT
Subject: Re: Retrieving checked RadioButton controls which were added to
a
Table control
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
Message-ID: <#72#[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
Lines: 508
Path: cpmsftngxa07.phx.gbl
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet.webcontrols:14596
NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122

Hi Anthony ,

This is actually a known issue that radio buttons in the ItemTemplate are
not mutually exclusive:

BUG: Radio Buttons Are Not Mutually Exclusive When Used in a Repeater
Server Control
http://support.microsoft.com/?scid=kb;en-us;Q316495

We can workaround this by using either client side script or handling the
CheckedChanged event on the server side. Here is the way to handle the
CheckedChanged event. Please note that this method requires more postback
than client side script does:

1. We can use a Datagrid's to display the rows as Lewis suggested.

2. Create a ItemTemplate column and add a RadioButton to the column. Bind
the RadioButton appropriately.

3. Open the ASPX view of the page, add "OnCheckedChanged" attribute to the
<asp:RadioButton> element, and make it point to a public handler method
defined in the code behind file. Here is a code snippet for example:

In ASPX file
==========
<asp:TemplateColumn HeaderText="RadioCol">
<ItemTemplate>
<asp:RadioButton id="RadioButton4" AutoPostBack="True"
OnCheckedChanged="RadioButton4_CheckedChanged" runat="server"
GroupName="DtFrom"></asp:RadioButton>
</ItemTemplate>
</asp:TemplateColumn>


In the code behind file
===================
public void RadioButton4_CheckedChanged(object sender, System.EventArgs e)
{
RadioButton rb=(RadioButton)sender;
Response.Write(rb.ClientID.ToString()); //This line is just for test
purpose.
for (int i =0 ; i <DataGrid1.Items.Count; i++)
{
((RadioButton)DataGrid1.Items.Controls[0].Controls[1]).Checked= false;
}
// check the selected radio button
rb.Checked= true;
}

To get the selected RadioButton when you submit the page, I think you can
try the FindCotrol method.

Regards,

Felix Wu
=======
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: Thu, 11 Sep 2003 12:31:57 +0100
Lines: 483
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:14563
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols

Lewis,

In answer to your first question, yes and no. It does meet the requirements
in some ways (in that I can get the values specified) but it doesn't allow
me to get the name of the control that was selected using code behind
techniques - as I mentioned in my previous post, I'd like to be able to
build a function which would return a reference to the RadioButton control
which has a specified GroupName and is checked.

Is there a way of iterating through each of the controls (of a given type)
in the user control, page or whatever container?

Cheers,
Anthony

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 :eek:) 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? :eek:)
|
|
| 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
| > | |
| > | |
message
| > | | | > | | > 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
 

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,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top