<asp:datagrid....>
<PagerStyle NextPageText="下一页" PrevPageText="上一页"></PagerStyle>
</asp:datagrid>
<PagerStyle NextPageText="下一页" PrevPageText="上一页"></PagerStyle>
</asp:datagrid>
解决方案 »
- 如何终止一个线程。thread1.Name="a1".
- 如何取字符串的其中一个?
- asp.net的问题,谢谢各位高手
- 关于Response.Write("<script>window.alert('密码不正确!')的问题!~!~!
- 新人第一贴:在vb.net中datagrid控件无法正常显示,请各位大师帮帮忙阿.多谢多谢~~
- 有关Pop3邮件接收后如何解码、附件和邮件主体在一起,如何取出,不同文件类型如何处理。
- 如何将一个DataSet转换成数组?
- ASP.NET中的WEB控件可不可以调用客户端脚本啊
- 关于datagrid的宽度问题?(来者有分)
- 能否给自定义控件传值啊,同一个控件根据不同参数显示不同的数据
- 关于用 Virtual PC 模拟网络开发环境!请关注。。。
- 关于DataGrid的动态生成并作为一个.ascx控件后,怎么样把事件暴露在引用此控件的页面?
</p>
</form>
不知道这样会不会有问题?改了再试试?
而是:AllowPaging="True"
<%@ Import Namespace="System.Data" %>
<Script Language="C#" Runat="Server">
int startIndex;
void BindGrid()
{
//定义语句 string mySelectQuery = "SELECT * from test";
string myConnString=@"server=localhost;uid=sa;pwd= ;database=test ";//联结SqlConnection myConnection = new SqlConnection(myConnString);
DataSet myDataSet = new DataSet();
SqlDataAdapter myAdapter;
try
{
myAdapter = new SqlDataAdapter(mySelectQuery, myConnection);
myAdapter.Fill(myDataSet, "test");
}
catch(Exception ex)
{
return;
}
show.DataSource=myDataSet.Tables["test"].DefaultView;
show.DataBind();
}
void Page_Load(Object sender,EventArgs e){
if(!IsPostBack){
startIndex=0;
}
BindGrid();
}void ChangePage(Object sender,DataGridPageChangedEventArgs e)
{
startIndex=e.NewPageIndex*show.PageSize;
show.CurrentPageIndex=e.NewPageIndex;
BindGird();
}
</Script>
<HTML>
<HEAD>
<title></title>
</HEAD>
<body>
<form runat=server>
<asp:DataGrid
AllowPaging="True"
PageSize="5"
PagerStyle-HorizontanAlign="Right"
<PagerStyle NextPageText="下一页" PrevPageText="上一页"></PagerStyle>
OnPageindexChanged="ChangePage"
HeaderStyle-BackColor="Blue"
AlternatingItemStyle--BackColor="blue"
BorderColor="Red"
BorderWidth="2"
CellPadding="10"
CellSpacing="2"
Font-Name="Verdana"
Font-Size="20pt"
id="show" runat="server"></asp:DataGrid>
</form>
</body>
</HTML>
CS0246: The type or namespace name 'show' could not be found (are you missing a using directive or an assembly reference?)Source Error: Line 27:
Line 28:
Line 29: show.DataSource=myDataSet.Tables["test"].DefaultView;
Line 30: show.DataBind();
Line 31: }
PagerStyle-NextPageText="上一页"
你写错了啦,应该是:
PagerStyle-NextPageText="下一页"
PagerStyle-prePageText="上一页"
<asp:DataGrid PageSize="5"
PagerStyle-HorizontanAlign="Right"
PagerStyle-NextPageText="下一页"
OnPageindexChanged="ChangePage"
HeaderStyle-BackColor="Blue"
AlternatingItemStyle--BackColor="blue"
BorderColor="Red"
BorderWidth="2px"
CellPadding="10"
CellSpacing="2"
Font-Name="Verdana"
Font-Size="20pt"
id="show"
runat="server" AllowPaging="True"
Font-Names="Verdana">
<HeaderStyle BackColor="Blue">
</HeaderStyle>
<PagerStyle NextPageText="下一页" PrevPageText="上一页">
</PagerStyle>
</asp:DataGrid>
运行成功了的
PagerStyle-HorizontanAlign="Right"
PagerStyle-NextPageText="下一页"
OnPageindexChanged="ChangePage"
HeaderStyle-BackColor="Blue"
AlternatingItemStyle--BackColor="blue"
BorderColor="Red"
BorderWidth="2px"
CellPadding="10"
CellSpacing="2"
Font-Name="Verdana"
Font-Size="20pt"
id="show"
runat="server" AllowPaging="True"
Font-Names="Verdana">
<HeaderStyle BackColor="Blue">
</HeaderStyle>
<PagerStyle NextPageText="下一页" PrevPageText="上一页">
</PagerStyle>
</asp:DataGrid>
修改后的错误:
An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0103: The name 'BindGird' does not exist in the class or namespace 'ASP.link3_aspx'Source Error: Line 42: startIndex=e.NewPageIndex*show.PageSize;
Line 43: show.CurrentPageIndex=e.NewPageIndex;
Line 44: BindGird();
Line 45: }
Line 46:
前台Html:
<%@ Page language="c#" Codebehind="WebForm4.aspx.cs" AutoEventWireup="false" Inherits="Test.WebForm4" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm4</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="WebForm4" method="post" runat="server">
<asp:DataGrid PageSize="5" PagerStyle-HorizontanAlign="Right" PagerStyle-NextPageText="下一页" OnPageindexChanged="ChangePage" HeaderStyle-BackColor="Blue" AlternatingItemStyle--BackColor="blue" BorderColor="Red" BorderWidth="2px" CellPadding="10" CellSpacing="2" Font-Name="Verdana" Font-Size="20pt" id="show" runat="server" AllowPaging="True" Font-Names="Verdana">
<HeaderStyle BackColor="Blue"></HeaderStyle>
<PagerStyle NextPageText="下一页" PrevPageText="上一页"></PagerStyle>
</asp:DataGrid>
</form>
</body>
</HTML>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;namespace Test
{
/// <summary>
/// WebForm4 的摘要说明。
/// </summary>
public class WebForm4 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid show;
protected int startIndex;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
startIndex=0;
}
BindGrid();
} protected void BindGrid()
{
//定义语句 string mySelectQuery = "select * from Rooms";
string myConnString=@"server=(local);database=jj;uid=sa;pwd=;";//我的数据库连接串 //联结 SqlConnection myConnection = new SqlConnection(myConnString);
myConnection.Open();//打开数据库
DataSet myDataSet = new DataSet();
SqlDataAdapter myAdapter;
// try
// {
myAdapter = new SqlDataAdapter(mySelectQuery, myConnection);
myAdapter.Fill(myDataSet, "test");
// }
//
// catch(Exception ex)
// {
// return;
// }
show.DataSource=myDataSet.Tables["test"].DefaultView;
show.DataBind();
} protected void ChangePage(Object sender,DataGridPageChangedEventArgs e)
{
startIndex=e.NewPageIndex*show.PageSize;
show.CurrentPageIndex=e.NewPageIndex;
BindGrid();
}
myConnection.Open();//打开数据库
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<%@ import Namespace="System.Collections" %>
<script runat="server"> void Page_Load(object sender, EventArgs e) {
// TODO: Update the ConnectionString and CommandText values for your application
show.VirtualItemCount=94;
show.DataSource=CreateDataSource();
show.DataBind();
}
ICollection CreateDataSource()
{
SqlConnection objConnection;
SqlDataAdapter objCommand;
string strConnect="server=(local);database=pubs;trusted_connection=true";
string strCommand="select au_lname as [Last Name], au_fname as [First Name], Address, City, State from Authors";
DataSet DataSet1=new DataSet();
objConnection=new SqlConnection(strConnect);
objCommand=new SqlDataAdapter(strCommand,objConnection);
objCommand.Fill(DataSet1,"person");
DataView dv =new DataView(DataSet1.Tables[0]);
return dv;
}
void show_PageIndexChanged(Object source, DataGridPageChangedEventArgs e)
{
show.CurrentPageIndex = e.NewPageIndex;
show.DataSource=CreateDataSource();
show.DataBind();
}</script>
<html>
<head>
</head>
<body style="FONT-FAMILY: arial">
<h2>Simple Data Report
</h2>
<hr size="1" />
<form runat="server">
<asp:DataGrid id="show" style="Z-INDEX: 101; LEFT: 15px; POSITION: absolute; TOP: 91px" runat="server" OnPageIndexChanged="show_PageIndexChanged" Height="281px" Width="689px" PageSize="5" AllowPaging="True">
<PagerStyle nextpagetext="下页" prevpagetext="上页"></PagerStyle>
<Columns>
<asp:ButtonColumn Text="<div id=de onclick="javascript:return confirm('是否删除...');">删除</div>" CommandName="Delete"></asp:ButtonColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>