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());
        }
    
    截图如下:

    怀揣着一点点梦想的年轻人
    相信技术和创新的力量
    喜欢快速反应的工作节奏
  • 相关阅读:
    sublimetext ruby 插件
    [C]goto statement, rarely been used. Deprecated???
    [C]union
    [C] Struct Test
    [C,Java,Python]Command Line Argument: argv, argc, sys.argv, args
    [Python]**otherInfo, *other
    [C]parameterized macros 带参数的宏
    [C]指针与结构变量
    [C]结构变量传递给函数
    [C]结构变量数组array of structure varibles
  • 原文地址:https://www.cnblogs.com/hfliyi/p/1982603.html
Copyright © 2011-2022 走看看