Gridview disappear click edit field in the gridview and click update button. if remove ispostback from page load and run the solution then click update button, gridview is not dissappear but previous values coming from gridview, if i check with break point
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Flow.aspx.cs" Inherits="WebApplication1.Flow" %> <!DOCTYPE html> <title> .headerstyle { color:#FFFFFF;border-right-color:#abb079;border-bottom-color:#abb079;background-color: #df5015;padding:0.5em 0.5em 0.5em 0.5em;text-align:center; } <div> <asp:TextBox ID="txtpname" runat="server" /><asp:TextBox ID="txtprice" runat="server" /> <asp:Button ID="btnAdd" runat="server" Text="Add Product" OnClick="btnAdd_Click" /> </div> <asp:GridView runat="server" ID="gvDetails" ShowFooter="true" AllowPaging="true" PageSize="10" AutoGenerateColumns="false" DataKeyNames="productid,productname,price" OnPageIndexChanging="gvDetails_PageIndexChanging" OnRowCancelingEdit="gvDetails_RowCancelingEdit" OnRowEditing="gvDetails_RowEditing" OnRowUpdating="gvDetails_RowUpdating" OnRowDeleting="gvDetails_RowDeleting" EnableViewState="False" > <HeaderStyle CssClass="headerstyle" /> <columns> <asp:BoundField DataField="productid" HeaderText="Product Id" ReadOnly="true" /> <asp:TemplateField HeaderText="Product Name"> <itemtemplate> <asp:Label ID="lblProductname" runat="server" Text='<%# Eval("productname")%>'/> <edititemtemplate> <asp:TextBox ID="txtProductname" runat="server" Text='<%# Eval("productname")%>'/> <asp:TemplateField HeaderText = "Price"> <itemtemplate> <asp:Label ID="lblPrice" runat="server" Text='<%# Eval("price")%>'> <edititemtemplate> <asp:TextBox ID="txtProductprice" runat="server" Text='<%# Eval("price")%>'/> <asp:CommandField ShowEditButton="True" ShowDeleteButton="true" /> Flow.aspx.cs ______________ <pre>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using WebApplication1.Account; using System.Data; using System.Data.SqlClient; namespace WebApplication1 { public partial class Flow : System.Web.UI.Page { BEL objUserBEL = new BEL(); string Output = string.Empty; DataSet ds=new DataSet(); BLL objUserBLL = new BLL(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindGridview(); } } protected void btnAdd_Click(object sender, EventArgs e) { objUserBEL.productname = txtpname.Text; objUserBEL.price = txtprice.Text; objUserBEL.op_type = "INSERT"; Output = objUserBLL.InsertUserDetails(objUserBEL); } protected void BindGridview() { objUserBEL.op_type = "SELECT"; ds = objUserBLL.GetUserDetails(objUserBEL); if (ds.Tables[0].Rows.Count > 0) { gvDetails.DataSource = ds; gvDetails.DataBind(); } else { ds.Tables[0].Rows.Add(ds.Tables[0].NewRow()); gvDetails.DataSource = ds; gvDetails.DataBind(); int columncount = gvDetails.Rows[0].Cells.Count; gvDetails.Rows[0].Cells.Clear(); gvDetails.Rows[0].Cells.Add(new TableCell()); gvDetails.Rows[0].Cells[0].ColumnSpan = columncount; gvDetails.Rows[0].Cells[0].Text = "No Records Found"; } } protected void gvDetails_RowEditing(object sender, GridViewEditEventArgs e) { gvDetails.EditIndex = e.NewEditIndex; BindGridview(); } protected void gvDetails_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { gvDetails.EditIndex = -1; BindGridview(); } protected void gvDetails_PageIndexChanging(object sender, GridViewPageEventArgs e) { gvDetails.PageIndex = e.NewPageIndex; BindGridview(); } protected void gvDetails_RowUpdating(object sender, GridViewUpdateEventArgs e) { int productid = Convert.ToInt32(gvDetails.DataKeys[e.RowIndex].Values["productid"].ToString()); string productname = gvDetails.DataKeys[e.RowIndex].Values["productname"].ToString(); string price = gvDetails.DataKeys[e.RowIndex].Values["price"].ToString(); objUserBEL.price = price; objUserBEL.productname = productname; objUserBEL.op_type="UPDATE"; objUserBEL.productid=productid; Output=objUserBLL.updatecrudoperations(objUserBEL); BindGridview(); } protected void gvDetails_RowDeleting(object sender, GridViewDeleteEventArgs e) { int productid = Convert.ToInt32(gvDetails.DataKeys[e.RowIndex].Values["productid"].ToString()); string productname = gvDetails.DataKeys[e.RowIndex].Values["productname"].ToString(); objUserBEL.price=txtprice.Text; objUserBEL.productname=productname; objUserBEL.op_type="DELETE"; objUserBEL.productid=productid; Output=objUserBLL.deletecrudoperations(objUserBEL); BindGridview(); } } }
debug
break-point
BindGridView()
RowUpdating
step-into
ds = objUserBLL.GetUserDetails(objUserBEL);
GridView
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)