Click here to Skip to main content
15,888,527 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: repeater control Pin
Venkatesh Mookkan12-Aug-09 5:31
Venkatesh Mookkan12-Aug-09 5:31 
GeneralRe: repeater control Pin
deep7612-Aug-09 6:41
deep7612-Aug-09 6:41 
GeneralRe: repeater control Pin
Venkatesh Mookkan12-Aug-09 6:49
Venkatesh Mookkan12-Aug-09 6:49 
GeneralRe: repeater control Pin
deep7612-Aug-09 6:54
deep7612-Aug-09 6:54 
GeneralRe: repeater control Pin
deep7612-Aug-09 7:03
deep7612-Aug-09 7:03 
GeneralRe: repeater control Pin
Venkatesh Mookkan12-Aug-09 7:10
Venkatesh Mookkan12-Aug-09 7:10 
GeneralRe: repeater control Pin
Venkatesh Mookkan12-Aug-09 7:07
Venkatesh Mookkan12-Aug-09 7:07 
GeneralRe: repeater control Pin
deep7612-Aug-09 9:20
deep7612-Aug-09 9:20 
Abhijit Jana wrote:
eep76 wrote:
ASP.NET Tip: Using RadioButton Controls in a Repeater[^]



I tried the code from this link given by Abhijit Jana, but the code in the event handler childRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) is never reached. The radoi buttons are displayed but all are selectable.
My code copied below:
aspx:
<script type="text/javascript">
function SetUniqueRadioButton(nameregex, current)
{
re = new RegExp(nameregex);
for(i = 0; i < document.forms[0].elements.length; i++)
{
elm = document.forms[0].elements[i]
if (elm.type == 'radio')
{
if (re.test(elm.name))
{
elm.checked = false;
}
}
}
current.checked = true;
}
</script>

<!-- start parent repeater -->
<asp:repeater id="parentRepeater" runat="server">
<itemtemplate>
<br><b><%# DataBinder.Eval(Container.DataItem,"QID") %>:&nbsp;</b>
<b><%# DataBinder.Eval(Container.DataItem,"Question") %></b><br>

<!-- start child repeater -->
<asp:repeater id="childRepeater" datasource='<%# ((DataRowView)Container.DataItem)
.Row.GetChildRows("myrelation") %>' runat="server">

<itemtemplate>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:RadioButton ID="choices" runat="server" GroupName=<%# DataBinder.Eval(Container.DataItem, "[\"QID\"]")%> />
<%# DataBinder.Eval(Container.DataItem, "[\"Answer_Num\"]")%>.&nbsp;
<%# DataBinder.Eval(Container.DataItem, "[\"Answer\"]")%><br>
</asp:RadioButton>
</itemtemplate>
</asp:repeater>
<!-- end child repeater -->

</itemtemplate>
</asp:repeater>
<!-- end parent repeater -->

aspx.cs

protected void childRepeater_ItemDataBound(object sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType
!= ListItemType.AlternatingItem)
return;
RadioButton rdo = (RadioButton)e.Item.FindControl("rdoSelected");
string script =
"SetUniqueRadioButton('childRepeater.*groupName',this)";
rdo.Attributes.Add("onclick", script);
}


protected void CreateQuiz()
{
//Create the connection and DataAdapter for the questions table.
SqlConnection cnn = new SqlConnection(connectionString);
SqlDataAdapter cmd1 = new SqlDataAdapter("select QID, Question from Curriculum_Questions where ChapterID='2'",cnn);

//Create and fill the DataSet.
DataSet ds = new DataSet();
cmd1.Fill(ds,"questions");

//Create a second DataAdapter for the answers table.
SqlDataAdapter cmd2 = new SqlDataAdapter("select QID, Answer_Num, Answer from Curriculum_Answers where ChapterID='2'", cnn);
cmd2.Fill(ds,"answers");

//Create the relation bewtween the questions and answers tables.
ds.Relations.Add("myrelation",
ds.Tables["questions"].Columns["QID"],
ds.Tables["answers"].Columns["QID"]);

//Bind the questions table to the parent Repeater control, and call DataBind.
parentRepeater.DataSource = ds.Tables["questions"];
Page.DataBind();

//Close the connection.
cnn.Close();
}

Thanks for your help.
QuestionASP.NET Configuration Problem Pin
pampam11011-Aug-09 10:19
pampam11011-Aug-09 10:19 
AnswerRe: ASP.NET Configuration Problem Pin
Abhijit Jana11-Aug-09 10:42
professionalAbhijit Jana11-Aug-09 10:42 
GeneralRe: ASP.NET Configuration Problem Pin
pampam11012-Aug-09 22:21
pampam11012-Aug-09 22:21 
GeneralRe: ASP.NET Configuration Problem Pin
pampam11015-Aug-09 11:35
pampam11015-Aug-09 11:35 
GeneralRe: ASP.NET Configuration Problem Pin
JacSophie13-Jan-10 15:10
JacSophie13-Jan-10 15:10 
QuestionSome Help on how to assign a Web Service to a NamedPipe Pin
AndyASPVB11-Aug-09 9:18
AndyASPVB11-Aug-09 9:18 
AnswerRe: Some Help on how to assign a Web Service to a NamedPipe Pin
eggsovereasy11-Aug-09 11:36
eggsovereasy11-Aug-09 11:36 
GeneralRe: Some Help on how to assign a Web Service to a NamedPipe Pin
AndyASPVB11-Aug-09 12:01
AndyASPVB11-Aug-09 12:01 
QuestionProblem with crystal reports Pin
shylock111-Aug-09 9:02
shylock111-Aug-09 9:02 
AnswerRe: Problem with crystal reports Pin
Rahul Chitte17-Aug-09 6:01
Rahul Chitte17-Aug-09 6:01 
Questiona general question on download function Pin
Seraph_summer11-Aug-09 8:53
Seraph_summer11-Aug-09 8:53 
AnswerRe: a general question on download function Pin
Abhijit Jana11-Aug-09 10:47
professionalAbhijit Jana11-Aug-09 10:47 
GeneralRe: a general question on download function Pin
4anusha411-Aug-09 19:41
4anusha411-Aug-09 19:41 
GeneralRe: a general question on download function Pin
Abhijit Jana11-Aug-09 19:58
professionalAbhijit Jana11-Aug-09 19:58 
GeneralRe: a general question on download function Pin
4anusha411-Aug-09 20:00
4anusha411-Aug-09 20:00 
GeneralRe: a general question on download function Pin
Abhijit Jana11-Aug-09 20:11
professionalAbhijit Jana11-Aug-09 20:11 
GeneralRe: a general question on download function Pin
Seraph_summer12-Aug-09 9:13
Seraph_summer12-Aug-09 9:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.