zoukankan      html  css  js  c++  java
  • GridView学习,常用记下来

    先自定义一个表

    前台

      <div>
            <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" OnSelectedIndexChanged="GridView2_SelectedIndexChanged" Width="600px">
                <Columns>
                    <asp:TemplateField >
             <ItemTemplate>
                 <input id="Radio1" type="radio" name="rad" />      
             </ItemTemplate>
             </asp:TemplateField>
                    
              
                    <asp:BoundField DataField="prizename" HeaderText="入住酒店" />
                    <asp:BoundField DataField="point" HeaderText="" />
                    <asp:BoundField DataField="number" HeaderText="" />
                    <asp:BoundField DataField="totalpoint" FooterText="" HeaderText="" />
                    <asp:BoundField DataField="prizeid" FooterText="" HeaderText="" />
                    <asp:CommandField SelectText="确认价格"  HeaderText="操作" ShowSelectButton="True">
                        <ItemStyle Width="60px" HorizontalAlign="Center" />
                    </asp:CommandField>
                </Columns>
              
                
            </asp:GridView>  
        </div>

    后代码

    protected void Button1_Click(object sender, EventArgs e)
        {
            
            DataTable dt = new DataTable("cart");
            DataColumn dc1 = new DataColumn("prizename", Type.GetType("System.String"));
            DataColumn dc2 = new DataColumn("point", Type.GetType("System.Int16"));
            DataColumn dc3 = new DataColumn("number", Type.GetType("System.Int16"));
            DataColumn dc4 = new DataColumn("totalpoint", Type.GetType("System.Int64"));
            DataColumn dc5 = new DataColumn("prizeid", Type.GetType("System.String"));
            dt.Columns.Add(dc1);
            dt.Columns.Add(dc2);
            dt.Columns.Add(dc3);
            dt.Columns.Add(dc4);
            dt.Columns.Add(dc5);
            for (int i = 0; i < 10; i++)
            {
                DataRow dr = dt.NewRow();
                dr["prizename"] = "娃娃";
                dr["point"] = 10;
                dr["number"] = 1;
                dr["totalpoint"] = 10;
                dr["prizeid"] = "001";
                dt.Rows.Add(dr);
            }
            
    
            GridView2.DataSource = dt;
            GridView2.DataBind();
    
            
            
            
        }
        protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
        {
            Page.ClientScript.RegisterStartupScript(GetType(), "", "alert('aaa')", true);
        }
  • 相关阅读:
    组件之间通信(父传子)
    flex布局
    ffmpeg解析TS流(转)
    swift之?和!的含义(转)
    Swift之画圆角添加多个枚举值方法
    swift之singleton
    swift之闭包
    Swift之fallthrough
    Selector
    Settings Bundle
  • 原文地址:https://www.cnblogs.com/xu3593/p/2995725.html
Copyright © 2011-2022 走看看