using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.bindGridview();//调用自定义方法绑定控件数据
}
}
public void bindGridview()
{
SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["strCon"]);
con.Open();//打开数据库连接
SqlDataAdapter ada = new SqlDataAdapter("Select * From tb_Send05", con);//创建数据适配器
DataSet ds = new DataSet();//创建数据集
ada.Fill(ds);//填充数据集
GridView1.DataSource = ds;//绑定数据
GridView1.DataBind();
con.Close();
}
protected void ImgBtnSend_Click(object sender, ImageClickEventArgs e)
{
try
{
SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["strCon"]);
con.Open();
string InsertSql = "Insert Into tb_send05 values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "')";
SqlCommand com = new SqlCommand(InsertSql, con);//创建执行SQL命令的SqlCommand对象
com.ExecuteNonQuery();//执行添加操作
SqlDataAdapter ada = new SqlDataAdapter("Select * From tb_Send05", con);//创建适配器
DataSet ds = new DataSet();
ada.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
Response.Write("");
}
catch
{
Response.Write("");
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
this.bindGridview();
}
}
|