2013-08-18
展开全部
DataGridView 本身就具有分页 可以直接使用的 也可以不用那个分页 那就自己写个 用DataGridView的DataSource来绑定一个DataTable ,DataTable 主要是查询某个区间的数据,主要有几个参数 1 RowCount 一次返回多少行 PageSize一页几个, CurragePage第几页 通过SQl语句 Select top RowCount * from tableName Where Id not in(Select top (CurragePage-1)*PageSize Id form tableName) and 查询条件 大致就这样了 细节地方多注意就是 不懂可以找我 我基本每天都在线的
推荐于2016-08-20
展开全部
private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“myDBDataSet.login”中。您可以根据需要移动或移除它。
this.loginTableAdapter.Fill(this.myDBDataSet.login);//自动添加数据时自动生成的
int intMod, dgr;
dataGridView2.ScrollBars = System.Windows.Forms.ScrollBars.None;//先让垂直滚动条消失 dgr = dataGridView2.RowCount-1;//取出DGV的行数,为什么要减一是因为它总是多出一行给你编辑的所以那行也占用一行的空间 if (dgr % 10 == 0) //进行取模 { intMod = 0; }
else
{
intMod = 1;
} for (int i = 1; i <= dgr / 10+intMod; i++) //主要时这个for循环将表一共分为几页添加到comboBox
{
comboBox2.Items.Add("第" + i + "页"); }
comboBox2.SelectedIndex = 0; //默认选中第一个 }然后在comboBox1_SelectedValueChanged事件里面添加下面代码private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
{
dataGridView2.FirstDisplayedScrollingRowIndex = comboBox2.SelectedIndex * 10;
}
{
// TODO: 这行代码将数据加载到表“myDBDataSet.login”中。您可以根据需要移动或移除它。
this.loginTableAdapter.Fill(this.myDBDataSet.login);//自动添加数据时自动生成的
int intMod, dgr;
dataGridView2.ScrollBars = System.Windows.Forms.ScrollBars.None;//先让垂直滚动条消失 dgr = dataGridView2.RowCount-1;//取出DGV的行数,为什么要减一是因为它总是多出一行给你编辑的所以那行也占用一行的空间 if (dgr % 10 == 0) //进行取模 { intMod = 0; }
else
{
intMod = 1;
} for (int i = 1; i <= dgr / 10+intMod; i++) //主要时这个for循环将表一共分为几页添加到comboBox
{
comboBox2.Items.Add("第" + i + "页"); }
comboBox2.SelectedIndex = 0; //默认选中第一个 }然后在comboBox1_SelectedValueChanged事件里面添加下面代码private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
{
dataGridView2.FirstDisplayedScrollingRowIndex = comboBox2.SelectedIndex * 10;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-08-18
展开全部
刚做好的 html代码: <html xmlns=" http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>部门信息选择</title>
<link href="Image/Main.css" rel="stylesheet" type="text/css" />
<%-- //屏蔽右键菜单
--%> <script type="text/javascript"> </script>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align: left">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px"
CellPadding="2" GridLines="None" OnPageIndexChanging="GridView1_PageIndexChanging"
OnRowCommand="GridView1_RowCommand" PageSize="5" ForeColor="Black">
<FooterStyle BackColor="Tan" />
<Columns>
<asp:BoundField DataField="SuppliersID" HeaderText="供应商编号" InsertVisible="False"
ReadOnly="True" SortExpression="DepartmentID" />
<asp:ButtonField ButtonType="Image" CommandName="select" HeaderText="请选择" ImageUrl="~/Image/option.gif"
Text="选择" />
</Columns>
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
HorizontalAlign="Center" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<AlternatingRowStyle BackColor="PaleGoldenrod" />
</asp:GridView>
<asp:Label ID="Label1" runat="server"></asp:Label>
<input id="hiddenfm" runat="server" type="hidden" /></div>
</form>
</body>
</html>
C#代码: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 SqlHelper;
public partial class SuppliersIDSelect : System.Web.UI.Page
{
Helper he = new Helper();//这是链接数据库的代码,见后面 static int i = 1;//页数 protected void Page_Load(object sender, EventArgs e)
{
GridView1.DataSource = he.BindSuppliersInfo();
if (!IsPostBack)
{
this.hiddenfm.Value = (string)Request["name"]; Label1.Text = "当前页码是" + Convert.ToString(GridView1.PageIndex + i); GridView1.DataBind();
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex; Label1.Text = "当前页码是" + Convert.ToString(GridView1.PageIndex + i); GridView1.DataBind();
}
} Help.cs代码:public DataSet BindSuppliersInfo()
{
String sql = "select * from Suppliers"; SqlDataAdapter da = new SqlDataAdapter(sql, conn); conn.Open(); ds = new DataSet(); da.Fill(ds); conn.Close(); return ds;
}
<head id="Head1" runat="server">
<title>部门信息选择</title>
<link href="Image/Main.css" rel="stylesheet" type="text/css" />
<%-- //屏蔽右键菜单
--%> <script type="text/javascript"> </script>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align: left">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px"
CellPadding="2" GridLines="None" OnPageIndexChanging="GridView1_PageIndexChanging"
OnRowCommand="GridView1_RowCommand" PageSize="5" ForeColor="Black">
<FooterStyle BackColor="Tan" />
<Columns>
<asp:BoundField DataField="SuppliersID" HeaderText="供应商编号" InsertVisible="False"
ReadOnly="True" SortExpression="DepartmentID" />
<asp:ButtonField ButtonType="Image" CommandName="select" HeaderText="请选择" ImageUrl="~/Image/option.gif"
Text="选择" />
</Columns>
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
HorizontalAlign="Center" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<AlternatingRowStyle BackColor="PaleGoldenrod" />
</asp:GridView>
<asp:Label ID="Label1" runat="server"></asp:Label>
<input id="hiddenfm" runat="server" type="hidden" /></div>
</form>
</body>
</html>
C#代码: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 SqlHelper;
public partial class SuppliersIDSelect : System.Web.UI.Page
{
Helper he = new Helper();//这是链接数据库的代码,见后面 static int i = 1;//页数 protected void Page_Load(object sender, EventArgs e)
{
GridView1.DataSource = he.BindSuppliersInfo();
if (!IsPostBack)
{
this.hiddenfm.Value = (string)Request["name"]; Label1.Text = "当前页码是" + Convert.ToString(GridView1.PageIndex + i); GridView1.DataBind();
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex; Label1.Text = "当前页码是" + Convert.ToString(GridView1.PageIndex + i); GridView1.DataBind();
}
} Help.cs代码:public DataSet BindSuppliersInfo()
{
String sql = "select * from Suppliers"; SqlDataAdapter da = new SqlDataAdapter(sql, conn); conn.Open(); ds = new DataSet(); da.Fill(ds); conn.Close(); return ds;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询