GridView添加RadioButton列

 

aspx页面:

<asp:GridView ID="RadioGV" runat="server" AllowPaging="true" PageSize="5"
          OnRowDataBound="RadioGV_RowDataBound" >
       <Columns>
        <asp:TemplateField HeaderText="选择">
            <ItemTemplate>
                <asp:Literal ID="RadioButtonMarkup" runat="server"></asp:Literal>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
 

cs页面:

protected void RadioGV_RowDataBound(object sender, GridViewRowEventArgs e)
   {
       if(e.Row.RowType == DataControlRowType.DataRow)
       {
          Literal output = e.Row.FindControl("RadioButtonMarkup") as Literal;
          output.Text = string.Format("<input type=\"radio\" name=\"ProductGroup\" " +
 "id=\"RowSelector{0}\" value=\"{0}\"" ,e.Row.RowIndex);
 }
 }
 
这样就可以添加onclick事件,判断selectchange()

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>