点击更新时,它ID不会更新并返回到之前的值,但删除选项正常工作
Id = ((Label)GridView1.Rows[e.RowIndex].FindControl("lblDealerId")).Text;
Name = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtDealer_Name")).Text;
Address = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtDealer_Address")).Text;
City = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtCity")).Text;
Pincode = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtDealer_Pincode")).Text;
string cs = ConfigurationManager.ConnectionStrings["dbcs"].ConnectionString;
SqlConnection con = new SqlConnection(cs);
SqlCommand cmd = new SqlCommand("sp_update_dealer", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@dealer_id", SqlDbType.NVarChar).Value = Id;
cmd.Parameters.Add("@dealer_name", SqlDbType.NVarChar).Value = Name;
cmd.Parameters.Add("@dealer_address", SqlDbType.NVarChar).Value = Address;
cmd.Parameters.Add("@dealer_city", SqlDbType.NVarChar).Value = City;
cmd.Parameters.Add("@dealer_pincode", SqlDbType.NVarChar).Value = Pincode;
//GridView1.EditIndex = -1;
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
答案 0 :(得分:0)
您的标签lblDealerId
也应放在EditTemplate
:
<EditItemTemplate>
<asp:Label ID="lblDealerId" runat="server" Text='<%# Eval("Id") %>'></asp:Label>
//.. some other TexBoxes
</EditItemTemplate>