注册 登录
编程论坛 ASP.NET技术论坛

[求助]DataGrid用如下方法绑定后分页发生错误

zhzh 发布于 2007-06-29 19:55, 761 次点击

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();
}

2 回复
#2
zhzh2007-06-29 19:58

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

#3
zhzh2007-06-29 23:06
版主救命啊
1