Reputation:
hi I need to design a code like this image in asp.net:
the lists come from a database and the elements come from database too .
but I need to make each box : (1 list - multi element) is a separated radiobox so I can click any where inside the box and check the radio in it
I think about make a asp:RadioButtonList for the main datasource (for the list)
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
</asp:RadioButtonList>
and inside each radio make a repeater for the elements in every list ... how to do it ? how can I add repeater inside a radiobuttonlist ?
I tried this code
:
<asp:RadioButtonList ID="radio" runat="server" DataSourceID="radio" DataTextField="name" DataValueField="id">
<asp:HiddenField runat="server" ID="hidden" value='<%#Eval("id") %>'>
</asp:HiddenField>
<asp:Repeater runat="server" ID="repeater" DataSourceID="repeaterds">
<ItemTemplate>
<%#Eval("name") %>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="repeaterds" runat="server" ConnectionString="<%$ ConnectionStrings:samy_sarc %>" SelectCommand="select * from level where (team_id = @id)">
<SelectParameters>
<asp:ControlParameter ControlID="hidden" Name="@id" PropertyName="Value" />
</SelectParameters>
</asp:SqlDataSource>
</asp:RadioButtonList>
<asp:SqlDataSource ID="radiods" runat="server" ConnectionString="<%$ ConnectionStrings:samy_sarc %>" SelectCommand="select * from team"></asp:SqlDataSource>
but it's won't work because the radiobuttonlist didn't take sibling element
Upvotes: 1
Views: 2178
Reputation: 141
Maybe i misunderstood your question, with no need for using repeater...
public class TData
{
public String TText { get; set; }
public UInt32 TValue { get; set; }
}
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
List<TData> Data = new List<TData>
{
new TData{TText = "JSON", TValue = 0},
new TData{TText = "C#", TValue = 1},
new TData{TText = "JAVA", TValue = 2},
};
this.RadioButtonList1.DataTextField = "TText";
this.RadioButtonList1.DataValueField = "TValue";
this.RadioButtonList1.DataSource = Data;
this.RadioButtonList1.DataBind();
}
}
all right, let's improve it
asp.net page
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:RadioButton runat="server" Text="<%# (Container.DataItem as Dummy.TData).TText %>" />
<asp:Repeater runat="server" DataSource="<%# (Container.DataItem as Dummy.TData).TValue %>">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text="<%# (Container.DataItem as Dummy.TData1).TText %>"></asp:Label>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
and code behind:
public class TData1
{
public String TText { get; set; }
public String TValue { get; set; }
}
public class TData
{
public String TText { get; set; }
public List<TData1> TValue { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
List<TData1> lst = new List<TData1>
{
new TData1 {TText = "JSON", TValue = "0"},
new TData1 {TText = "C#", TValue = "1"},
new TData1 {TText = "JAVA", TValue = "1"}
};
List<TData> Data = new List<TData>
{
new TData{TText = "JSON", TValue = lst},
new TData{TText = "C#", TValue = lst},
new TData{TText = "JAVA", TValue = lst}
};
this.Repeater1.DataSource = Data;
this.Repeater1.DataBind();
}
it's done
Upvotes: 1