?
Solved

Databound RadioButtonList Selected Item in a Data Grid

Posted on 2006-04-08
2
Medium Priority
?
916 Views
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">
      <ItemTemplate>
            <asp:Label id=lblLoanTypeDG runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FormOption1") %>'>
            </asp:Label>
      </ItemTemplate>
      <EditItemTemplate>
            <asp:RadioButtonList id=rblEditLoanType runat="server" Width="200px" Height="40px" DataSource="<%# dvLoanType %>" DataTextField="OptionValue" DataValueField="OptionValue">
            </asp:RadioButtonList>
      </EditItemTemplate>
</asp:TemplateColumn>

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,
Don
0
Comment
Question by:TheTennMan
2 Comments
 
LVL 7

Accepted Solution

by:
ayha1999 earned 2000 total points
ID: 16407669
Hi,

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

Ayha
0
 

Author Comment

by:TheTennMan
ID: 16480163
Thanks for your help, Ayha!
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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…
Integration Management Part 2
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month15 days, 1 hour left to enroll

839 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