我用gridview控件,想用他这个编辑功能,怎么获取这文本框的值啊,然后进行更新操作,这个是直接

2025-03-22 16:10:44
推荐回答(1个)
回答1:

public partial class Default4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
FlashView("selet * from 表");
}

}
public DataTable GetDT(string SQL)
{
string strConn = "data source=.;initial catalog=数据库;uid=登录名;password=密码";
SqlConnection con = new SqlConnection(strConn);
con.Open();
SqlDataAdapter da = new SqlDataAdapter(SQL, con);
DataTable dt = new DataTable();
da.Fill(dt);
con.Close();
return dt;
}
public void FlashView(string SQL)
{
DataTable dt = GetDT(SQL);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
FlashView("链接字符串");
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{//这个地方需要强制类型转换
string s1 = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[0].Controls[0])).Text;
string s2 = ((Label)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text;
string s3 = ((DropDownList)(GridView1.Rows[e.RowIndex].FindControl("DropDownList1"))).Text;
//三种控件的的获取方式
//将获取到的值update到你所需要的表中就好了
FlashView("链接字符串");//再刷新一下
}