关于GRidview问题 [英] Regarding GRidview Issue

查看:79
本文介绍了关于GRidview问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个网格视图,更新按钮在网格视图之外。网格视图中有一个图像按钮编辑。当我点击该编辑按钮时,文本框出现在我必须编辑的网格视图之外。但我的更新按钮是按钮3没有更新相应的行。它会更新整个网格视图。更新按钮如何仅更新我点击的编辑按钮的行。这是我的代码。请帮助

Hi Everyone,
I have an grid view and update button is outside the grid view. There is a image button Edit inside grid view. When i am clicking that edit button text boxes appears outside the grid view where i have to edit. But my update button which is button 3 not updating the corresponding row. it updates the whole Grid view. how the update button only update that row which edit button i have clicked. This is my code .please help

protected void Button3_Click(object sender, EventArgs e)
{
  foreach ( GridView row in GridView1.Rows)
  {
        Label ID = (Label)row.FindControl("ID");
        Label Vendor_Name = (Label)row.FindControl("Vendor_Name");
        Label Asset_Type = (Label)row.FindControl("Asset_Type");

        Label status = (Label)row.FindControl("Status");
        Label Email = (Label)row.FindControl("Email");
        Label Date_Of_Registration = (Label)row.FindControl("Date_Of_Registration");
        Label Phone_Number = (Label)row.FindControl("Phone_Number");
        Label Vendor_Address = (Label)row.FindControl("Vendor_Address");
        Label Vendor_Billing_Address = (Label)row.FindControl("Vendor_Billing_Address");
        //TextBox1.Text = Vendor_Name.Text;
        //TextBox7.Text = Asset_Type.Text;
        //Status.SelectedValue = Status.Text;
        //TextBox5.Text = Email.Text;
        //TextBox6.Text = Phone_Number.Text;
        //TextBox4.Text = Date_Of_Registration.Text;
        //TextBox8.Text = Vendor_Address.Text;
        //TextBox9.Text = Vendor_Billing_Address.Text;
        con.Open();
        string sql = "update VandorDetail set Vendor_Name='" +
    TextBox1.Text + "',Asset_Type='" + TextBox7.Text + "',Email='" +
   TextBox5.Text + "',Status='" + Status.SelectedValue + "',Date_Of_Registration='" + TextBox4.Text + "',Phone_Number='" + TextBox6.Text + "',Vendor_Address='" + TextBox8.Text + "',Vendor_Billing_Address='" + TextBox9.Text + "' where ID='" +
   ID.Text + "'";
        SqlCommand cmd = new SqlCommand(sql);
        cmd.CommandType = CommandType.Text;
        cmd.Connection = con;
        cmd.ExecuteNonQuery();
        con.Close();
        Populategridview();
    }
}









已添加 pre 标签。

添加了正确的标签。

[/编辑]

推荐答案

这种情况正在发生,因为您正在更新所有行...

This is happening because you are updating all the rows...
foreach ( GridView row in GridView1.Rows)



要仅更新已编辑的特定行,您必须存储一个引用或<该行的code> Key 位于 ViewState Session 或a HiddenField 或其他什么。您有一个 ID 列。因此,您可以将其存储为参考。



然后在按钮3单击事件中,读取并更新该特定的行。


To update only the particular row edited, you have to store one reference or Key of that Row somewhere either on ViewState or Session or a HiddenField or something. You have one ID column. So, you can store that as a reference.

Then inside this Button 3 Click Event, read that Key and update that particular Row.


这篇关于关于GRidview问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆