亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Asp.net GridView使用大全(分頁(yè)實(shí)現(xiàn))

 更新時(shí)間:2013年04月26日 00:40:39   作者:  
關(guān)于GridView的使用涉及很多,網(wǎng)絡(luò)上零零散散的有一些,為了讓自己使用方便,也為了大家能很好的學(xué)習(xí)與工作,我把網(wǎng)絡(luò)上的GridView使用方法收集了一些

GridView自帶的分頁(yè)功能實(shí)現(xiàn):

要實(shí)現(xiàn)GrdView分頁(yè)的功能
操作如下:
1、更改GrdView控件的AllowPaging屬性為true。
2、更改GrdView控件的PageSize屬性為 任意數(shù)值(默認(rèn)為10)
3、更改GrdView控件的PageSetting->Mode為Numeric等(默認(rèn)為Numeric)該屬性為分頁(yè)樣式。
GridView屬性設(shè)置好了,從頁(yè)面上也能看到分頁(yè)樣式。

現(xiàn)在開(kāi)始實(shí)現(xiàn)分頁(yè)的功能:

1、在<<asp:GridView ID=......>后添加,OnPageIndexChanging="GridView1_PageIndexChanging"
2、在對(duì)應(yīng)的aspx.cs中添加:
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        InitPage(); //重新綁定GridView數(shù)據(jù)的函數(shù)
    }
3、
GridView1.PageIndex = e.NewPageIndex;
完了之后再重新綁定一下GridView。

GridView添加CheckBox列實(shí)現(xiàn)全選/全部取消功能

首先GridView編輯模版,在模板上添加CheckBox控件,之后將新添加列字段轉(zhuǎn)換為TemplateFiled



后臺(tái)代碼:

復(fù)制代碼 代碼如下:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class Default5 : System.Web.UI.Page
{
    SqlConnection sqlcon;
    string strCon = "Data Source=(local);Database=北風(fēng)貿(mào)易;Uid=sa;Pwd=sa";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bind();
        }
    }
    protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
    {
        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
            if (CheckBox2.Checked == true)
            {
                cbox.Checked = true;
            }
            else
            {
                cbox.Checked = false;
            }
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        sqlcon = new SqlConnection(strCon);
        SqlCommand sqlcom;
        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
            if (cbox.Checked == true)
            {

                string sqlstr = "delete from 飛狐工作室 where 身份證號(hào)碼='" + GridView1.DataKeys[i].Value + "'";
                sqlcom = new SqlCommand(sqlstr, sqlcon);
                sqlcon.Open();
                sqlcom.ExecuteNonQuery();
                sqlcon.Close();
            }
        }
        bind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        CheckBox2.Checked = false;
        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
            cbox.Checked = false;
        }
    }
    public void bind()
    {
        string sqlstr = "select top 5 * from 飛狐工作室";
        sqlcon = new SqlConnection(strCon);
        SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
        DataSet myds = new DataSet();
        sqlcon.Open();
        myda.Fill(myds, "tb_Member");
        GridView1.DataSource = myds;
        GridView1.DataKeyNames = new string[] { "身份證號(hào)碼" };
        GridView1.DataBind();
        sqlcon.Close();
    }
}


前臺(tái)主要代碼:
復(fù)制代碼 代碼如下:

<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
                        CellPadding="3" Font-Size="9pt" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px">
                        <FooterStyle BackColor="White" ForeColor="#000066" />
                        <Columns>
                             <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:CheckBox ID="CheckBox1" runat="server" />
                                </ItemTemplate>
                            </asp:TemplateField>
                             <asp:BoundField DataField="身份證號(hào)碼" HeaderText="用戶ID" SortExpression="身份證號(hào)碼" />
                            <asp:BoundField DataField="姓名" HeaderText="用戶姓名" SortExpression="姓名"/>

                            <asp:BoundField DataField="家庭住址" HeaderText="家庭住址" SortExpression="家庭住址"/>

                        </Columns>
                        <RowStyle ForeColor="#000066" />
                        <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
                        <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
                    </asp:GridView>
                     <asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="True" Font-Size="9pt" OnCheckedChanged="CheckBox2_CheckedChanged"
                        Text="全選" />
                    <asp:Button ID="Button1" runat="server" Font-Size="9pt" Text="取消" onClick="Button1_Click" />
                    <asp:Button ID="Button2" runat="server" Font-Size="9pt" Text="刪除" onClick="Button2_Click" />

相關(guān)文章

最新評(píng)論