Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > radio button in colums are not grouped correctly

Reply
Thread Tools

radio button in colums are not grouped correctly

 
 
George Paiva
Guest
Posts: n/a
 
      01-09-2004
Hello,

I have a datagrid that I dynamically add radio buttons to in the
onItemDataBoud Event. I set each radio button to the same GroupName but
when I run the page the radio button group does not dissallow multiple
selections as it should. My C# code snippet is below.

Any thoughts???

public void ItemDataBoundHandler(Object sender, DataGridItemEventArgs e)
{
RadioButton rb = new RadioButton();
rb.AutoPostBack=true;
rb.GroupName="selItem";
rb.ID=e.Item.Cells[0].Text;
e.Item.Cells[2].Controls.Add(rb);
}



Thanks
Geo


 
Reply With Quote
 
 
 
 
Alvin Bruney
Guest
Posts: n/a
 
      01-09-2004
That will not work. Well i suppose you already figured this out. Add it this
way instead. can't find the code... hold on

if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)

{

Label lbl = (Label)e.Item.FindControl("Dig");

if(lbl != null)

lbl.Text = "<input type=radio name='samegroup' value=" +
e.Item.Cells[1].Text + ">";

[snip]

to retrieve the selected radio button do this:

private string GetSelectedItems()

{

string retval = Request.Form["samegroup"];

if(retval == null || String.Empty == retval)

Page.Controls.Add(new LiteralControl("<script>alert('Please select a row to
dig on by enabling a radio button in the grid')</script>"));

else

retval = retval.Trim();


return retval;

}

The returned value from that function will be whatever you put in in the
value attribute of the input tag (e.Item.Cells[1].Text)

You can sorta tell that this is my current project right?

--
Regards,
Alvin Bruney
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"George Paiva" <geo AT NO SPAM promaxim DOT com> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> I have a datagrid that I dynamically add radio buttons to in the
> onItemDataBoud Event. I set each radio button to the same GroupName but
> when I run the page the radio button group does not dissallow multiple
> selections as it should. My C# code snippet is below.
>
> Any thoughts???
>
> public void ItemDataBoundHandler(Object sender, DataGridItemEventArgs e)
> {
> RadioButton rb = new RadioButton();
> rb.AutoPostBack=true;
> rb.GroupName="selItem";
> rb.ID=e.Item.Cells[0].Text;
> e.Item.Cells[2].Controls.Add(rb);
> }
>
>
>
> Thanks
> Geo
>
>



 
Reply With Quote
 
 
 
 
George Paiva
Guest
Posts: n/a
 
      01-09-2004
Thanks Alvin,

I find it interesting that the DataGrid renames the "name" property of the
RadioButton with some prepended text (like gridname:_ctl2 because this
nullifies the functionality of the HTML control. You would think that the
framework would use its own property to itentify the controls in the grid.
No?

I will use your solution to get around this issue so thanks again.

Geo



"Alvin Bruney" <vapor at steaming post office> wrote in message
news:(E-Mail Removed)...
> That will not work. Well i suppose you already figured this out. Add it

this
> way instead. can't find the code... hold on
>
> if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
> ListItemType.AlternatingItem)
>
> {
>
> Label lbl = (Label)e.Item.FindControl("Dig");
>
> if(lbl != null)
>
> lbl.Text = "<input type=radio name='samegroup' value=" +
> e.Item.Cells[1].Text + ">";
>
> [snip]
>
> to retrieve the selected radio button do this:
>
> private string GetSelectedItems()
>
> {
>
> string retval = Request.Form["samegroup"];
>
> if(retval == null || String.Empty == retval)
>
> Page.Controls.Add(new LiteralControl("<script>alert('Please select a row

to
> dig on by enabling a radio button in the grid')</script>"));
>
> else
>
> retval = retval.Trim();
>
>
> return retval;
>
> }
>
> The returned value from that function will be whatever you put in in the
> value attribute of the input tag (e.Item.Cells[1].Text)
>
> You can sorta tell that this is my current project right?
>
> --
> Regards,
> Alvin Bruney
> Got tidbits? Get it here...
> http://tinyurl.com/3he3b
> "George Paiva" <geo AT NO SPAM promaxim DOT com> wrote in message
> news:(E-Mail Removed)...
> > Hello,
> >
> > I have a datagrid that I dynamically add radio buttons to in the
> > onItemDataBoud Event. I set each radio button to the same GroupName but
> > when I run the page the radio button group does not dissallow multiple
> > selections as it should. My C# code snippet is below.
> >
> > Any thoughts???
> >
> > public void ItemDataBoundHandler(Object sender, DataGridItemEventArgs e)
> > {
> > RadioButton rb = new RadioButton();
> > rb.AutoPostBack=true;
> > rb.GroupName="selItem";
> > rb.ID=e.Item.Cells[0].Text;
> > e.Item.Cells[2].Controls.Add(rb);
> > }
> >
> >
> >
> > Thanks
> > Geo
> >
> >

>
>



 
Reply With Quote
 
Saravana [MVP]
Guest
Posts: n/a
 
      01-12-2004
If you check out this support link , you will find the answer why datagrid
is changing the name of the radio button in runtime.
http://support.microsoft.com/default...;EN-US;Q316495



--
Saravana
Microsoft MVP - ASP.NET
www.extremeexperts.com



"George Paiva" <geo AT NO SPAM promaxim DOT com> wrote in message
news:#(E-Mail Removed)...
> Thanks Alvin,
>
> I find it interesting that the DataGrid renames the "name" property of the
> RadioButton with some prepended text (like gridname:_ctl2 because this
> nullifies the functionality of the HTML control. You would think that the
> framework would use its own property to itentify the controls in the grid.
> No?
>
> I will use your solution to get around this issue so thanks again.
>
> Geo
>
>
>
> "Alvin Bruney" <vapor at steaming post office> wrote in message
> news:(E-Mail Removed)...
> > That will not work. Well i suppose you already figured this out. Add it

> this
> > way instead. can't find the code... hold on
> >
> > if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
> > ListItemType.AlternatingItem)
> >
> > {
> >
> > Label lbl = (Label)e.Item.FindControl("Dig");
> >
> > if(lbl != null)
> >
> > lbl.Text = "<input type=radio name='samegroup' value=" +
> > e.Item.Cells[1].Text + ">";
> >
> > [snip]
> >
> > to retrieve the selected radio button do this:
> >
> > private string GetSelectedItems()
> >
> > {
> >
> > string retval = Request.Form["samegroup"];
> >
> > if(retval == null || String.Empty == retval)
> >
> > Page.Controls.Add(new LiteralControl("<script>alert('Please select a row

> to
> > dig on by enabling a radio button in the grid')</script>"));
> >
> > else
> >
> > retval = retval.Trim();
> >
> >
> > return retval;
> >
> > }
> >
> > The returned value from that function will be whatever you put in in the
> > value attribute of the input tag (e.Item.Cells[1].Text)
> >
> > You can sorta tell that this is my current project right?
> >
> > --
> > Regards,
> > Alvin Bruney
> > Got tidbits? Get it here...
> > http://tinyurl.com/3he3b
> > "George Paiva" <geo AT NO SPAM promaxim DOT com> wrote in message
> > news:(E-Mail Removed)...
> > > Hello,
> > >
> > > I have a datagrid that I dynamically add radio buttons to in the
> > > onItemDataBoud Event. I set each radio button to the same GroupName

but
> > > when I run the page the radio button group does not dissallow multiple
> > > selections as it should. My C# code snippet is below.
> > >
> > > Any thoughts???
> > >
> > > public void ItemDataBoundHandler(Object sender, DataGridItemEventArgs

e)
> > > {
> > > RadioButton rb = new RadioButton();
> > > rb.AutoPostBack=true;
> > > rb.GroupName="selItem";
> > > rb.ID=e.Item.Cells[0].Text;
> > > e.Item.Cells[2].Controls.Add(rb);
> > > }
> > >
> > >
> > >
> > > Thanks
> > > Geo
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Alvin Bruney
Guest
Posts: n/a
 
      01-17-2004
> I find it interesting that the DataGrid renames the "name" property of the
> RadioButton with some prepended text (like gridname:_ctl2 because this

this is because webcontrols which implement inamingcontainer interface -
like the datagrid - must meet the criteria that their html name be unique,
hence the renaming. i'm not sure if they are working on getting an exemption
for the datagrid because this is a sore spot

--
Regards,
Alvin Bruney
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"George Paiva" <geo AT NO SPAM promaxim DOT com> wrote in message
news:%(E-Mail Removed)...
> Thanks Alvin,
>
> I find it interesting that the DataGrid renames the "name" property of the
> RadioButton with some prepended text (like gridname:_ctl2 because this
> nullifies the functionality of the HTML control. You would think that the
> framework would use its own property to itentify the controls in the grid.
> No?
>
> I will use your solution to get around this issue so thanks again.
>
> Geo
>
>
>
> "Alvin Bruney" <vapor at steaming post office> wrote in message
> news:(E-Mail Removed)...
> > That will not work. Well i suppose you already figured this out. Add it

> this
> > way instead. can't find the code... hold on
> >
> > if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
> > ListItemType.AlternatingItem)
> >
> > {
> >
> > Label lbl = (Label)e.Item.FindControl("Dig");
> >
> > if(lbl != null)
> >
> > lbl.Text = "<input type=radio name='samegroup' value=" +
> > e.Item.Cells[1].Text + ">";
> >
> > [snip]
> >
> > to retrieve the selected radio button do this:
> >
> > private string GetSelectedItems()
> >
> > {
> >
> > string retval = Request.Form["samegroup"];
> >
> > if(retval == null || String.Empty == retval)
> >
> > Page.Controls.Add(new LiteralControl("<script>alert('Please select a row

> to
> > dig on by enabling a radio button in the grid')</script>"));
> >
> > else
> >
> > retval = retval.Trim();
> >
> >
> > return retval;
> >
> > }
> >
> > The returned value from that function will be whatever you put in in the
> > value attribute of the input tag (e.Item.Cells[1].Text)
> >
> > You can sorta tell that this is my current project right?
> >
> > --
> > Regards,
> > Alvin Bruney
> > Got tidbits? Get it here...
> > http://tinyurl.com/3he3b
> > "George Paiva" <geo AT NO SPAM promaxim DOT com> wrote in message
> > news:(E-Mail Removed)...
> > > Hello,
> > >
> > > I have a datagrid that I dynamically add radio buttons to in the
> > > onItemDataBoud Event. I set each radio button to the same GroupName

but
> > > when I run the page the radio button group does not dissallow multiple
> > > selections as it should. My C# code snippet is below.
> > >
> > > Any thoughts???
> > >
> > > public void ItemDataBoundHandler(Object sender, DataGridItemEventArgs

e)
> > > {
> > > RadioButton rb = new RadioButton();
> > > rb.AutoPostBack=true;
> > > rb.GroupName="selItem";
> > > rb.ID=e.Item.Cells[0].Text;
> > > e.Item.Cells[2].Controls.Add(rb);
> > > }
> > >
> > >
> > >
> > > Thanks
> > > Geo
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET Reset Radio Button in a group of Radio Buttons Scott D Johnson ASP .Net 1 09-27-2006 10:38 PM
Adding HeaderText and HeaderImageUrl to Colums in DataGrid Patrick Olurotimi Ige ASP .Net 1 03-11-2005 01:37 PM
Radio button List problem: How to find value of Radio button list's Selected Item using javascript?? Hiten ASP .Net Web Controls 1 05-26-2004 10:32 AM
DataGrid Button Colums Javascript !! Amit Garg ASP .Net 0 01-22-2004 11:17 AM
Dynamic Colums blake lawless ASP .Net 0 11-21-2003 10:22 PM



Advertisments