zoukankan      html  css  js  c++  java
  • 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());
        }
    
    截图如下:

    怀揣着一点点梦想的年轻人
    相信技术和创新的力量
    喜欢快速反应的工作节奏
  • 相关阅读:
    Vue 中使用 viewerjs
    PS 给照片换背景
    HTML学习-1网页基础知识
    git使用
    Java读取XML配置文件
    Java是如何读到hbase-site.xml 的内容的
    HBASE count方法总结
    Getting Started with Java Development on Docker
    持续集成案例学习:Docker、Java与Maven
    利用MAVEN打包时,如何包含更多的资源文件
  • 原文地址:https://www.cnblogs.com/hfliyi/p/1982603.html
Copyright © 2011-2022 走看看