我做的是查询功能,查询条件在一个panel1中,查询结果在panel2中,查询出的结果是用aspnetpager的URL分页。加载查询页面的时候,panel1显示出查询条件,panel2不显示,点击查询条件中的开始查询的时候panel1不显示,显示出panel2中的查询结果。我出现的错误是在没有用aspnetpager的时候能够正常显示panel1中的查询条件的,也能查询出结果,但我用了aspnetpager的时候,直接得到结果是直接显示查询结果,也就是panel2中的查询结果显示出来了,而panel1没有显示,而没有按照我们的要求先显示panel1中的查询条件。下面是我的代码大家帮我看看问题出在什么地方
private void Page_Load(object sender, System.EventArgs e)
{
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();
cmd.CommandText="select * from line order by adddate desc";
SqlDataReader sdr2 = cmd.ExecuteReader();
this.xlmc.DataSource=sdr2;
this.xlmc.DataTextField="linename";
this.xlmc.DataValueField="ID";
this.xlmc.DataBind();
this.xlmc.Items.Insert(0,new ListItem("线路名称",""));
sdr2.Close();
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion 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();
}
private void Page_Load(object sender, System.EventArgs e)
{
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();
cmd.CommandText="select * from line order by adddate desc";
SqlDataReader sdr2 = cmd.ExecuteReader();
this.xlmc.DataSource=sdr2;
this.xlmc.DataTextField="linename";
this.xlmc.DataValueField="ID";
this.xlmc.DataBind();
this.xlmc.Items.Insert(0,new ListItem("线路名称",""));
sdr2.Close();
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion 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();
}
<form id="Form1" method="post" runat="server">
<asp:panel id="Panel1" runat="server">
<TABLE id="Table1" cellSpacing="1" cellPadding="5" width="600" align="center" bgColor="#ffffff"
border="0">
<TR bgColor="#f2fddf">
<TD colSpan="2"><IMG height="12" src="images/star1.gif" width="12"> 综合信息</TD>
</TR>
<TR>
<TD align="right" width="80">团队来源:</TD>
<TD>
<asp:DropDownList id="tdly" style="FONT-SIZE: 12px; FONT-FAMILY: Tahoma, 新宋体, sans-serif" runat="server"
Width="120"></asp:DropDownList></TD>
</TR>
<TR>
<TD align="right" width="80">团队编号:</TD>
<TD>
<asp:TextBox id="course_code" runat="server"></asp:TextBox></TD>
</TR>
<TR>
<TD align="right" width="80">启程时间:</TD>
<TD>
<asp:textbox id="st_time" runat="server"></asp:textbox> <A onclick="event.cancelBubble=true;" href="javascript:ShowCalendar(document.Form1.currentdate,document.Form1.st_time,null,0,330)"><IMG id="currentdate" height="21" src="rl/calendar.gif" width="34" align="absMiddle"
border="0"> <A onclick="event.cancelBubble=true;" href="javascript:ShowCalendar(document.form1.currentdate,document.form1.st_time,null,0,330)">
</A>
</TD>
</TR>
<TR>
<TD align="right" width="80"> </TD>
<TD>
<asp:textbox id="unpaied_time" runat="server"></asp:textbox> <A onclick="event.cancelBubble=true;" href="javascript:ShowCalendar(document.Form1.currentdate1,document.Form1.unpaied_time,null,0,330)"><IMG id="currentdate1" height="21" src="rl/calendar.gif" width="34" align="absMiddle"
border="0"></A>
</TD>
</TR>
<TR>
<TD align="right" width="80">地接地区:</TD>
<TD>
<asp:DropDownList id="djdq" style="FONT-SIZE: 12px; FONT-FAMILY: Tahoma, 新宋体, sans-serif" runat="server"
Width="120"></asp:DropDownList></TD>
</TR>
<TR>
<TD align="right" width="80">地接团队:</TD>
<TD>
<asp:DropDownList id="djtd" style="FONT-SIZE: 12px; FONT-FAMILY: Tahoma, 新宋体, sans-serif" runat="server"
Width="120"></asp:DropDownList></TD>
</TR>
<TR>
<TD align="right" width="80">线路名称:</TD>
<TD>
<asp:DropDownList id="xlmc" style="FONT-SIZE: 12px; FONT-FAMILY: Tahoma, 新宋体, sans-serif" runat="server"
Width="360"></asp:DropDownList></TD>
</TR>
<TR>
<TD align="right" width="80">显示条件:</TD>
<TD>
<TABLE id="Table2" cellSpacing="1" cellPadding="3" width="100%" border="0">
<TR>
<TD> 团队编号</TD>
<TD> 组团社名称</TD>
<TD> 导游
</TD>
<TD> 成人
</TD>
<TD> 儿童</TD>
</TR>
<TR>
<TD> 陪同</TD>
<TD> 旅游线路</TD>
<TD> 团队来源</TD>
<TD> 地接地区</TD>
<TD> </TD>
</TR>
</TABLE>
</TD>
</TR>
<TR bgColor="#f2fddf">
<TD align="center" colSpan="2">
<asp:Button id="Button1" runat="server" Text="搜索信息"></asp:Button>
<asp:Button id="Button2" runat="server" Text="取消信息"></asp:Button></TD>
</TR>
</TABLE>
</asp:panel><asp:panel id="Panel2" runat="server" Visible="False">
<TABLE id="Table3" cellSpacing="5" cellPadding="5" width="300" border="0">
<TR>
<TD>
<asp:DataGrid id="DataGrid1" runat="server" Width="650px" Visible="False" PageSize="20" AutoGenerateColumns="False"
CellPadding="4" BackColor="White" BorderWidth="1px" BorderStyle="None" BorderColor="#EFEEF0">
<SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle ForeColor="Black" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="Black" BackColor="#F2FDDF"></HeaderStyle>
<FooterStyle ForeColor="Black" BackColor="#F2FDDF"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="ID" HeaderText="序号"></asp:BoundColumn>
<asp:BoundColumn DataField="course_code" HeaderText="编号"></asp:BoundColumn>
<asp:BoundColumn DataField="teamname" HeaderText="团队名称"></asp:BoundColumn>
<asp:BoundColumn DataField="linename" HeaderText="线路名称"></asp:BoundColumn>
<asp:BoundColumn DataField="crs" HeaderText="成人"></asp:BoundColumn>
<asp:BoundColumn DataField="ets" HeaderText="儿童"></asp:BoundColumn>
<asp:BoundColumn DataField="pts" HeaderText="陪同"></asp:BoundColumn>
<asp:BoundColumn DataField="ID" HeaderText="导游"></asp:BoundColumn>
</Columns>
<PagerStyle NextPageText="下一页" PrevPageText="上一页" HorizontalAlign="Center" ForeColor="Black"
BackColor="#F2FDDF"></PagerStyle>
</asp:DataGrid>
<webdiyer:AspNetPager id="AspNetPager1" runat="server" Visible="True" PageSize="20" UrlPageIndexName="pageindex"
OnPageChanged="AspNetPager1_PageChanged" HorizontalAlign="Right" ShowInputBox="Always" SubmitButtonText="转页"
NumericButtonTextFormatString="[{0}]" UrlPaging="True"></webdiyer:AspNetPager></TD>
</TR>
</TABLE>
</asp:panel></form>
this.Panel2.Visible=true;
如果把他设置成true正常显示
到底什么原因