• Gridview中放置 html的控件Radio


    在Gridview模板中放置静态的控件Radio

    //前台代码:

     <div style="text-align:center; font-size:smaller; margin:30px auto;">
            <asp:GridView ID="GridView1" BorderColor="Black" runat="server" AutoGenerateColumns="False" 
                onrowdatabound="GridView1_RowDataBound">
                <Columns>
                <asp:TemplateField HeaderText ="选择">
                <ItemTemplate>
                   <%-- <asp:RadioButton ID="RadioButton1" GroupName="aa" runat="server" Text ='<%#Eval("CustomerID") %>' />--%>
                    
                   <input name="MyRadioButton" type="radio" value='<%#Eval("CustomerID") %>' />
                </ItemTemplate>
                </asp:TemplateField>
                    <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" />
                    <asp:BoundField DataField="ContactName" HeaderText="ContactName" />
                    <asp:BoundField DataField="ContactTitle" HeaderText="ContactTitle" />
                </Columns>
                <HeaderStyle BackColor="Azure" Font-Size="12px" HorizontalAlign="Center" />
                <RowStyle HorizontalAlign="Left" />
            </asp:GridView>
        </div>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
     
    

    后台代码:

      protected void Page_Load(object sender, EventArgs e)
        {
    
            if (!IsPostBack)
            {
                databind();
            }
        }
        public void databind()
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ToString());
            SqlCommand cmd = new SqlCommand("SELECT top 10 * FROM CUSTOMERS", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            this.GridView1.DataSource = ds.Tables[0];
            this.GridView1.DataKeyNames = new string[] { "CustomerID" };
            this.GridView1.DataBind();
        }
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            foreach (TableCell  item in e.Row.Cells)
            {
                item.Attributes.Add("style", "border-color:black");
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Write(Request.Form["MyRadioButton"].ToString());
        }
    
    截图如下:

    怀揣着一点点梦想的年轻人
    相信技术和创新的力量
    喜欢快速反应的工作节奏
  • 相关阅读:
    解析XML技术
    XML名命空间
    XML解析器
    java列表组件鼠标双击事件的实现
    XML(可拓展标记语言)基本概念
    数据包式套接字:基于UDP协议的Socket网络编程
    流式套接字:基于TCP协议的Socket网络编程(案例3)
    剑指 Offer 58
    剑指 Offer 58
    剑指 Offer 57
  • 原文地址:https://www.cnblogs.com/hfliyi/p/1982603.html
Copyright © 2020-2023  润新知