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