Gridview,RadioButtonList

1.GridView

在aspx页面加gridview控件

        <asp:GridView ID="grid1" runat="server" OnRowDataBound="grid1_RowDataBound"
            HeaderStyle-CssClass="tdbackcolor" Font-Size="14px" CellPadding="5">
            <HeaderStyle CssClass="tdbackcolor" BackColor="Gainsboro"></HeaderStyle>
            <FooterStyle BackColor="Gainsboro" Font-Size="14px" />
        </asp:GridView>
后台代码

        grid1.Columns.Clear();
        BoundField col = new BoundField();
        col.DataField = "name";
        col.HeaderText = "姓名";
        col.Visible = true;
        grid1.Columns.Add(col);

        BoundField col1 = new BoundField();
        col1.DataField = "age";
        col1.HeaderText = "年龄";
        col1.Visible = true;
        grid1.Columns.Add(col1);

        BoundField col2 = new BoundField();
        col2.DataField = "school";
        col2.HeaderText = "学校";
        col2.Visible = true;
        grid1.Columns.Add(col2);

        //添加数据源
        DataTable dt = new DataTable();
        dt.Columns.Add(new DataColumn("name", typeof(string)));
        dt.Columns.Add(new DataColumn("age", typeof(decimal)));
        dt.Columns.Add(new DataColumn("school", typeof(string)));

        dt.Rows.Add("张三", 16, "一中");
        dt.Rows.Add("李四", 13, "二中");
        dt.Rows.Add("王五", 14, "九中");
        dt.Rows.Add("陈留", 17, "六中");
        dt.Rows.Add("吴七", 18, "七中");

        //将gridview的数据源绑定为dt,这样的话,gridview自定义的字段名会和表中字段名匹配,相同的则显示该列的数据
        grid1.AutoGenerateColumns = false;
        this.grid1.DataSource = dt;
        this.grid1.DataBind();  
效果:

2.RadioButtonList

apsx页面上:

        <asp:RadioButtonList RepeatDirection="Horizontal" runat="server" ID="cqcAnalysisType"
                            RepeatLayout="Table" 
                            AutoPostBack="True">
        </asp:RadioButtonList>

后台添加项:

        this.cqcAnalysisType.Items.Add(new ListItem("吃饭", "eat"));
        this.cqcAnalysisType.Items.Add(new ListItem("睡觉", "sleep"));
        this.cqcAnalysisType.Items.Add(new ListItem("唱歌", "sing"));

效果图:



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值