我在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
------------------------------------------------------------------------
问题比较长,由于回答的人少,所以没解决帖子就沉了,只好洁帖了,希望这次能在大家的帮助下解决,我可以在申请新号给分。

解决方案 »

  1.   

    你看这样行不行,把RadioButton的状态保存起来,每次更改后都修改RadioButton的状态,然后在保存起来,初始化的时候,定义个字符串如:string str = ",,,,,,,",然后Session["str"]=str;逗号的个数根据你查出的记录的条数来决定,然后每当修改RadioButton的状态的时候在他的事件中先读出Session["str"],然后定义个字符串数组,把Session["str"]按","分组然后赋给字符串数组,修改相应的状态,在连成字符串保存到Session["str"]中.
      

  2.   

    赋值数组如: 
    string[] arrstr = str.Split(new char[]{','});
      

  3.   

    很想帮你,可是repeater控件还没用过,只能帮你顶了
      

  4.   

    服务器端的话,那个RadioButton点击以后就不能再点击了,也就是说它保持了Check==true的状态,此时还可以点击其他的,radiobutton变成了向checkbox那样的复选框。
    请帮帮忙,谢谢。
      

  5.   

    很想帮你,可是不明白你的问题,看了模模糊糊的。Repeater继承了INamingContainer接口,所有“<asp:RadioButton ID="RadioButton1" runat="server"  AutoPostBack="true" GroupName="1" OnCheckedChanged="changed"/>”中的GroupName是无效的。因为这个RadioButton所对应的组里只有一个元素,就是它自己,而且选中了以后,就无法取消。你是不是这样的意思:Repeater中的所有RadioButton同属一个组,只能选中其中的一个。选中的那一个,把该行的数据提交。
      

  6.   

    什么意思?要是提交后那个之前选中的RadioButton还是选中?有个办法就是用session
      

  7.   

    对,就像JGood()所说一样,只是不知道怎么来实现。还请帮忙。
    Repeater中的所有RadioButton同属一个组,只能选中其中的一个。选中的那一个,把该行的数据提交。
      

  8.   

    Repeater继承并实现了INamingContainer接口,所以RepeaterItem中的RadioButton有相同的ID而不会冲突(在输出html时,他们的id属性是不一样的,这就是INamingContainer的作用)。同样,GroupName也会一样,在输出html的时候,他们就不可能在同一组。所以如果用RadioButton的GroupName来达到“多选一”这个效果不现实,不过换一种思路,可以实现你要的效果:.aspx:
    <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;
            }
        }
    }楼主你试试!
      

  9.   

    我昨天晚上想了想,大概也是这样,就是不知道怎么取点中的RadioButton这一行的值,而且在点中这一行之后还要把每行的数据取出来,这个不知道怎么实现,JGood()多谢了。我在给你100分够吗?
      

  10.   

    还有就是:
    //用item.FindControl("")获取该行中其他控件的值
    ---------------------------------------------------
    如果不用控件就不能取得这一行的值吗?
      

  11.   

    JGood请进http://community.csdn.net/Expert/PostNew.asp?room=5202