private void DataGridDataBind()
{
//定义数据连接对象,其中数据库连接字符串是在Web.Config文件中定义的
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionSqlServer"].ToString());
//创建数据适配器对象
SqlDataAdapter da = new SqlDataAdapter("select LastName,FirstName,BirthDate,City from Employees",conn);
//创建DataSet对象
DataSet ds = new DataSet();
try
{
//从指定的索引开始取PageSize条记录
da.Fill(ds,startIndex,dgCustomPage.PageSize,"CurDataTable");
//填充数据集
da.Fill(ds,"AllDataTable");
//设置DataGrid控件实际要显示的项数
dgCustomPage.VirtualItemCount = ds.Tables["AllDataTable"].Rows.Count;
//进行数据绑定
dgCustomPage.DataSource = ds.Tables["CurDataTable"];
dgCustomPage.DataBind();
}
catch(Exception error)
{
Response.Write(error.ToString());
}
}
下面这两句,分别做了些什么呢?:
第一句,把指定行数的记录填充到DS中?
第二句,把所有的记录填充条DS中?//1,从指定的索引开始取PageSize条记录
da.Fill(ds,startIndex,dgCustomPage.PageSize,"CurDataTable");
//2,填充数据集
da.Fill(ds,"AllDataTable");那么在我绑定的时候 DS 中究竟存了些什么呢?
我只希望每次存当前页的记录,,,没这么做过分页,,,也不晓得该怎么问哪位可以帮忙回个话。
{
//定义数据连接对象,其中数据库连接字符串是在Web.Config文件中定义的
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionSqlServer"].ToString());
//创建数据适配器对象
SqlDataAdapter da = new SqlDataAdapter("select LastName,FirstName,BirthDate,City from Employees",conn);
//创建DataSet对象
DataSet ds = new DataSet();
try
{
//从指定的索引开始取PageSize条记录
da.Fill(ds,startIndex,dgCustomPage.PageSize,"CurDataTable");
//填充数据集
da.Fill(ds,"AllDataTable");
//设置DataGrid控件实际要显示的项数
dgCustomPage.VirtualItemCount = ds.Tables["AllDataTable"].Rows.Count;
//进行数据绑定
dgCustomPage.DataSource = ds.Tables["CurDataTable"];
dgCustomPage.DataBind();
}
catch(Exception error)
{
Response.Write(error.ToString());
}
}
下面这两句,分别做了些什么呢?:
第一句,把指定行数的记录填充到DS中?
第二句,把所有的记录填充条DS中?//1,从指定的索引开始取PageSize条记录
da.Fill(ds,startIndex,dgCustomPage.PageSize,"CurDataTable");
//2,填充数据集
da.Fill(ds,"AllDataTable");那么在我绑定的时候 DS 中究竟存了些什么呢?
我只希望每次存当前页的记录,,,没这么做过分页,,,也不晓得该怎么问哪位可以帮忙回个话。
解决方案 »
- 在母版頁上用cookie設置中英文切換,內容頁如何能相應改變?
- 关于OA产品,谁给推荐个物美价廉的
- 关于DropDownList
- 怎么把CS处理好的数据送到ASPX页上?
- 在规定时间内解决这些问题,证明你很强!(参加变态笔试后)
- ASP.NET共通问题
- 在GridView1_DataBound事件中,取到的GridView1.Columns.Count值為0?
- 关于在web.config中配置了<identity>引发的怪问题!
- 在JavaScript中如何读写cookie?
- 怎么判断dataset返回为空?(c#)
- 我用AJAX每隔2秒请求一次数据 系统运行长后客户端内存消耗出现耗光问题 怎么解决有没有一种不怎么消耗资源的方法
- 关于在后台取TEXTBOX中值的问题
{
int allrowscount = 0;
try
{
if(selectCountCmd.Connection.State.Equals(ConnectionState.Closed))
{
selectCountCmd.Connection.Open();
}
allrowscount = Convert.ToInt32(selectCountCmd.ExecuteScalar()); }
catch(SqlException sqlex)
{
System.Console.WriteLine(sqlex.Message);
allrowscount = 0;
}
catch(Exception ex)
{
System.Console.WriteLine(ex.Message);
allrowscount = 0;
}
finally
{
selectCountCmd.Connection.Close();
}
return allrowscount;
} public static DataTable CurrentPageData(SqlCommand selectAllRowsCmd,int currentPageIndex,int pageSize)
{
DataSet ds = new DataSet();
try
{
if(selectAllRowsCmd.Connection.State.Equals(ConnectionState.Closed))
{
selectAllRowsCmd.Connection.Open();
}
SqlDataAdapter adapter = new SqlDataAdapter(selectAllRowsCmd);
adapter.Fill(ds,pageSize*currentPageIndex,pageSize,"CurrentPageData");
}
catch(Exception ex)
{
System.Console.WriteLine(ex.Message);
}
finally
{
selectAllRowsCmd.Connection.Close();
}
int i = ds.Tables["CurrentPageData"].Rows.Count;
return ds.Tables["CurrentPageData"];
} public int AllUserCount()
{
int allUserCount = 0;
SqlConnection conn = DbConn.CreateSqlConn();
SqlCommand cmd = new SqlCommand("select count(*) from users",conn);
allUserCount = Pagination.AllRowsCount(cmd);
return allUserCount;
} public DataTable UserCurrentPageData(int currentPageIndex,int pageSize)
{
DataTable dt = null;
SqlConnection conn = DbConn.CreateSqlConn();
SqlCommand cmd = new SqlCommand("select * from users",conn);
dt = Pagination.CurrentPageData(cmd,currentPageIndex,pageSize);
return dt;
}