我做的是查询功能,查询条件在一个panel1中,查询结果在panel2中,查询出的结果是用aspnetpager的URL分页。加载查询页面的时候,panel1显示出查询条件,panel2不显示,点击查询条件中的开始查询的时候panel1不显示,显示出panel2中的查询结果。我出现的错误是在没有把aspnetpager的UrlPaging设置成False时候能够正常显示panel1中的查询条件的,也能查询出结果。
我用了aspnetpager的UrlPaging设置成True时候,得到结果是直接显示查询记录,也就是panel2中的查询结果显示出来了,而panel1没有显示,而没有按照我们的要求先显示panel1中的查询条件。
我用了aspnetpager的UrlPaging设置成True时候,得到结果是直接显示查询记录,也就是panel2中的查询结果显示出来了,而panel1没有显示,而没有按照我们的要求先显示panel1中的查询条件。
解决方案 »
- 关于双引号被转成"
- 怎样固定gridview的前几列
- 服务器控件TextBox里的值改变后取出时又被改成原来的值
- 如何实现QZONE的某些功能.
- 确认对话框带参数的问题
- oracle,文章表,文章内容字段为clob,但是为什么添加文章内容时候,字数超过1,2千,就报错
- ???????紧急求助????不能更新数据库
- 请问如何做asp.net 2.0 的多语言?对OnClientClick="return confirm('您確定了嗎?');" 这样的嵌入文本,应该怎样做啊?难道只能用后台的数组?
- 怎么设置session值的超时时间呢?
- 请问CSDN上的短信息怎么做?
- >>>高手请进>>>多表(数据)复制问题:两个有关系的表,如何复制?
- 如何在扩展GridView控件中实现绑定数据和排序
{
if(!this.IsPostBack)
{
this.BindToPage();
}
this.TotalRecordset();
// 在此处放置用户代码以初始化页面
}
private void BindToPage()
{
this.djdq.Attributes.Add("onChange","proform()");
SqlConnection con = DB.createCon();
con.Open();
SqlCommand cmd = new SqlCommand("select * from setsystem where Sort=2 order by place",con);
SqlDataReader sdr = cmd.ExecuteReader();
this.tdly.DataSource=sdr; this.tdly.DataTextField="setname";
this.tdly.DataValueField="ID";
this.tdly.DataBind();
this.tdly.Items.Insert(0,new ListItem("部门选择",""));
sdr.Close();
}
private void Button1_Click(object sender, System.EventArgs e)
{ this.TotalRecordset();
this.BindToDataGrid();
}
private void TotalRecordset()
{
SqlConnection con = DB.createCon();
con.Open(); string StrSql="select count(upteam.ID) from upteam,team,line where team.ID=upteam.djtd and line.ID=upteam.xlmc ";
if(this.tdly.SelectedItem!=null && this.tdly.SelectedValue.ToString()!="")
{
StrSql=StrSql+" and upteam.tdly='"+this.tdly.SelectedValue.ToString()+"'";
}
if(this.xlmc.SelectedItem!=null && this.xlmc.SelectedValue.ToString()!="")
{
StrSql=StrSql+" and upteam.xlmc='"+this.xlmc.SelectedValue.ToString()+"'";
} SqlCommand cmd = new SqlCommand(StrSql,con);
//必须判断总计有多少条数
this.AspNetPager1.RecordCount=(int)cmd.ExecuteScalar();
}
private void BindToDataGrid()
{
this.Panel1.Visible=false;
this.Panel2.Visible=true;
this.DataGrid1.Visible=true;
this.AspNetPager1.Visible=true;
SqlConnection con = DB.createCon();
SqlDataAdapter sda = new SqlDataAdapter();
string StrSql="select team.teamname,line.linename,upteam.ID,upteam.course_code,upteam.crs,upteam.ets,upteam.pts from upteam,team,line where team.ID=upteam.djtd and line.ID=upteam.xlmc ";
if(this.tdly.SelectedItem!=null && this.tdly.SelectedValue.ToString()!="")
{
StrSql=StrSql+" and upteam.tdly='"+this.tdly.SelectedValue.ToString()+"'";
}
if(this.xlmc.SelectedItem!=null && this.xlmc.SelectedValue.ToString()!="")
{
StrSql=StrSql+" and upteam.xlmc='"+this.xlmc.SelectedValue.ToString()+"'";
} StrSql=StrSql+" order by upteam.st_time desc,upteam.tdly"; sda.SelectCommand=new SqlCommand(StrSql,con);
DataSet ds = new DataSet(); //这一部分必须加上的,重新填充数据
sda.Fill(ds,this.AspNetPager1.PageSize*(this.AspNetPager1.CurrentPageIndex-1),this.AspNetPager1.PageSize,"upteam"); this.DataGrid1.DataKeyField="ID";
this.DataGrid1.DataSource=ds.Tables["upteam"];
this.DataGrid1.DataBind();
} //这部分必须加上,事件相应
protected void AspNetPager1_PageChanged(object src,EventArgs e)
{
this.BindToDataGrid();
}
不是使用DoPostBack方式的提交
那么
if(!this.IsPostBack)
{
this.BindToPage();
}
这里的ViewState不存在
修改取消IsPostBack的判断
直接
this.BindToPage();