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;
using System.Data.SqlClient;
public partial class admin_Manage_FengCai : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) { getGridView(); };
}
public void getGridView()
{
SqlDataAdapter sda = new SqlDataAdapter();
SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=111111;database=sanjingkou");
sda.SelectCommand = new SqlCommand("select * from FengCai", con);
DataSet ds1 = new DataSet();
sda.Fill(ds1, "FengCai");
GridView1.DataSource = ds1.Tables["FengCai"].DefaultView;
GridView1.DataBind();
}
public void getmessage(string FengCaiNames, string FengCaiDate, string FengCaiContent,int id)
{
SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=sa;database=sanjingkou");
SqlCommand cmd = new SqlCommand("update FengCai set FengCaiNames='"+FengCaiNames+"',FengCaiDate='"+FengCaiDate+"',FengCaiContent='"+FengCaiContent+"'where id='"+id+"'", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
public void delmessage(int id)
{
SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=sa;database=sanjingkou");
SqlCommand cmd = new SqlCommand("delete from FengCai where id='" + id + "'", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
GridView1.SelectedIndex = e.NewSelectedIndex;
getGridView();
}
protected void GridView1_RowUpdating1(object sender, GridViewUpdateEventArgs e)
{
int id = int.Parse(this.GridView1.DataKeys[e.RowIndex].Value.ToString());
//列是从第一列开始的
string FengCaiNames = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text.ToString();
string FengCaiDate = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text.ToString();
string FengCaiContent = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text.ToString();
getmessage(FengCaiNames, FengCaiDate, FengCaiContent, id);//与函数的定义不同
this.GridView1.EditIndex = -1;
getGridView();
}
protected void GridView1_RowEditing1(object sender, GridViewEditEventArgs e)
{
this.GridView1.EditIndex = e.NewEditIndex;
getGridView();
}
protected void GridView1_RowDeleting1(object sender, GridViewDeleteEventArgs e)
{
int id = int.Parse(this.GridView1.DataKeys[e.RowIndex].Value.ToString());
getGridView();
delmessage(id);
}
protected void GridView1_RowCancelingEdit1(object sender, GridViewCancelEditEventArgs e)
{
this.GridView1.EditIndex = -1;
getGridView();
}
}