gridview搜索后分页的问题,请大家帮帮忙,不要那种判定文本框是否的方法,谢谢大家!
解决方案 »
- SOCKET编程UDP和UdpClient有什么区别?
- SerialPort关闭卡死
- c#调用c++的dll
- 自定义光标的图像问题
- 如何形成新的表? 超难,真烦!!!
- 本命年已经发生了一件很不爽的事情
- C#调用VC编写的COM组件中的全局函数,怎么把C#自定义的结构体作为函数的参数传递?
- ORA-00942: table or view does not exist
- 怎么保存DataGridView(显示的表是用代码写出来的)里的内容(经过修改,删除)到数据库中???
- C#如何将图片转为16位5R6G5B格式通过串口传输到显示屏
- 使用web.config配置数据库连接,还应在程序中应添加什么代码才能实现连接?
- 还是datagradview的问题,郁闷,在线等
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;
using System.Data.OleDb;public partial class ok : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string tempusername;
Response.Write(Application["username"]);
if (Session["values"] == null)
{
//Label4.Visible = false;
TextBox1.Enabled = false;
TextBox2.Enabled = false;
TextBox3.Enabled = false;
}
else
{
Label4.Visible = true;
//TextBox1.Enabled = false;
//TextBox2.Enabled = false;
//TextBox3.Enabled = false;
}
if (!IsPostBack)
{ DataBind();
} }
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex; DataBind();
}
private void DataBind()
{
string db = Server.MapPath("db1.mdb");
string ConnectionStr = "Data Source=" + db + ";Provider=Microsoft.Jet.OLEDB.4.0";
OleDbConnection myConn = new OleDbConnection(ConnectionStr);
myConn.Open();
string sqlselect = "select * from message where username='song'";
OleDbCommand mycommand1 = new OleDbCommand(sqlselect, myConn);
OleDbDataAdapter myadapter = new OleDbDataAdapter();
myadapter.SelectCommand = mycommand1;
DataSet mydata = new DataSet();
myadapter.Fill(mydata); GridView1.DataSource = mydata.Tables[0].DefaultView;
GridView1.DataBind();
}
//GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) protected void Button1_Click(object sender, EventArgs e)
{
string tempusername = TextBox1.Text;
string temptitle = TextBox2.Text;
string tempmessage = TextBox3.Text;
if (tempusername != "" && temptitle != "" && tempmessage != "")
{
string db = Server.MapPath("db1.mdb");
string ConnectionStr = "Data Source=" + db + ";Provider=Microsoft.Jet.OLEDB.4.0";
OleDbConnection myConn = new OleDbConnection(ConnectionStr);
myConn.Open();
string sql = "insert into message(username,title,message) values('" + tempusername + "','" + temptitle + "','" + tempmessage + "')"; OleDbCommand mycommand = new OleDbCommand(sql, myConn);
mycommand.ExecuteNonQuery();
myConn.Close();
Response.Write("发表留言成功!");
//Response.Redirect("ok.aspx");
}
}
}