Databound RadioButtonList Selected Item in a Data Grid

Posted on 2006-04-08
Last Modified: 2008-01-09
I have the following template column in a data grid whose data source is a data view.  The column displays the stored text value for the loan type from the database in a label for display in the data grid.  For editing, a radio button list is populated with items from another data view that contains all of the available loan types.  One of these items from the second data view matches the displayed value from the first data view.

<asp:TemplateColumn Visible="False" SortExpression="FormOption1" HeaderText="Loan Type">
            <asp:Label id=lblLoanTypeDG runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FormOption1") %>'>
            <asp:RadioButtonList id=rblEditLoanType runat="server" Width="200px" Height="40px" DataSource="<%# dvLoanType %>" DataTextField="OptionValue" DataValueField="OptionValue">

What do I need to add to the code for the EditItemTemplate above that will select the correct loan type item?  Do I add a "Selected Index" parameter and tie that to a query that will return the appropriate index?  If so, I'm not quite sure about the syntax required in the asp:RadioButtonList item.  If that's not the way to approach it, how do you do it?

Thanks in advance,
Question by:TheTennMan
    LVL 7

    Accepted Solution


    In the itemdatabound event you can it

     If e.Item.ItemType = ListItemType.EditItem Then
    If Not DataBinder.Eval(e.Item.DataItem, "FormOption1") Is DBNull.Value Then
       Dim ListFormOption1 As ListItem = CType(e.Item.FindControl("rblEditLoanType "), RadioButtonList).Items.FindByValue(DataBinder.Eval(e.Item.DataItem, "FormOption1"))
       If Not ListFormOption1 Is Nothing Then
          ListFormOption1 .Selected = True
       End If

    End IF


    Author Comment

    Thanks for your help, Ayha!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now