用模板列
<templatecolumns>
html表格
</templatecolumns>

解决方案 »

  1.   

    用模板列,RadioButton的id绑定不同的value
      

  2.   

    to: wxlada(绿茶)
    首先在绑定RadioButton的时候不能给起cheak属性指定列值,因为cheak必须为true或者false
    其次如果只单独绑定RadioButton的话无法实现每行只能有一个被选中的功能
      

  3.   

    而且普通的RadioButton根本就没有DataSource和DataBind的方法,也就说根本无法从dataset中获取所需要的checked值。所以必须要选用RadioButtonList
      

  4.   

    <%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <%@ Import Namespace="System.Data" %>
    <html>
    <script language="C#" runat="server">    ICollection CreateDataSource() {
            DataTable dt = new DataTable();
            DataRow dr;        dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
            dt.Columns.Add(new DataColumn("StringValue", typeof(string)));
            dt.Columns.Add(new DataColumn("DateTimeValue", typeof(DateTime)));
            dt.Columns.Add(new DataColumn("BoolValue", typeof(bool)));
            dt.Columns.Add(new DataColumn("CurrencyValue", typeof(double)));        for (int i = 0; i < 9; i++) {
                dr = dt.NewRow();            dr[0] = i;
                dr[1] = "Item " + i.ToString();
                dr[2] = DateTime.Now;
                dr[3] = (i % 2 != 0) ? true : false;
                dr[4] = 1.23 * (i+1);            dt.Rows.Add(dr);
            }        DataView dv = new DataView(dt);
            return dv;
        }void Page_Load(Object sender, EventArgs e) {
    string master = "three|four.";
    string master_2="";
    string [] master_1 = master.Split(new Char [] {'|'});
    for (int i = 0; i < master_1.Length; i++) {
    master_2 += "&nbsp;"+master_1[i];
    }
    lb.Text = master_2;
    if(!IsPostBack){
            MyDataGrid.DataSource = CreateDataSource();
            MyDataGrid.DataBind();
       }
      }
    public bool bb(object obj)
    {
    string tf = obj.ToString();
    if(tf=="Item 3")
    return true;
    else
    return false;
    }
    void sb(Object sender, EventArgs E) {
     string aa="";
    for( int i = 0; i < MyDataGrid.Items.Count; i++ ){
    RadioButton rb0 = ( RadioButton )MyDataGrid.Items[i].FindControl("rb_0");
    RadioButton rb1 = ( RadioButton )MyDataGrid.Items[i].FindControl("rb_1");
    RadioButton rb2 = ( RadioButton )MyDataGrid.Items[i].FindControl("rb_2");
          string bb = "";
      string cc = "";
      if(rb0.Checked)
      bb += "true_rb0";
       if(rb1.Checked)
      bb += "true_rb1";
       if(rb2.Checked)
      bb += "true_rb2";
    for( int j = 0; j < MyDataGrid.Columns.Count; j++ ){
      cc +=MyDataGrid.Items[i].Cells[j].Text+"&nbsp;&nbsp;";
      }
          aa +=bb+cc+"<br>";
          }
    lb.Text=aa;
    }
    public void MyDataGrid_Command(Object sender, DataGridCommandEventArgs e)
          {
           if (e.CommandName == "Radio0"){
                  l.Text = e.ToString();
             }
          }
    </script><body>    <h3><font face="Verdana">Simple DataGrid Example</font></h3>    <form runat=server>      <ASP:DataGrid id="MyDataGrid" runat="server"
       AutoGenerateColumns="false"
            BorderColor="black"
            BorderWidth="1"
            GridLines="Both"
            CellPadding="3"
            CellSpacing="0"
            Font-Name="Verdana"
            Font-Size="8pt"
    OnItemCommand="MyDataGrid_Command"
            HeaderStyle-BackColor="#aaaadd">
    <Columns>
    <asp:TemplateColumn SortExpression="iSign" HeaderText="商品状态">
    <HeaderStyle Width="145px"></HeaderStyle>
    <ItemTemplate>
    <asp:RadioButton id=rb_0 runat="server" Text="下架"  AutoPostBack="false"  CommandName="Radio0" Checked='<%# Convert.ToInt32(DataBinder.Eval(Container.DataItem,"IntegerValue"))<3?true:false %>' GroupName="iSign">
    </asp:RadioButton>
    <asp:RadioButton id=rb_1 runat="server" Text="上架" AutoPostBack="false" CommandName="Radio1" Checked='<%# Convert.ToInt32(DataBinder.Eval(Container.DataItem,"IntegerValue"))==3?true:false %>' GroupName="iSign">
    </asp:RadioButton>
    <asp:RadioButton id=rb_2 runat="server"  Text="缺货" AutoPostBack="false" CommandName="Radio2" Checked='<%# Convert.ToInt32(DataBinder.Eval(Container.DataItem,"IntegerValue"))>3?true:false %>' GroupName="iSign">
    </asp:RadioButton>
    </ItemTemplate>
    </asp:TemplateColumn>
               <asp:BoundColumn HeaderText="Integer" DataField="IntegerValue" />
                <asp:BoundColumn HeaderText="Date/Time" DataField="DateTimeValue"/>
                <asp:BoundColumn HeaderText="String" DataField="StringValue"/>
                <asp:BoundColumn HeaderText="True/False" DataField="BoolValue"/>
                <asp:BoundColumn HeaderText="Price" DataField="CurrencyValue" DataFormatString="{0:c}" ItemStyle-HorizontalAlign="right" />
    <asp:TemplateColumn HeaderText="商品">
    <HeaderStyle Width="145px"></HeaderStyle>
    <ItemTemplate>
    <asp:Label id=rb Text='<%# Convert.ToInt32(DataBinder.Eval(Container.DataItem,"IntegerValue"))<3?true:false %>' runat="server"/>
    </ItemTemplate>
    <footertemplate></footertemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn HeaderText="商品">
    <HeaderStyle Width="145px"></HeaderStyle>
    <ItemTemplate>
    <asp:TextBox id=tb  Text='<%# Convert.ToInt32(DataBinder.Eval(Container.DataItem,"IntegerValue"))<3?true:false %>' runat="server"/>
    </ItemTemplate>
    <footertemplate></footertemplate>
    </asp:TemplateColumn></Columns>
    </ASP:DataGrid>
          
    <asp:button ID="bt" Text="提交" OnClick="sb" runat="server"/>
      </form>
     <asp:Label id="lb" runat="server"/>
     <asp:label ID="l" runat="server"></asp:label>
     <a href="m.rar">下载源码</a> </body>
    </html>
      

  5.   

    以上是一位兄弟写的datagrid示例,请参考,演示地址忘了!