一个DataGrid的小问题(在线) 将查询条件传送到一个DataGrid显示页面后,需要将DataGrid重新绑定一次。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 当查询条件改变后,(dataset要更新)将DataGrid重新绑定一次 sub page_load() if not ispostback then '数据绑定 end ifend sub page_load() if not ispostback then '数据绑定 end ifend当查询条件改变后,将DataGrid重新绑定。 DataSet thisDs=new DataSet();SqlDataAdapter thisAda=new SqlDataAdapter("select .........",conn);//conn为已打开的连接thisAda.Fill(ds);DataGrid1.DataSource=ds;DataGrid1.DataBind();conn.close(); 当查询条件改变后,(dataset要更新)将DataGrid重新绑定一次 DataGrid改变数据源,比如删除、翻页等等后都要重新绑定 在Asp.net的内部机制里JavaScript的脚本会影响到整个web的运行机制.如果内部脚本发生的错乱,就会出现很多很奇怪的情况 代码如下:private void Page_Load(object sender, System.EventArgs e){ Sql_Str = (string)Session[Session.SessionID+"Sql_Str"]; if(!Page.IsPostBack) { BindGrid(); }}private void BindGrid(){ DataSet daDetail=new DataSet(); SqlConnection sqlConn=new SqlConnection(ConfigurationSettings.AppSettings[0]); SqlDataAdapter sqlDA=new SqlDataAdapter(Sql_Str,sqlConn); sqlConn.Open(); sqlDA.Fill(daDetail,"wh_detail"); sqlConn.Close(); DataGrid1.DataSource=daDetail; DataGrid1.DataBind(); Num_TB.Text=daDetail.Tables["wh_detail"].Rows.Count.ToString().Trim(); sqlDA.Dispose(); sqlConn.Dispose(); daDetail.Dispose();} private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e){ DataGrid1.CurrentPageIndex=e.NewPageIndex; BindGrid(); } Sql_Str 不是全局变量当然在DataGrid1_PageIndexChanged中绑定时就查不到内容了 你从什么地方看出Sql_Str 不是全局变量呢??? 取得Session对象里Sql_Str查询字符串。 不要将绑定事件放在Load中,将绑定事件放在执行页面的最后一个事件Page_Pre中。 这样试试BindGrid();放外面,但这样做不太合理private void Page_Load(object sender, System.EventArgs e){ Sql_Str = (string)Session[Session.SessionID+"Sql_Str"]; BindGrid(); } 在BindGrid()里用Response.Write看看sql语句把。 日期函数问题 这里有谁是百度联盟用户吗?有的话请加我QQ,大家一起交流心得,赚大钱! 关于DataGrid更新的问题 100分吐血求网络行政办公系统中文头处理部分的资料,分不够再加!!! 求助,使用WebClient的UploadFile上传的文件如何去掉多余的内容? 如何把数据库取出的时间类型格式化为要的形式? 有没有高手呀!!!紧急求助!!! 在线等待问题? 请教专家如何解决使用Crystal Report空引用的问题 用my97DatePicker的问题 怎样删除有回复但是回复没有任何意义的贴子? 思归大侠救命!浏览器停止响应!
'数据绑定
end ifend
'数据绑定
end ifend当查询条件改变后,将DataGrid重新绑定。
SqlDataAdapter thisAda=new SqlDataAdapter("select .........",conn);//conn为已打开的连接
thisAda.Fill(ds);
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
conn.close();
重新绑定
部脚本发生的错乱,就会出现很多很奇怪的情况
private void Page_Load(object sender, System.EventArgs e)
{
Sql_Str = (string)Session[Session.SessionID+"Sql_Str"];
if(!Page.IsPostBack)
{
BindGrid();
}
}private void BindGrid()
{
DataSet daDetail=new DataSet();
SqlConnection sqlConn=new SqlConnection(ConfigurationSettings.AppSettings[0]);
SqlDataAdapter sqlDA=new SqlDataAdapter(Sql_Str,sqlConn);
sqlConn.Open();
sqlDA.Fill(daDetail,"wh_detail");
sqlConn.Close();
DataGrid1.DataSource=daDetail;
DataGrid1.DataBind();
Num_TB.Text=daDetail.Tables["wh_detail"].Rows.Count.ToString().Trim();
sqlDA.Dispose();
sqlConn.Dispose();
daDetail.Dispose();
}
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex=e.NewPageIndex;
BindGrid();
}
BindGrid();放外面,但这样做不太合理
private void Page_Load(object sender, System.EventArgs e)
{
Sql_Str = (string)Session[Session.SessionID+"Sql_Str"];
BindGrid();
}
里用Response.Write看看sql语句把。