repeater循环出的checkbox,实现单选 代码 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 单选,使用rediobuton就可以啊。为何使用checkbox 是,我一开始也用了 <asp:RadioButton ID="RBtnxz" runat="server" GroupName="1" />但是页面不可以单选 是,我一开始也用了 <asp:RadioButton ID="RBtnxz" runat="server" GroupName="1" />但是页面不可以单选 我在repeater外面就可以,里面就不行 <input id="Repeater2_ctl00_RBtnxz" type="radio" name="Repeater2$ctl00$1" value="RBtnxz" />页面源 for (int i = 0; i < this.Play_ListRepeater.Items.Count; i++) //遍历 { CheckBox check = (CheckBox)this.Play_ListRepeater.Items[i].FindControl("Music_Box"); //Label Music_lable = (Label)this.Play_ListRepeater.Items[i].FindControl("Music_Name"); //if (check.Checked == true) //{ // string aa = check.Value; // string bb = check.Name; //} if(check.Checked==false) { string aa = check.Text; string bb = check.Text; } else { string aa = check.Text; string bb = check.Text; } 单选,使用rediobuton,并用PANEL 容器框选所有rediobuton,系统自动为你单选 panel怎么能容器框选所有rediobuton,repeater里面循环出来的 上百度找下 单选的复选框js就行了 你加到页面上应该就ok了 //前台 <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <input type="checkbox" name="<%# DataBinder.Eval(Container.DataItem,"name") %>" /> <%# DataBinder.Eval(Container.DataItem,"value") %> </ItemTemplate> </asp:Repeater>//后台 DataSet ds = new DataSet(); DataTable tbl = ds.Tables.Add("mytable"); tbl.Columns.Add("name"); tbl.Columns.Add("value"); // 添加新行 DataRow row = tbl.NewRow(); row["name"] = "test"; row["value"] = "checkbox1"; tbl.Rows.Add(row); row = tbl.NewRow(); row["name"] = "test"; row["value"] = "checkbox2"; tbl.Rows.Add(row); Repeater1.DataSource = tbl.DefaultView; Repeater1.DataBind();是不是需要这样?我觉得像你这样还是先去找本书看比较好, Repeater 里面设置一个TD 根据问题类型来决定使用CheckBox还是rediobuton <asp:Repeater ID="rptList" runat="server"> <ItemTemplate> <div style="width: 90%; margin-bottom: 5px;"> <table class="table" width="100%" border="0"> <tr> <td> <div class="qNumber"> Q.<%# Container.ItemIndex + 1%></div> <b> <%# Eval("Title")%> </b> </td> </tr> <tr> <td runat="server" id="tdOption" style="padding: 5 0 5 20;"> </td> </tr> </table> </div> </ItemTemplate></asp:Repeater> if (myDT != null) //数据不为空 { rptList.DataSource = myDT; rptList.DataBind(); if (myDT.Rows.Count > 0) { for (int i = 0; i < myDT.Rows.Count; i++) { bool IsType = myDT.Rows[i]["Type"].ToString() == "1" ? true : false; //0 单选 1 多选 if (IsType)//多选 { CheckBoxList ckblist = new CheckBoxList(); ckblist.ID = "ckbAnswer" + i; DataTable optionDT = new DataTable(); optionDT //问题的数据 if (optionDT != null) { ckblist.DataSource = optionDT; ckblist.DataTextField = "答案"; ckblist.DataValueField = "答案值"; ckblist.DataBind(); } HtmlTableCell tdOption = (HtmlTableCell)rptList.Items[i].FindControl("tdOption"); tdOption.Controls.Add(ckblist); //添加到TD里面去 } else { RadioButtonList rbtlist = new RadioButtonList(); rbtlist.ID = "rbtlist" + i; DataTable optionDT = new DataTable(); optionDT //问题的数据 自己去拿吧 if (optionDT != null) { rbtlist.DataSource = optionDT; rbtlist.DataTextField = "答案"; rbtlist.DataValueField = "值"; rbtlist.DataBind(); } HtmlTableCell tdOption = (HtmlTableCell)rptList.Items[i].FindControl("tdOption"); tdOption.Controls.Add(rbtlist); } } } } } 1.<input type="radio" name="day" id="r4" value="后天"/><label for="r4">后天</label>2.<asp:RadioButton ID="RadioButton1" runat="server" Text="今天" GroupName="day"/>第一可以实现单选,但是第二个不可以,问下我怎么在后台得到前台他选和这一行ID, checkbox 单选,checkbox是repeater循环出来的,多少个不知道 js代码也可以只求单选 牛腩新闻发布系统里面有个repeater控件中根据是否登录来显示删除按钮(linkbutton),看看,也许能有启发。<asp:Repeater ID="repComment" runat="server" OnItemDataBound="repComment_ItemDataBound"> <ItemTemplate> ......<asp:LinkButton ID="lbtnDelComment" onclick="lbtnDelComment_Click" CommandArgument='<%# Eval("id") %>' runat="server" Visible="false">删除</asp:LinkButton><ItemTemplate> </asp:Repeater>cs文件: // 根据session的值显示或者隐藏删除评论的按钮 protected void repComment_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { // 判断session的值显示或者隐藏删除评论的按钮 if (Session["admin"] != null && Session["admin"].ToString() == "niunan") { ((LinkButton)e.Item.FindControl("lbtnDelComment")).Visible = true; } } } <input type="radio" name="day" id="r4" value="后天" runat=server /><label for="r4">后天</label>后台就可以得到; C#实现TextBox的自动匹配属性 正则高手来帮忙,解决一个问题!! 程序连接到指定无线AP 程序绑定硬盘号怎么做? 有关AForge.Imaging.dll的商业使用问题 C# 调用vc编写的dll 的问题 求一个正则表达式 winform应用程序打包问题 Form之间的数据传递问题 HTTP POST访问 在线等待:自定义DataGridViewColumn控件中自定义属性值无法保存的问题? 求救~~C#又出问题了。~还是 老问题啊。并非所有的代码路径都返回值
但是页面不可以单选
是,我一开始也用了 <asp:RadioButton ID="RBtnxz" runat="server" GroupName="1" />
但是页面不可以单选 我在repeater外面就可以,里面就不行
{
CheckBox check = (CheckBox)this.Play_ListRepeater.Items[i].FindControl("Music_Box");
//Label Music_lable = (Label)this.Play_ListRepeater.Items[i].FindControl("Music_Name");
//if (check.Checked == true)
//{
// string aa = check.Value;
// string bb = check.Name;
//}
if(check.Checked==false)
{
string aa = check.Text;
string bb = check.Text;
}
else
{
string aa = check.Text;
string bb = check.Text;
}
panel怎么能容器框选所有rediobuton,repeater里面循环出来的
//前台
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<input type="checkbox" name="<%# DataBinder.Eval(Container.DataItem,"name") %>" />
<%# DataBinder.Eval(Container.DataItem,"value") %>
</ItemTemplate>
</asp:Repeater>//后台
DataSet ds = new DataSet();
DataTable tbl = ds.Tables.Add("mytable");
tbl.Columns.Add("name");
tbl.Columns.Add("value"); // 添加新行
DataRow row = tbl.NewRow();
row["name"] = "test";
row["value"] = "checkbox1";
tbl.Rows.Add(row); row = tbl.NewRow();
row["name"] = "test";
row["value"] = "checkbox2";
tbl.Rows.Add(row);
Repeater1.DataSource = tbl.DefaultView;
Repeater1.DataBind();是不是需要这样?
我觉得像你这样还是先去找本书看比较好,
<asp:Repeater ID="rptList" runat="server">
<ItemTemplate>
<div style="width: 90%; margin-bottom: 5px;">
<table class="table" width="100%" border="0">
<tr>
<td>
<div class="qNumber">
Q.<%# Container.ItemIndex + 1%></div>
<b>
<%# Eval("Title")%>
</b>
</td>
</tr>
<tr>
<td runat="server" id="tdOption" style="padding: 5 0 5 20;">
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:Repeater>
if (myDT != null) //数据不为空
{
rptList.DataSource = myDT;
rptList.DataBind();
if (myDT.Rows.Count > 0)
{
for (int i = 0; i < myDT.Rows.Count; i++)
{
bool IsType = myDT.Rows[i]["Type"].ToString() == "1" ? true : false; //0 单选 1 多选
if (IsType)//多选
{ CheckBoxList ckblist = new CheckBoxList();
ckblist.ID = "ckbAnswer" + i;
DataTable optionDT = new DataTable();
optionDT //问题的数据 if (optionDT != null)
{
ckblist.DataSource = optionDT;
ckblist.DataTextField = "答案";
ckblist.DataValueField = "答案值";
ckblist.DataBind();
} HtmlTableCell tdOption = (HtmlTableCell)rptList.Items[i].FindControl("tdOption");
tdOption.Controls.Add(ckblist); //添加到TD里面去
}
else
{ RadioButtonList rbtlist = new RadioButtonList();
rbtlist.ID = "rbtlist" + i;
DataTable optionDT = new DataTable();
optionDT //问题的数据 自己去拿吧
if (optionDT != null)
{
rbtlist.DataSource = optionDT;
rbtlist.DataTextField = "答案";
rbtlist.DataValueField = "值";
rbtlist.DataBind();
}
HtmlTableCell tdOption = (HtmlTableCell)rptList.Items[i].FindControl("tdOption");
tdOption.Controls.Add(rbtlist);
}
}
}
}
}
<input type="radio" name="day" id="r4" value="后天"/><label for="r4">后天</label>
2.
<asp:RadioButton ID="RadioButton1" runat="server" Text="今天" GroupName="day"/>
第一可以实现单选,但是第二个不可以,问下我怎么在后台得到前台他选和这一行ID,
<ItemTemplate>
......
<asp:LinkButton ID="lbtnDelComment" onclick="lbtnDelComment_Click" CommandArgument='<%# Eval("id") %>' runat="server" Visible="false">删除</asp:LinkButton>
<ItemTemplate>
</asp:Repeater>cs文件:
// 根据session的值显示或者隐藏删除评论的按钮
protected void repComment_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
// 判断session的值显示或者隐藏删除评论的按钮
if (Session["admin"] != null && Session["admin"].ToString() == "niunan")
{
((LinkButton)e.Item.FindControl("lbtnDelComment")).Visible = true;
}
}
}