GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
}
留言板管理功能实现代码(DeleteBBS.aspx.cs):
public partial class DeleteBBS : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
BindData();
}
ConnectionStringSettings sets = ConfigurationManager.ConnectionStrings["DBConnection"];
SqlConnection conn;
protected void BindData()
{
conn = new SqlConnection(sets.ConnectionString);
SqlDataAdapter da = new SqlDataAdapter("select * from BBS ", conn);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
conn = new SqlConnection(sets.ConnectionString);
int id = Convert.ToInt32(GridView1.Rows[e.RowIndex].Cells[0].Text);
SqlCommand cmd = new SqlCommand("delete from BBS where bbsID=" + id, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
BindData();
}
protected void Button1_Click(object sender, EventArgs e)
{
BindData2();
}
protected void BindData2()
{
string ggbt1 = ggbt.Text;
conn = new SqlConnection(sets.ConnectionString);
SqlDataAdapter da = new SqlDataAdapter("select * from BBS where bbstitle='" + ggbt1 + "'", conn);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>