验证中...
Languages: ASP
Categories: Web开发技术
Latest update 2018-12-25 09:40
在GridView Web服务器控件中分页——后台
Raw Copy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace Listbox
{
public partial class WebForm3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private DataView dv;
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
this.GridView1.PagerSettings.Mode = PagerButtons.Numeric;
this.GridView1.DataSource = dv;
this.GridView1.DataBind();
}
protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
this.GridView1.PagerSettings.Mode = PagerButtons.NextPrevious;
this.GridView1.DataSource = dv;
this.GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
this.GridView1.DataSource = dv;
this.GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
string sqlUrl = @"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\asp.net\数据库文件\supermarket数据库文件\SuperMarket.mdf;Integrated Security=True;User Instance=True";
SqlConnection conn = new SqlConnection(sqlUrl);
conn.Open();
SqlCommand comm = new SqlCommand("SELECT * FROM Product", conn);
SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = comm;
DataSet ds = new DataSet();
adp.Fill(ds);
dv = ds.Tables[0].DefaultView;
conn.Close();
RadioButton1.Checked = true;
this.GridView1.DataSource = dv;
this.GridView1.DataBind();
}
}
}
在GridView Web服务器控件中分页——前台
Raw Copy
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="Mode"
oncheckedchanged="RadioButton1_CheckedChanged" Text="Numeric" />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="Mode"
oncheckedchanged="RadioButton2_CheckedChanged" Text="NextPrevious" />
<br />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" PageSize="5"
onpageindexchanging="GridView1_PageIndexChanging">
<PagerSettings NextPageText="下一页" PreviousPageText="上一页" />
<PagerStyle HorizontalAlign="Right" />
</asp:GridView>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="显示" />
</div>
</form>
</body>

Comment list( 0 )

You need to Sign in for post a comment

Help Search

Gitee_sixth 5th_float_left_close