GridView & Web控件

9_4

using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.WebControls;

namespace FinalTest
{
    public partial class GridView9_4 : System.Web.UI.Page
    {
        private DataView m_DataView;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            GridView1.DataSource = m_DataView;
            GridView1.DataBind();
        }

        protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
        {
            GridView1.PagerSettings.Mode = PagerButtons.Numeric;
            GridView1.DataSource = m_DataView;
            GridView1.DataBind();
        }        

        protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
        {
            GridView1.PagerSettings.Mode = PagerButtons.NextPrevious;
            GridView1.DataSource = m_DataView;
            GridView1.DataBind();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            String sqlcon = "";
            SqlConnection con = new SqlConnection(sqlcon);
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from student", con);
            SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = cmd;
            DataSet ds = new DataSet();
            adapter.Fill(ds);
            m_DataView = ds.Tables[0].DefaultView;
            RadioButton1.Checked = true;
            GridView1.DataSource = m_DataView;
            GridView1.DataBind();
        }
    }
}

验证控件

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Validator3_7_8_9.aspx.cs" Inherits="FinalTest.Validator3_7_8_9" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        用户名
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="用户名不能为空" ControlToValidate="TextBox1" Display="Dynamic"></asp:RequiredFieldValidator>
        <asp:Button ID="Button1" runat="server" Text="登录" />
        <br />
        价格
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="TextBox2" Display="Dynamic" ErrorMessage="输入大于0的数" Operator="GreaterThan" Type="Double" ValueToCompare="0"></asp:CompareValidator>
        <asp:Button ID="Button2" runat="server" Text="提交" />
        <br />
        价格     
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
        <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="TextBox3" Display="Dynamic" ErrorMessage="输入900到1000之间的数" MaximumValue="1000" MinimumValue="900" Type="Double"></asp:RangeValidator>
        <asp:Button ID="Button3" runat="server" Text="提交" />

    </div>
    </form>
</body>
</html>

列表控件-----ListBox

using System;
using System.Data;
using System.Web.UI;

namespace FinalTest
{
    public partial class ListBox : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                DataSet ds = new DataSet();
                ds.Tables.Add("stu");
                ds.Tables["stu"].Columns.Add("stuNo",typeof(int));
                ds.Tables["stu"].Columns.Add("stuName", typeof(string));
                ds.Tables["stu"].Columns.Add("stuScore", typeof(string));
                ds.Tables["stu"].Rows.Add(new object[] { 001, "tom", "98" });
                ds.Tables["stu"].Rows.Add(new object[] { 002, "mia", "88" });
                ds.Tables["stu"].Rows.Add(new object[] { 003, "heb", "20" });
                //绑定数据到listbox
                this.ListBox1.DataSource = ds.Tables["stu"];
                this.ListBox1.DataValueField = "stuNo";
                this.ListBox1.DataTextField = "stuName";
                this.ListBox1.DataBind();
            }
        }

        protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Label1.Text = "学生学号为:" + this.ListBox1.SelectedValue.ToString() + "姓名为:" +this.ListBox1.SelectedItem.Text.ToString();
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值