Binding data to radiobutton in a FormView

Discussion in 'ASP .Net' started by sck10, Jun 29, 2006.

  1. sck10

    sck10 Guest

    Hello,

    I am trying to use a radiobutton inside of a FormView for editing data. My
    question is how do you bind the radio buttons to the data field? Thanks,
    sck10



    <td style="width:30%; text-align:center;">
    <asp:RadioButton id="rbn01Approved" runat="server"
    Text="Approved"
    TextAlign="left"
    GroupName="rbn02"
    Checked="False"/></td>

    <td style="width:50%; text-align:left;">
    <asp:RadioButton id="rbn01Denied" runat="server"
    Text="Denied"
    TextAlign="Right"
    GroupName="rbn02"
    Checked="False"/></td>
     
    sck10, Jun 29, 2006
    #1
    1. Advertisements

  2. Guest

    you'll have to fill the radiobuttonlist with data, either enter
    manually, or from another data source

    to hook it up with the data in for your formview:

    you can set

    SelectedValue='<%# Eval("Some Field In Your Formview Datasource") %>'

    or

    SelectedIndex='<%# Eval("Some Field In Your Formview Datasource") %>'

    cheers

    neil


    sck10 wrote:
    > Hello,
    >
    > I am trying to use a radiobutton inside of a FormView for editing data. My
    > question is how do you bind the radio buttons to the data field? Thanks,
    > sck10
    >
    >
    >
    > <td style="width:30%; text-align:center;">
    > <asp:RadioButton id="rbn01Approved" runat="server"
    > Text="Approved"
    > TextAlign="left"
    > GroupName="rbn02"
    > Checked="False"/></td>
    >
    > <td style="width:50%; text-align:left;">
    > <asp:RadioButton id="rbn01Denied" runat="server"
    > Text="Denied"
    > TextAlign="Right"
    > GroupName="rbn02"
    > Checked="False"/></td>
     
    , Jun 29, 2006
    #2
    1. Advertisements

  3. Hi,

    Thank you for your post.

    You can use RadioButtonList and its DataBinding event to do this. Using
    SqlServer database Northwind's Products for example:

    <asp:RadioButtonList ID="rlist1"
    OnDataBinding="RadioButtonList1_DataBinding" runat="server">
    <asp:ListItem Text="Discontinued"></asp:ListItem>
    <asp:ListItem Text="In Stock"></asp:ListItem>
    </asp:RadioButtonList>

    protected void RadioButtonList1_DataBinding(object sender, EventArgs e)
    {
    RadioButtonList rlist = (RadioButtonList) sender;
    bool discontinued = (bool) DataBinder.Eval(rlist.BindingContainer,
    "DataItem.Discontinued");
    string text = "In Stock";
    if (discontinued)
    {
    text = "Discontinued";
    }
    foreach(ListItem li in rlist.Items)
    {
    if (li.Text == text)
    {
    li.Selected = true;
    break;
    }
    }
    }

    Hope this helps. Please feel free to post here if anything is unclear.

    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Jun 29, 2006
    #3
  4. sck10

    sck10 Guest

    Thanks Walter...


    "Walter Wang [MSFT]" <> wrote in message
    news:...
    > Hi,
    >
    > Thank you for your post.
    >
    > You can use RadioButtonList and its DataBinding event to do this. Using
    > SqlServer database Northwind's Products for example:
    >
    > <asp:RadioButtonList ID="rlist1"
    > OnDataBinding="RadioButtonList1_DataBinding" runat="server">
    > <asp:ListItem Text="Discontinued"></asp:ListItem>
    > <asp:ListItem Text="In Stock"></asp:ListItem>
    > </asp:RadioButtonList>
    >
    > protected void RadioButtonList1_DataBinding(object sender, EventArgs e)
    > {
    > RadioButtonList rlist = (RadioButtonList) sender;
    > bool discontinued = (bool) DataBinder.Eval(rlist.BindingContainer,
    > "DataItem.Discontinued");
    > string text = "In Stock";
    > if (discontinued)
    > {
    > text = "Discontinued";
    > }
    > foreach(ListItem li in rlist.Items)
    > {
    > if (li.Text == text)
    > {
    > li.Selected = true;
    > break;
    > }
    > }
    > }
    >
    > Hope this helps. Please feel free to post here if anything is unclear.
    >
    > Regards,
    > Walter Wang (, remove 'online.')
    > Microsoft Online Community Support
    >
    > ==================================================
    > When responding to posts, please "Reply to Group" via your newsreader so
    > that others may learn and benefit from your issue.
    > ==================================================
    >
    > This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    >
     
    sck10, Jun 30, 2006
    #4
  5. You're welcome!

    If you have any other questions or concerns, please do not hesitate to
    contact us. It is always our pleasure to be of assistance.

    Have a nice day!

    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Jul 3, 2006
    #5
    1. Advertisements

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. =?Utf-8?B?SmVmZiBIYXJrYXZ5?=

    FormView and stored proc data binding

    =?Utf-8?B?SmVmZiBIYXJrYXZ5?=, Jun 9, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    663
    =?Utf-8?B?SmVmZiBIYXJrYXZ5?=
    Jun 9, 2006
  2. Sam
    Replies:
    1
    Views:
    9,261
    Prnda76
    Feb 11, 2010
  3. Colorstone
    Replies:
    2
    Views:
    2,985
    Colorstone
    Oct 7, 2008
  4. David Thielen

    FormView/Repeater/ Eval(FormView data)

    David Thielen, Jun 16, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    883
    David Thielen
    Jun 16, 2006
  5. Sam
    Replies:
    0
    Views:
    370
Loading...

Share This Page