新手gridview问题

yubintj 2006-11-20 04:39:54
asp新手作网页查询
代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class maintain : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (TextBox1.Text != "") return;
TextBox1.Text = DateTime.Now.ToShortDateString();
TextBox2.Text = DateTime.Now.ToShortDateString();
}
protected void Button1_Click(object sender, EventArgs e)
{
String sql;
sql = "SELECT m_id, convert(varchar,datepart(year,m_maintaindate))+'年'+right('0'+convert(varchar,datepart(month,m_maintaindate)),2)+'月'+right('0'+convert(varchar,datepart(day,m_maintaindate)),2)+'日' as maintaindate, m_department, m_line, m_linekind, m_workarea, m_workleader, m_protect, m_worknum, m_casuallaborernum, m_implement, m_implementuser, m_workplace, m_task, m_num, m_stationprotect, m_ifclearstory, m_station, m_time, m_timeunit, m_sysdatetime, m_deptid FROM t_maintain WHERE (m_ifclearstory = '0')";
if (CheckBox1.Checked)
{
sql = sql + " and m_department='" + DropDownList1 .Text + "'";
}
if (CheckBox2.Checked)
{
try
{
DateTime.Parse(TextBox1.Text);
DateTime.Parse(TextBox2.Text);
}
catch
{
// 转化
Response.Write("<script language=javascript>alert('请输入正确的日期格式!');</script>");
return;
}
sql = sql + " and m_maintaindate between '" + TextBox1.Text + " 00:00:00' and '" + TextBox2.Text + " 23:59:59'";
}
sql = sql + " order by maintaindate desc";
this.SqlDataSource.SelectCommand = sql;
this.GridView1.DataBind();
}
}

查询后gridview的第一页没有问题,但是只要一点gridview上面的分页,gridview显示的数据就又回到查询以前的数据了,请高手指教!
...全文
65 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
triffang 2006-11-20
  • 打赏
  • 举报
回复
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{

if (TextBox1.Text != "") return;
TextBox1.Text = DateTime.Now.ToShortDateString();
TextBox2.Text = DateTime.Now.ToShortDateString();
BindGrid();

}
}

private void BindGrid()
{
String sql;
sql = "SELECT m_id, convert(varchar,datepart(year,m_maintaindate))+'年'+right('0'+convert(varchar,datepart(month,m_maintaindate)),2)+'月'+right('0'+convert(varchar,datepart(day,m_maintaindate)),2)+'日' as maintaindate, m_department, m_line, m_linekind, m_workarea, m_workleader, m_protect, m_worknum, m_casuallaborernum, m_implement, m_implementuser, m_workplace, m_task, m_num, m_stationprotect, m_ifclearstory, m_station, m_time, m_timeunit, m_sysdatetime, m_deptid FROM t_maintain WHERE (m_ifclearstory = '0')";
if (CheckBox1.Checked)
{
sql = sql + " and m_department='" + DropDownList1 .Text + "'";
}
if (CheckBox2.Checked)
{
try
{
DateTime.Parse(TextBox1.Text);
DateTime.Parse(TextBox2.Text);
}
catch
{
// 转化
Response.Write("<script language=javascript>alert('请输入正确的日期格式!');</script>");
return;
}
sql = sql + " and m_maintaindate between '" + TextBox1.Text + " 00:00:00' and '" + TextBox2.Text + " 23:59:59'";
}
sql = sql + " order by maintaindate desc";
this.SqlDataSource.SelectCommand = sql;
this.GridView1.DataBind();
}

}
protected void Button1_Click(object sender, EventArgs e)
{
BindGrid();

}

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧