我在repeater里面绑定了一个RadioButton和其他几项数据,格式大概为这样:
<asp:repeater id=“rep” runat="server">
<itemTemplate>
<TD > <asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="true" GroupName="1" OnCheckedChanged="changed"/></TD>
<TD ><%# DataBinder.Eval(Container.DataItem,"geneStep") %></TD>
<TD ><%# DataBinder.Eval(Container.DataItem,"ProfessionKind") %></TD>
<TD ><%# DataBinder.Eval(Container.DataItem,"air") %></TD>
<TD ><%# DataBinder.Eval(Container.DataItem,"water") %〉</TD>
<TD ><%# DataBinder.Eval(Container.DataItem,"product") %></TD>
</itemTemplate>
</asp:repeater>
我想达到的目的是:在数据库中将数据提出来之后,假如有10条纪录,每个记录前都应该有一个RadioButton是吧,当点击任何一个RadioButton后,自动将本条记录中的其他字段的值(geneStep、ProfessionKind等的值)传出来,然后它的Check=true,也就是说:自动提交到服务器之后哪个RadioButton选中的还是选中的,没选中还是没选中。
现在我做的是:提取出数据之后,点击任何一个RadioButton都可以,就是说只能选中,不能取消。在RadioButton的OnCheckChanged事件里将repeater重新绑定之后,每次点击RadioButton之后,由于重新提交到服务器,所以每个RadioButton又都不是选中的了。
怎么达到我上面说的那样啊?
请大家帮忙,谢谢了。
-------------------------------------------------------------------------
后来我又问了一些,可能不能用服务器端控件,而如果用客户端控件的话,我要把所选中的一行的数据区出来,是用Repeater绑定的数据。该怎么做啊?
-----------------------------------------------------------------------
没分了,如果问题解决了,我在申请新号给分。
-----------------------------------------------------------------------
问题补充:
http://community.csdn.net/Expert/topic/5726/5726962.xml?temp=.7734796
http://community.csdn.net/Expert/topic/5735/5735207.xml?temp=.5758783
http://community.csdn.net/Expert/topic/5740/5740478.xml?temp=.306164
------------------------------------------------------------------------
问题比较长,由于回答的人少,所以没解决帖子就沉了,只好洁帖了,希望这次能在大家的帮助下解决,我可以在申请新号给分。
<asp:repeater id=“rep” runat="server">
<itemTemplate>
<TD > <asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="true" GroupName="1" OnCheckedChanged="changed"/></TD>
<TD ><%# DataBinder.Eval(Container.DataItem,"geneStep") %></TD>
<TD ><%# DataBinder.Eval(Container.DataItem,"ProfessionKind") %></TD>
<TD ><%# DataBinder.Eval(Container.DataItem,"air") %></TD>
<TD ><%# DataBinder.Eval(Container.DataItem,"water") %〉</TD>
<TD ><%# DataBinder.Eval(Container.DataItem,"product") %></TD>
</itemTemplate>
</asp:repeater>
我想达到的目的是:在数据库中将数据提出来之后,假如有10条纪录,每个记录前都应该有一个RadioButton是吧,当点击任何一个RadioButton后,自动将本条记录中的其他字段的值(geneStep、ProfessionKind等的值)传出来,然后它的Check=true,也就是说:自动提交到服务器之后哪个RadioButton选中的还是选中的,没选中还是没选中。
现在我做的是:提取出数据之后,点击任何一个RadioButton都可以,就是说只能选中,不能取消。在RadioButton的OnCheckChanged事件里将repeater重新绑定之后,每次点击RadioButton之后,由于重新提交到服务器,所以每个RadioButton又都不是选中的了。
怎么达到我上面说的那样啊?
请大家帮忙,谢谢了。
-------------------------------------------------------------------------
后来我又问了一些,可能不能用服务器端控件,而如果用客户端控件的话,我要把所选中的一行的数据区出来,是用Repeater绑定的数据。该怎么做啊?
-----------------------------------------------------------------------
没分了,如果问题解决了,我在申请新号给分。
-----------------------------------------------------------------------
问题补充:
http://community.csdn.net/Expert/topic/5726/5726962.xml?temp=.7734796
http://community.csdn.net/Expert/topic/5735/5735207.xml?temp=.5758783
http://community.csdn.net/Expert/topic/5740/5740478.xml?temp=.306164
------------------------------------------------------------------------
问题比较长,由于回答的人少,所以没解决帖子就沉了,只好洁帖了,希望这次能在大家的帮助下解决,我可以在申请新号给分。
string[] arrstr = str.Split(new char[]{','});
请帮帮忙,谢谢。
Repeater中的所有RadioButton同属一个组,只能选中其中的一个。选中的那一个,把该行的数据提交。
<ItemTemplate>
<tr>
<td>
<asp:RadioButton ID="rb" runat="server" AutoPostBack="true" OnCheckedChanged="rb_CheckedChanged" />
</td>
</tr>
</ItemTemplate>.cs
比较重要的方法BindData() //绑定数据到Repeater//RadioButton的CheckChanged事件
protected void rb_CheckedChanged(object sender, EventArgs e)
{
RadioButton rb = sender as RadioButton;
if (rb != null)
{
RepeaterItem item = rb.Parent as RepeaterItem; //RadioButton所在的RepeaterItem //用item.FindControl("")获取该行中其他控件的值 //把行index保存在ViewState中
//这很重要
ViewState["ItemIndex"] = item.ItemIndex;
} BindData();
}//Repeater的ItemDataBound事件
protected void Bound(object sender, RepeaterItemEventArgs e)
{
if (ViewState["ItemIndex"] != null)
{
int index = int.Parse(ViewState["ItemIndex"].ToString());
if (e.Item.ItemIndex == index)
{
RadioButton rb = e.Item.FindControl("rb") as RadioButton;
if (rb != null)
rb.Checked = true;
}
}
}楼主你试试!
//用item.FindControl("")获取该行中其他控件的值
---------------------------------------------------
如果不用控件就不能取得这一行的值吗?