[asp.net c#]从gridview页脚插入一行数据,已经添加至数据库了,但为啥gridview上不更新、不显示? 5
protectedvoidGridView1_RowCommand(objectsender,GridViewCommandEventArgse){if(e.Comman...
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "ItemSure" && Page.IsValid)
{
// string id = GridView1.DataKeys[e.RowIndex].Values[0].ToString().Trim();
string s1 = ((TextBox)GridView1.FooterRow.FindControl("NewCompanyName")).Text.Trim();
string s2 = ((TextBox)GridView1.FooterRow.FindControl("Keyword")).Text.Trim();
string s3 = ((TextBox)GridView1.FooterRow.FindControl("Industry")).Text.Trim();
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=localhost;Initial Catalog=enterprise;uid=sa;pwd=sql";
conn.Open();
string sqlStr = "insert into 企业名单(企业名称,关键词,行业分类) values ('" + s1 + "','" + s2 + "','" + s3 + "')";
SqlCommand cmd = new SqlCommand(sqlStr, conn);
cmd.ExecuteNonQuery();
conn.Close();
GridViewBind();
}
} 展开
{
if (e.CommandName == "ItemSure" && Page.IsValid)
{
// string id = GridView1.DataKeys[e.RowIndex].Values[0].ToString().Trim();
string s1 = ((TextBox)GridView1.FooterRow.FindControl("NewCompanyName")).Text.Trim();
string s2 = ((TextBox)GridView1.FooterRow.FindControl("Keyword")).Text.Trim();
string s3 = ((TextBox)GridView1.FooterRow.FindControl("Industry")).Text.Trim();
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=localhost;Initial Catalog=enterprise;uid=sa;pwd=sql";
conn.Open();
string sqlStr = "insert into 企业名单(企业名称,关键词,行业分类) values ('" + s1 + "','" + s2 + "','" + s3 + "')";
SqlCommand cmd = new SqlCommand(sqlStr, conn);
cmd.ExecuteNonQuery();
conn.Close();
GridViewBind();
}
} 展开
2012-05-26
展开全部
添加完成后,要重新加载数据库的值进行重新绑定,看你的 GridViewBind(); 里有有没有加载数据库信息。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
GridViewBind(); 在这之前,你先调用 加载DS的那个方法,然后用dataset 进行绑定
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询