标题:[求助]DataGrid用如下方法绑定后分页发生错误
只看楼主
zhzh
Rank: 2
等 级:新手上路
威 望:3
帖 子:377
专家分:0
注 册:2006-10-18
 问题点数:0 回复次数:2 
[求助]DataGrid用如下方法绑定后分页发生错误

DataGrid里面有一个模版列,里面放置一个HyperLink1控件,再根据数据库中的Other_load是否为空判断是否显示该行的HyperLink1控件,下面的方法是实现了,但是分页的时候出现错误说超出索引index等等

private void Binder()
{
SqlConnection con=new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
con.Open();
string sel="select * from jz_Other where Other_id=1 order by Other_id DESC";
SqlDataAdapter da=new SqlDataAdapter(sel,con);
DataSet ds=new DataSet();
da.Fill(ds,"dg");

this.DG_Other.DataKeyField="Other_id";

this.DG_Other.DataSource=ds.Tables["dg"];
this.DG_Other.DataBind();
for(int i=0;i<ds.Tables["dg"].Rows.Count;i++)
{
if(ds.Tables["dg"].Rows[i]["Other_load"].ToString()=="")
{
DataGridItem dgit=DG_Other.Items[(int)i];//
HyperLink h=(HyperLink)dgit.FindControl("HyperLink1");
h.Visible=false;
}
}
con.Close();
}

分页代码如下:
private void dg_cpltjl_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.DG_Other.CurrentPageIndex=e.NewPageIndex;
Binder();
}

搜索更多相关主题的帖子: DataGrid 绑定 数据库 Other con 
2007-06-29 19:55
zhzh
Rank: 2
等 级:新手上路
威 望:3
帖 子:377
专家分:0
注 册:2006-10-18
得分:0 

一般根据数据库中的某个字段是否为空,然后DG里面特定列中某行的一个控件是否显示有没有别的方法实现啊!??
求教.....
跪谢谢了


Tomorrow is another day! my love..................
2007-06-29 19:58
zhzh
Rank: 2
等 级:新手上路
威 望:3
帖 子:377
专家分:0
注 册:2006-10-18
得分:0 
版主救命啊

Tomorrow is another day! my love..................
2007-06-29 23:06



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-151439-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.130337 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved