我现在从数据库中查询一些数据绑定到gridview中,具体代码如下
public void BindZhishiku()
{
DataSet ds2 = new DataSet();
DataTable dt = new DataTable();
dt.TableName = "zhishiku";
dt.Columns.Add("gzxxname");
dt.Columns.Add("wxjiejueshuomin");
ds2.Tables.Add(dt);
DataRow dr;
DataSet ds = new DataSet();
ds = gz.GetAllgzxxname();
string str = "";
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
DataSet ds1 = new DataSet();
gugxx.Gzxxname = ds.Tables[0].Rows[i]["gzxxname"].ToString();
ds1 = gz.GetZhishikuByGzxxname(gugxx);
for (int j = 0; j < ds1.Tables[0].Rows.Count; j++)
{
string shuoming = ds1.Tables[0].Rows[j]["wxjiejueshuomin"].ToString();
//str = ";" + str;
str = str + shuoming + ";";
j++;
}
dr = ds2.Tables[0].NewRow();
dr["gzxxname"] = gugxx.Gzxxname;
dr["wxjiejueshuomin"] = str;
ds2.Tables[0].Rows.Add(dr);
}
GridView2.DataSource = ds2.Tables[0].DefaultView;
GridView2.DataBind();
}
在load事件中调用的,我现在想得到gridview的行数,我这样写的,int count = GridView2.Rows.Count; 为什么得到的值是1,可是绑定的值并不只一行,有使几页,这是怎么回事?
public void BindZhishiku()
{
DataSet ds2 = new DataSet();
DataTable dt = new DataTable();
dt.TableName = "zhishiku";
dt.Columns.Add("gzxxname");
dt.Columns.Add("wxjiejueshuomin");
ds2.Tables.Add(dt);
DataRow dr;
DataSet ds = new DataSet();
ds = gz.GetAllgzxxname();
string str = "";
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
DataSet ds1 = new DataSet();
gugxx.Gzxxname = ds.Tables[0].Rows[i]["gzxxname"].ToString();
ds1 = gz.GetZhishikuByGzxxname(gugxx);
for (int j = 0; j < ds1.Tables[0].Rows.Count; j++)
{
string shuoming = ds1.Tables[0].Rows[j]["wxjiejueshuomin"].ToString();
//str = ";" + str;
str = str + shuoming + ";";
j++;
}
dr = ds2.Tables[0].NewRow();
dr["gzxxname"] = gugxx.Gzxxname;
dr["wxjiejueshuomin"] = str;
ds2.Tables[0].Rows.Add(dr);
}
GridView2.DataSource = ds2.Tables[0].DefaultView;
GridView2.DataBind();
}
在load事件中调用的,我现在想得到gridview的行数,我这样写的,int count = GridView2.Rows.Count; 为什么得到的值是1,可是绑定的值并不只一行,有使几页,这是怎么回事?
解决方案 »
- 散分200,对当前.net网站中常用邮件组件做个统计,回帖就有分。
- 怎么使IE窗口右上角的关闭按钮给屏蔽掉?
- Window 2003构建 4.0环境.
- 用js变量给embed标签的src赋值的问题
- winform打印
- 现代程序员的几个错误观点
- SQLserver2005 Express不允许远程连接?
- asp.net的高手们请教:在asp.net中可不可以操作临时表?比喻在一个网页中一直都是在对临时表进行新增,修改,删除操作
- vs2008中,在同一个解决方案下,我有几个类工程,为什么我转到定义时他转到了临时目录下,而不是我我的类原文?
- 关于datagrid的编辑,删除的问题?
- Login控件问题
- 关于找回密码,我给用户邮箱发送一个修改密码的连接,请问这个连接的有效期如何控制
GridView2.DataBind(); 后面
我这样写的:
GridView2.DataSource = ds2.Tables[0].DefaultView;
GridView2.DataBind();
int count = GridView2.Rows.Count;
我绑定写一个方法内,在load中调用的这个方法
PagedDataSource PDS = new PagedDataSource();
它可以让你得到 gridview 每页的项目数,页数,等等属性
int count = result.Tables[0].Rows.Count; (資料總筆數)而如果是要由 GridView 取得,並且確定資料是由 SqlDataSource 來,請用:DataView view = GridView.DataSource as DataView;int count = view.Table.Rows.Count; (資料總筆數)
Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Charset = "UTF-8";
Response.ContentType = "application/ms-excel";
Response.ContentEncoding = System.Text.Encoding.UTF7; System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); GridView2.AllowPaging = false;//导出前先取消分页,以便能将所有数据导出。 GridView2.DataBind();//再重新绑定一次数据
int m = GridView2.Columns.Count;
for (int i = 0; i < GridView2.Rows.Count; i++)
{
GridView2.Rows[i].Cells[m - 1].Visible = false;
GridView2.Rows[i].Cells[m - 1].Enabled = false; } GridView2.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End(); GridView2.AllowPaging = true;//导出后先取消分页,以便能将所有数据导出。
GridView2.DataBind();//再重新绑定一次数据
在循环的时候得到的GridView2.Rows.Count还是等于,我在循环前就已经取消分页了啊,这是怎么回事呢
GridView2.AllowPaging = false;//导出前先取消分页,以便能将所有数据导出。
在load页面已经加载了,你还写这条语句有啥意思?
这个至少要写在生存周期中靠前的地方吧
pre_render事件里设置吧。