如何得到嵌套在Repeater里的RadioButtonList控件的SelectedValue的值

wjy217213 2010-01-29 08:43:09
aspx:
<table border="0" cellpadding="0" cellspacing="0" style=" margin-top:10px;" width="100%">
<asp:Repeater runat="server" ID="rptypelist" OnItemDataBound="rptypelist_ItemDataBound" >
<ItemTemplate>
<tr><td>
<asp:Label ID="lbId" runat="server" Text='<%#Eval("Id") %>' Visible="false"></asp:Label>
<asp:RadioButtonList ID="rblItem" runat="server"> </asp:RadioButtonList>
</td> </tr>
<tr>
<td >
<a href='voteCount.aspx?id=<%# DataBinder.Eval(Container.DataItem, "id") %>&voteDetailsID='><asp:Image ID="ImaVote" runat="server" ImageUrl="~/Images/btntoupiao.gif" o /></a>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
.cs:
protected void RpTypeBind()
{
string strSql = "select * from voteMaster ";
ds = SqlExec.ExecuteDataSet(strSql);
this.rptypelist.DataSource = ds;
this.rptypelist.DataMember = ds.Tables[0].TableName;
this.rptypelist.DataBind();

}
protected void rptypelist_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
RadioButtonList rbl = (RadioButtonList)e.Item.FindControl("rblItem");
Label lbl = (Label)e.Item.FindControl("lbId");
DetailsID= Convert.ToInt32( rbl.SelectedValue);
if (lbl != null)
{
string strSql = "select voteDetailsID,voteItem from voteDetails where ID = " + Convert.ToInt32(lbl.Text.Trim());
ds = SqlExec.ExecuteDataSet(strSql);
rbl.DataSource = ds;//指定数据源
rbl.DataTextField = "voteItem"; //指定要显示的字段
rbl.DataValueField = "voteDetailsID";//指定主键字段
rbl.DataBind();//绑定Rd
}
}
}
如何得到嵌套在Repeater里的RadioButtonList控件的SelectedValue的值作为参数传给上面红色的voteDetailsID,因为voteCount.aspx需要voteDetailsID这个值,但是它却是嵌套在Repeater里的RadioButtonList控件的属性,怎么做?或者有没有其它替代方法来实现功能。请大家帮忙解决一下!!!
...全文
521 27 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
27 条回复
切换为时间正序
请发表友善的回复…
发表回复
Cindy_2010 2010-09-09
  • 打赏
  • 举报
回复
protected void RepeaterTitle_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater RepeaterBooks = e.Item.FindControl("RepeaterBooks") as Repeater;
Label lab = e.Item.FindControl("lab") as Label;
ViewState["labText"] = lab.ToolTip.ToString();
RepeaterBooks.DataSource = View_ProductsBLL.Get_AllProductsByAId(int.Parse(lab.ToolTip));
RepeaterBooks.DataBind();
}
}
suncheng_hong 2010-01-30
  • 打赏
  • 举报
回复
rd.SelectedItem.value
ouc_ajax 2010-01-30
  • 打赏
  • 举报
回复
Jf
Adechen 2010-01-30
  • 打赏
  • 举报
回复
哈哈,来晚了,接分啦
wjy217213 2010-01-30
  • 打赏
  • 举报
回复
问题解决,哥儿们进来的都留个言吧,我好散分!!!呵呵
vip__888 2010-01-29
  • 打赏
  • 举报
回复

for(int i=0;i<repeater.Items.Count;i++)
{
RadioButtonList rbl=(RadioButtonList)repeater.Items[i].findcontrol("yourID");
rbl.Text;//这就是你的值 手写的 自己拿过去改下
}
wjy217213 2010-01-29
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 sq_zhuyi 的回复:]
#6楼
Response.Redirect是否执行了,如果没有执行page_load中是否加了if(!ispostback)
如果执行了试下是否能得到rd.SelectedItem.Text
[/Quote]

Response.Redirect执行了,但是得不到rd.SelectedItem.Text的值,怎么办?大侠
lovexilove 2010-01-29
  • 打赏
  • 举报
回复
findcontrol()
路人乙e 2010-01-29
  • 打赏
  • 举报
回复
#6楼
Response.Redirect是否执行了,如果没有执行page_load中是否加了if(!ispostback)
如果执行了试下是否能得到rd.SelectedItem.Text
wjy217213 2010-01-29
  • 打赏
  • 举报
回复
问题也可以理解为嵌套在Repeater里的RadioButtonList控件同嵌套在Repeater里的Button控件传radiobuttonlist1.selecteditem.value 这一值
wjy217213 2010-01-29
  • 打赏
  • 举报
回复
顶一下,在线等答案!
wjy217213 2010-01-29
  • 打赏
  • 举报
回复
RadioButtonList控件的SelectedValue的值能得到,我想问的是怎么传到前台<a href='voteCount.aspx?voteDetailsID='> <asp:Image ID="ImaVote" runat="server" ImageUrl="~/Images/btntoupiao.gif" /> </a> 的链接中,或传给嵌套在Repeater里的Button1的protected void Button1_Click(object sender, EventArgs e)
{
//Response.Redirect("voteCount.aspx?voteDetailsID="+);
}voteDetailsID中,
protected void Button1_Click(object sender, EventArgs e)
{
foreach (RepeaterItem ri in rptypelist.Items)
{
if (ri.ItemType == ListItemType.Item || ri.ItemType == ListItemType.AlternatingItem)
{
RadioButtonList rd = ri.FindControl("rblItem") as RadioButtonList;
if (rd.SelectedItem != null)
{Response.Redirect("voteCount.aspx?voteDetailsID=" + rd.SelectedItem.Value);
}
}
}
}
这种方法获取不到rd.SelectedItem.Value的值,不知道是什么原因,是不是因为RadioButtonList控件嵌套在Repeater里了?
khjian 2010-01-29
  • 打赏
  • 举报
回复
帮顶
  • 打赏
  • 举报
回复
((RadioButtonList)e.Item.FindControl("RadioButtonList1")).SelectedValue;
基本上是这样写的 要是不行就换成这样
((RadioButtonList)e.Item.FindControl("RadioButtonList1")).SelectedItem.Value
bychgh 2010-01-29
  • 打赏
  • 举报
回复

radiobuttonlist控件有一个叫SelectIndex的属性,这个个属性就是你选定时的索引值。radiobuttonlist.SelectedIndex
获取值的方法如下
radiobuttonlist1.selecteditem.value
在后台获取,再赋值给voteDetailsID,看行不?
liaoyukun111 2010-01-29
  • 打赏
  • 举报
回复
<asp:RadioButton
应该用这个吧
职业经理人 2010-01-29
  • 打赏
  • 举报
回复
兄弟你还在1.1啊,等下给你搞搞
C_NET_rgz 2010-01-29
  • 打赏
  • 举报
回复
RadioButtonList aa = rptypelist.findcontrol("rblItem") as RadioButtonList
wjy217213 2010-01-29
  • 打赏
  • 举报
回复
不用每个票投完都点投票了,把投票按钮做一个放在Repeater外面,那又应该怎么做呀?
wjy217213 2010-01-29
  • 打赏
  • 举报
回复
SelectedItem.Value没有值为什么呀?
加载更多回复(7)

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧