How to put a full radio button list in each row of datagrid?

Discussion in 'ASP .Net Datagrid Control' started by John Smith, Aug 20, 2003.

  1. John Smith

    John Smith Guest

    Hello,

    I have a datagrid where I display images. I want visitors to be able
    to rate the images on a scale of 1 to 10 by clicking a radio button,
    which will cause an auto-postback. In that auto-postback event, I
    want to be able to identify which row caused it, and determine which
    value was selected. Then I want to write that information to a
    database.

    All the examples I have found concerning radio button lists and the
    datagrid have to do with putting one radio button per row, to let
    users select the row. My request is different, in that in each row,
    there will be one radio button list with 10 buttons, from 1 to 10.

    I can put the radio button list in the datagrid, and the auto-postback
    feature does cause the form to post (because the screen blinks), but I
    don't know the name of the raised event, so I can't begin to write the
    handler. Also, I wouldn't know how to get the row and the value, thus
    my posting here.

    Thank you very much.

    John
     
    John Smith, Aug 20, 2003
    #1
    1. Advertising

  2. I have a similiar situation here's what I did:

    In my datagrid I added these columns:

    <ItemTemplate>
    <asp:RadioButton id="rdBtnAccept" Text="Yes" Runat="server"
    GroupName="Accept" AutoPostBack="True" OnCheckedChanged="rdbtnCheckChg">
    </asp:RadioButton>
    <asp:RadioButton id="rdBtnDeny" Text="No" Runat="server"
    GroupName="Accept">
    </asp:RadioButton>
    </ItemTemplate>

    Then in my code behind file:

    public void rdbtnCheckChg(object sender, System.EventArgs e)
    {
    RadioButton myBtn = (RadioButton)sender;
    DataGridItem myGridItem = (DataGridItem)myBtn.Parent.Parent;
    if(myBtn.Checked)
    {
    grdTrips.Columns[1].Visible = true;
    grdTrips.EditItemIndex = myGridItem.ItemIndex;
    BindGrid();
    }
    }

    You will also have to add an EditCommandColumn to generate the OnUpdate
    event to write to the database, you can specify your event handler for this
    event in your aspx file: <asp:DataGrid id="myGrid"
    OnUpdateCommand="myUpdateHandler" ...>

    HTH,
    David Churchill

    "John Smith" <> wrote in message
    news:...
    > Hello,
    >
    > I have a datagrid where I display images. I want visitors to be able
    > to rate the images on a scale of 1 to 10 by clicking a radio button,
    > which will cause an auto-postback. In that auto-postback event, I
    > want to be able to identify which row caused it, and determine which
    > value was selected. Then I want to write that information to a
    > database.
    >
    > All the examples I have found concerning radio button lists and the
    > datagrid have to do with putting one radio button per row, to let
    > users select the row. My request is different, in that in each row,
    > there will be one radio button list with 10 buttons, from 1 to 10.
    >
    > I can put the radio button list in the datagrid, and the auto-postback
    > feature does cause the form to post (because the screen blinks), but I
    > don't know the name of the raised event, so I can't begin to write the
    > handler. Also, I wouldn't know how to get the row and the value, thus
    > my posting here.
    >
    > Thank you very much.
    >
    > John
     
    David Churchill, Aug 20, 2003
    #2
    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. John Blair
    Replies:
    1
    Views:
    412
    Eliyahu Goldin
    Aug 3, 2005
  2. Ken Fine
    Replies:
    4
    Views:
    388
    Steven Cheng [MSFT]
    Jul 14, 2008
  3. D
    Replies:
    0
    Views:
    221
  4. Satish Appasani
    Replies:
    2
    Views:
    212
    Nick Hertl
    Dec 14, 2003
  5. Hiten
    Replies:
    1
    Views:
    632
    Vidar Petursson
    May 26, 2004
Loading...

Share This Page