radio button in colums are not grouped correctly

Discussion in 'ASP .Net Datagrid Control' started by George Paiva, Jan 9, 2004.

  1. George Paiva

    George Paiva Guest

    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
     
    George Paiva, Jan 9, 2004
    #1
    1. Advertising

  2. George Paiva

    Alvin Bruney Guest

    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:...
    > 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
    >
    >
     
    Alvin Bruney, Jan 9, 2004
    #2
    1. Advertising

  3. George Paiva

    George Paiva Guest

    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:...
    > 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:...
    > > 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
    > >
    > >

    >
    >
     
    George Paiva, Jan 9, 2004
    #3
  4. 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.aspx?scid=kb;EN-US;Q316495



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



    "George Paiva" <geo AT NO SPAM promaxim DOT com> wrote in message
    news:#...
    > 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:...
    > > 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:...
    > > > 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
    > > >
    > > >

    > >
    > >

    >
    >
     
    Saravana [MVP], Jan 12, 2004
    #4
  5. George Paiva

    Alvin Bruney Guest

    > 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:%...
    > 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:...
    > > 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:...
    > > > 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
    > > >
    > > >

    > >
    > >

    >
    >
     
    Alvin Bruney, Jan 17, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Amit Garg

    DataGrid Button Colums Javascript !!

    Amit Garg, Jan 22, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    938
    Amit Garg
    Jan 22, 2004
  2. blake lawless

    Dynamic Colums

    blake lawless, Nov 21, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    402
    blake lawless
    Nov 21, 2003
  3. Patrick Olurotimi Ige
    Replies:
    1
    Views:
    615
    Patrick Olurotimi Ige
    Mar 11, 2005
  4. Scott D Johnson
    Replies:
    1
    Views:
    1,131
    Scott D Johnson
    Sep 27, 2006
  5. Hiten
    Replies:
    1
    Views:
    701
    Vidar Petursson
    May 26, 2004
Loading...

Share This Page