1.你可以使用RadioButton有选中的存储到数据库,没选的就不用了,不要用RadioButtonList
2.DataGrid记录列表中你的RadioButton将是根据记录模板自动生成的,由于NameCollection,
  所以它的GroupName将无法一样(我个人认为).所以你必须自己保证只有一项被选中.
3.你必须保留当前选择的项,当选择改变时你要将原来的首页显示给取消,然后设置当前选择的项
  为首页显示.
4.<asp:RadioButton id="rblIndexShow" Enabled="True" AutoPostBack="true"           runat="server"  OnCheckChanged="Changed" Text='<%# DataBinder.Eval(Container,"DataItem.Field") %>'> </asp:RadioButton>
behind code:
public void Changed(object sender,System.EventArgs e)
{
  //通过以下可以得到当前选中RadioButton 的Text属性值.
  ((RadioButton)sender).Text;
  //这里你可以知道当前的记录了,你就可以进行相应处理了.
}你可以将RadioButton的Text属性绑定一些必要的信息

解决方案 »

  1.   

    1:autopostback=true
    2:   'Dim i As Integer
                'Dim aa As ListItem = New ListItem("", "")
                'Dim d As RadioButtonList
                'For i = 0 To DataGrid1.Items.Count - 1
                '    d = DataGrid1.Items(i).FindControl("RadioButtonList1")
                '    d.Items.Add(aa)
                'Next            'DataGrid1.Items(0).Cells(0).RowSpan = DataGrid1.Items.Count
                'For i = 1 To DataGrid1.Items.Count - 1
                '    DataGrid1.Items(i).Cells(0).Visible = False
                'Next
      

  2.   

    public void Changed(object sender,System.EventArgs e)
    {
      //通过以下可以得到当前选中RadioButton 的Text属性值.
      ((RadioButton)sender).Text;
      //这里你可以知道当前的记录了,你就可以进行相应处理了.
    }
    能否说的在详细点儿?
    我这样改的:
    <ItemTemplate>
    <asp:RadioButton id="rbIndexShowYes" Enabled="True" AutoPostBack="true" runat="server" OnCheckChanged="changedYes"Text="是"></asp:RadioButton>
    <asp:RadioButton id="rbIndexShowNo" Enabled="True" AutoPostBack="true" Checked=True runat="server" OnCheckChanged="changedNo"Text="否">
    </asp:RadioButton>
    </ItemTemplate>
    请问:怎样程序设计?
      

  3.   

    1.你不用用两个RadioButton控件,因为RadioButton本身就有两中状态的.
    2.你可以没条记录对应一个RadioButton,然后循环DataGrid的项和findcontrol
    方法来查找到RadioButton,根据数据库中读取的号码来确定相应记录对应的
    RadioButton的Checked状态.
    3.当用户选择时会出发事件rbIndexShowYes,你可以根据Checked的当前值来判断是否选中
    来处理相应的事件(存储号码等.)
    <ItemTemplate>
        <asp:RadioButton id="rbIndexShowYes" Enabled="True" AutoPostBack="true"       
             runat="server" OnCheckChanged="changedYes"  
             Text='<%# DataBinder.Eval(Container,"DataItem.Field") %>'>
        </asp:RadioButton>
    </ItemTemplate>// 下面的方法一定不能是private的否则将提示方法受保护之类的错误.
    public void changedYes(object sender,System.EventArgs e)
    {
      // 如果当前为选中状态.
      if( ( (RadioButton)sender ).Checked )
      {
       //简单的你可以将Text属性中绑定字段设置为信息的号码.
       // 通过以下获得号码
        号码 = ((RadioButton)sender).Text;
       //然后就可以了修改存储在数据库中的号码了.
       }
       else
       {
         // 取消选中
         // 你可以进行相应的处理,比如将数据库中的号码恢复回去等.
        }
    }
      

  4.   

    下面是我的datagrid数据绑定函数,
    可是我不晓得该如何绑定RadioButton
    请执教:
    private void showMenu2(string menuNo)
    {
    string webNo = Request["webNo"];
    //查询首页显示栏目号码
    string sqlFirstShowMenu = "select FirstShowMenu from WebBaseInfo where NO='"+webNo+"'";
    DataSet dsFirstShowMenu = (new DataAccess()).GetDataSet(sql,"firstShow");
    string firstShowMenu = dsFirstShowMenu.Tables[0].Rows[0]["FirstShowMenu"].ToString();
    //给datagrid赋值
    string sql = "select WebMenu.NO,WebMenu.Title from WebMenu,WebBaseInfo where WebMenu.BelongNo=WebBaseInfo.NO and WebMenu.BelongNo = '"+webNo+"'and WebMenu.UpMenuNo =  '"+menuNo+"'";
    DataSet ds = (new DataAccess()).GetDataSet(sql,"showMenu");
    int count = ds.Tables[0].Rows.Count;
    if(count > 0)
    {
    dgMenu.Visible = true;
    dgMenu.Visible = true;
    dgMenu.DataSource = ds.Tables["showMenu"];
    dgMenu.DataBind();
    }
    else
    {
                dgMenu.Visible = false;
    }
    }
    另外:
        号码 = ((RadioButton)sender).Text;
    这条语句能找到该记录的id号吗?
    他不是“是”吗 ?
    我通过Response.write来调试结果显示不出来,
    是怎么回事?
      

  5.   

    你看一下我上面的代码,
    我是说你将记录的id号绑定到RadioButton的Text属性,然后才有"号码 = ((RadioButton)sender).Text;"Text='<%# DataBinder.Eval(Container,"DataItem.Field") %>'
    中Fiedl就是你id号的字段名NO了.你选择那个RadioButton就表示该记录为首页显示,反之就不是了.另外我个人认为RadioButton由DataGrid项模板自动生成,由于NamingContainer,它的GroupName将无法一样(即使你设置为了GroupName的值).因此要求你自己循环DataGrid的项来保证只有一个被
    选中.
      

  6.   

    for(int i=0 ;i<DataGrid1.Items.Count;i++)
    {
       ((RadioButton)DataGrid1.Items[i].Cell[icolumn].FindControl("rbIndexShowYes").Checked={True|False}; 
    //以上设置rbIndexShowYes的选择状况了.
    }