Try the following:
1 - Define Repeater:
<asp:Repeater ID="rptDummy" runat="server" OnItemDataBound="rptDummy_OnItemDataBound" >
<ItemTemplate>
<asp:RadioButtonList ID="rbl" runat="server" DataTextField="Item2" DataValueField="Item2" />
</ItemTemplate>
</asp:Repeater>
2 - Create a data structure and bind the repeater:
List<Tuple<string,string>> values = new List<Tuple<string,string>>();
foreach (DataTable dt in ds.Tables){
foreach (DataRow r in dt.Rows){
string text = r[1] + " " + r[2] + " " + r[3] + " " + r[4];
string groupName = (string)r[5];
values.Add(new Tuple<string,string>(groupName, text));
}
}
rptDummy.DataSource = values.GroupBy(x => x.Item1);
rptDummy.DataBind();
3 - Define an event OnItemDataBound:
protected void rptDummy_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
IGrouping<string, Tuple<string, string>> group = (IGrouping<string, Tuple<string, string>>)e.Item.DataItem;
RadioButtonList list = (RadioButtonList)e.Item.FindControl("rbl");
list.DataSource = group;
list.DataBind();
}
}
You see that each IGrouping<string, Tuple<string, string>>belongs to the RadioButtons group of a specific GroupName, they are also elements of the relay. For each item, we create a new RadioButtonList, which represents the entire RadioButtons group.
, DataStructure, Tuple, , Item1 Item2.
UPDATE:
:
protected void button_OnClick(object sender, EventArgs e)
{
foreach (RepeaterItem item in rptDummy.Items)
{
RadioButtonList list = (RadioButtonList)item.FindControl("rbl");
string selectedValue = list.SelectedValue;
}
}