【问题标题】:Updating a row in a Template field gridview by using Commandfiled buttons?使用 Commandfiled 按钮更新模板字段网格视图中的行?
【发布时间】:2014-02-09 18:21:52
【问题描述】:

这里的代码有什么问题...我正在尝试通过编辑、更新、取消命令字段按钮更新在网格视图的一行中获取的值。

     protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    Label lblid = (Label)GridView1.Rows[e.RowIndex].FindControl("Elblid");
    TextBox txtuser = (TextBox)GridView1.Rows[e.RowIndex].FindControl("EtxtUserName");
    TextBox txtpass = (TextBox)GridView1.Rows[e.RowIndex].FindControl("EPassword");

    if (lblid.Text != "" || lblid.Text != null)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["con"].ConnectionString);
        con.Open();
        SqlCommand cmd = new SqlCommand("Update Login set UserName='" + txtuser.Text + "',Password='" + txtpass.Text + "' Where Id=" + lblid.Text, con);
        cmd.ExecuteNonQuery();
        con.Close();
        GridView1.EditIndex = -1;
        FillGrid();
    }

这是抛出的错误:

PS:当页面指令中的事件验证设置为 false 时。这个错误消失了,但代码没有做任何事情。

【问题讨论】:

    标签: c# asp.net .net gridview updating


    【解决方案1】:

    它显示什么错误??

    试试这个

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
        Label lblid = (Label)row.FindControl("Elblid");
        TextBox txtuser = (TextBox)row.FindControl("EtxtUserName");
        TextBox txtpass = (TextBox)row.FindControl("EPassword");
    }
    

    【讨论】:

      猜你喜欢
      • 2015-09-19
      • 2012-05-26
      • 2013-12-22
      • 1970-01-01
      • 2015-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多