///设置单选
/// </summary>
public void DataGridBoundEvent()
{
for(int i=0;i<dgShouldPay.Items.Count;i++)
{
Label r =(Label)(dgShouldPay.Items[i].Cells[0].FindControl("lbSel"));
if(dgShouldPay.Items[i].Cells[3].Text==null&&dgShouldPay.Items[i].Cells[2].Text=="")
{
r.Text = "<input type=radio name='myradiogroup' value=" + "" + "runat = server>";
}
else
{
r.Text = "<input type=radio name='myradiogroup' value='" + dgShouldPay.Items[i].Cells[2].Text + "'runat = server>";
}
if(i==0)
{
r.Text = "<input type=radio name='myradiogroup' value='" + dgShouldPay.Items[i].Cells[2].Text + "' checked = false runat = server>";
}}}
我用的是模板列,模板列中,放了一个Label.我怎么知道那个扭被选中

解决方案 »

  1.   

    直接用模版列吧!
    <Columns>
    <asp:TemplateColumn>
    <ItemTemplate>
    <input type=radiobutton runat=server id=rad value='<%#DataBinder.Eval(Container.DataItem,"字段名")%>'>
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    取值的时候直接
    Request.Form["rad"]就行了,不用像checkbox那样循环判断
      

  2.   

    不是那么做的..我给你一个全选,删除的函数..思路就是,把Radio用服务器控件表示..然后循环你的数据列表...========================= 
    页面数据列表控件中的代码:
    <ItemTemplate>
    <INPUT id="xz" type="checkbox" value='<%# DataBinder.Eval(Container.DataItem,"id") %>' name="xz" runat="server">
    </ItemTemplate>===============================
    #region  Del()  选中删除的函数 /// <summary>
    /// 选中删除的函数
    /// </summary>
    public void Del(object sender, System.EventArgs e)
    {
    string allid = null;
    int i=0;
    HtmlInputCheckBox cb;
    foreach(DataGridItem di in dg.Items)
    {
    cb = (HtmlInputCheckBox)di.FindControl("xz");
    if (cb.Checked==true)
    {
    allid += cb.Value+",";
    i++;
    }
    }
    if (allid!=null)
    {
    allid = allid.TrimEnd(',');
    AdminClass myClass = new AdminClass();

    if (Request.QueryString["state"] == "smallclass")
    {
    tableName = "smallclass";
    }
    else
    {
    tableName = "classList";
    }
    if(myClass.delTable(tableName,allid))
    {
    myClass.Dispose();
    Function.showerr("删除成功!",Request.Url.Segments[Request.Url.Segments.Length-1] + Request.Url.Query);
    return ;
    }
    else
    {
    myClass.Dispose();
    Function.showerr("删除失败,请返回重新操作!");
    return ;
    }
    }

    }
    #endregion
    ================================