Note that there are some explanatory texts on larger screens.

plurals
  1. POrow updating in gridview not working
    primarykey
    data
    text
    <p>Gridview update is not happening after I edit it. Used breakpoints and checked, its showing the same existing values which is there before editing. I am not getting any kind of error. Have used Store Procedure to update the Gridview. Please go through the code and help me sort out this problem.</p> <p>aspx code</p> <pre><code>&lt;asp:GridView ID="gvData" runat="server" AutoGenerateColumns="False" OnRowEditing="gvData_RowEditing" OnRowDataBound="gvData_RowCreated" OnRowCreated="gvData_RowCreated" OnRowCancelingEdit="gvData_RowCancelingEdit" OnRowUpdating="gvData_RowUpdating" Style="text-align: center; margin-left: 0px;" Height="160px" Width="657px" BackColor="#DEBA84" BorderColor="#DEBA84" orderStyle="None" BorderWidth="0px" CellPadding="3" CellSpacing="2" DataKeyNames="BtnID" Font-Names="Calibri" ForeColor="#CC3300" EmptyDataText="No Records Found!!!" CaptionAlign="Left" HorizontalAlign="Left" &gt; &lt;AlternatingRowStyle HorizontalAlign="Left" VerticalAlign="Middle" Wrap="False" BorderStyle="None" /&gt; &lt;Columns&gt; &lt;asp:TemplateField HeaderText="BtnID" &gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="lblBtnID" runat="server" ForeColor="#003366" Font-Names="Calibri" Font-Size="Small" Height="24px" Width="20px" Text='&lt;%#Eval("BtnID") %&gt;'&gt; &lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText="LogdInUsername" &gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="lblLogdInUsername" runat="server" ForeColor="#003366" Font-Names="Calibri" Font-Size="Small" Height="24px" Width="20px" Text='&lt;%#Eval("LogdInUsername") %&gt;'&gt; &lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText="Year"&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="lblYear" runat="server" ForeColor="#003366" Font-Names="Calibri" Font-Size="Small" Height="24px" Text='&lt;%# Eval("Year") %&gt;' Width="20px"&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText="Month"&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="lblMonth" runat="server" ForeColor="#003366" Font-Names="Calibri" Font-Size="Small" Text='&lt;%# Eval("Month") %&gt;' Height="24px" Width="20px"&gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText="Comments"&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="lblComments" runat="server" ForeColor="#003366" Font-Names="Calibri" Text='&lt;%# Eval("Comments") %&gt;' Font-Size="Small" Height="24px" Width="20px" &gt;&lt;/asp:Label&gt; &lt;/ItemTemplate&gt; &lt;EditItemTemplate&gt; &lt;asp:TextBox ID="TxtComments" runat="server" Width="300px" Text='&lt;%# Bind("Comments") %&gt;' &gt;&lt;/asp:TextBox&gt; &lt;/EditItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:TemplateField HeaderText="Action"&gt; &lt;ItemTemplate&gt; &lt;asp:LinkButton ID="btnEdit" Text="Edit" runat="server" CommandName="Edit" /&gt; &lt;/ItemTemplate&gt; &lt;EditItemTemplate&gt; &lt;asp:LinkButton ID="btnUpdate" Text="Update" runat="server" CommandName="Update" /&gt; &lt;asp:LinkButton ID="btnCancel" Text="Cancel" runat="server" CommandName="Cancel" /&gt; &lt;/EditItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;EditRowStyle HorizontalAlign="Left" VerticalAlign="Middle" Wrap="False" BorderStyle="None" /&gt; &lt;EmptyDataRowStyle HorizontalAlign="Left" VerticalAlign="Middle" Wrap="False" /&gt; &lt;FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" /&gt; &lt;HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Wrap="False" /&gt; &lt;PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" /&gt; &lt;RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" HorizontalAlign="Left" VerticalAlign="Middle" Wrap="False" /&gt; &lt;SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" VerticalAlign="Middle" Wrap="False" /&gt; &lt;SortedAscendingCellStyle BackColor="#FFF1D4" HorizontalAlign="Left" VerticalAlign="Middle" Wrap="False" /&gt; &lt;SortedAscendingHeaderStyle BackColor="#B95C30" /&gt; &lt;SortedDescendingCellStyle BackColor="#F1E5CE" /&gt; &lt;SortedDescendingHeaderStyle BackColor="#93451F" /&gt; &lt;/asp:GridView&gt; </code></pre> <p>cs code </p> <pre><code>protected void Page_Load(object sender, EventArgs e) { DTO objc = new DTO(); string str = Environment.UserName; GrdGetComments(); if (!IsPostBack) { GetYear(); GetMonth(); GrdGetComments(); UserPrincipal up1 = GetUserPrincipal(str); Session["Username"] = str; Session["Name"] = up1.Name; LblName.Text = Session["Username"].ToString(); objc.Name = LblName.Text; LblLogdInUsername.Text = Session["Name"].ToString(); objc.LogdInUsername = LblLogdInUsername.Text; LblDateTime.Text = DateTime.Now.ToString(); LblCompany.Text = ""; objc.Company = LblCompany.Text; } } public static UserPrincipal GetUserPrincipal(String userName) { UserPrincipal up = null; PrincipalContext context = new PrincipalContext(ContextType.Domain); up = UserPrincipal.FindByIdentity(context, userName); if (up == null) { context = new PrincipalContext(ContextType.Machine); up = UserPrincipal.FindByIdentity(context, userName); } if (up == null) throw new Exception("Unable to get user from Domain or Machine context."); return up; } protected void GetYear() { DTO objc = new DTO(); { DrpForYear.DataSource = obj.GetYear(); DrpForYear.DataTextField = "Year"; DrpForYear.DataBind(); } } protected void GetMonth() { DTO objc = new DTO(); { DrpForMonth.DataSource = obj.GetMonth(); ; DrpForMonth.DataTextField = "Month"; DrpForMonth.DataBind(); } } public void GrdGetComments() { DTO objc = new DTO(); { objc.LogdInUsername = Convert.ToString(Session["LogdInUsername"]); DataSet GrdVC = obj.GetButtonComment(objc); DataView GrdViewC = new DataView(); GrdViewC.Table = GrdVC.Tables[0]; gvData.DataSource = GrdViewC; gvData.DataBind(); } } protected void BtnSave_Click(object sender, EventArgs e) { DTO objc = new DTO(); int Flag = 0; LblLogdInUsername.Text = Session["Username"].ToString(); objc.LogdInUsername = LblLogdInUsername.Text; objc.DateTime = DateTime.Now; objc.Comments = TxtComments.Text; objc.Company = LblCompany.Text; LblName.Text = Session["Name"].ToString(); objc.Name = LblName.Text; objc.Year = DrpForYear.SelectedItem.Text; objc.Month = DrpForMonth.SelectedItem.Text; objc.ViewPreference = RadView.SelectedItem.Text; int X = obj.InsertButtonComment(objc); if (X &gt;= 0) { Flag = 1; } else { Flag = 0; } if (Flag == 1) { LblSuccess.Visible = true; LblSuccess.Text = "Comment Saved"; } else { LblErr.Visible = true; LblErr.Text = "Failed To Save Comment!!!"; } objc.LogdInUsername = Convert.ToString(Session["LogdInUsername"]); DataSet GrdVC = obj.GetButtonComment(objc); DataView GrdViewC = new DataView(); GrdViewC.Table = GrdVC.Tables[0]; gvData.DataSource = GrdViewC; gvData.DataBind(); TxtComments.Text = ""; DrpForYear.ClearSelection(); DrpForMonth.ClearSelection(); RadView.Text = ""; } protected void gvData_RowEditing(object sender, GridViewEditEventArgs e) { gvData.EditIndex = e.NewEditIndex; GrdGetComments(); } protected void gvData_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { gvData.EditIndex = -1; GrdGetComments(); } protected void gvData_RowUpdating(object sender, GridViewUpdateEventArgs e) { DTO objc = new DTO(); Label lblBtnID = (Label)gvData.Rows[e.RowIndex].FindControl("lblBtnID"); Label lblLogdInUsername = (Label)gvData.Rows[e.RowIndex].FindControl("lblLogdInUsername"); Label lblYear = (Label)gvData.Rows[e.RowIndex].FindControl("lblYear"); Label lblMonth = (Label)gvData.Rows[e.RowIndex].FindControl("lblMonth"); Label lblComments = (Label)gvData.Rows[e.RowIndex].FindControl("lblComments"); TextBox txtComments = (TextBox)gvData.Rows[e.RowIndex].FindControl("TxtComments"); LblLogdInUsername.Text = Session["Username"].ToString(); objc.LogdInUsername = LblLogdInUsername.Text; objc.Comments = TxtComments.Text; objc.BtnID = Convert.ToInt32(Session["BtnID"]); int Flag = 0; int X = obj.UpdategvData(objc); { if (X &gt;= 0) { Flag = 1; } else { Flag = 0; } } if (Flag == 1) { LblSuccss.Visible = true; LblSuccss.Text = "Comment Updated"; } else { LblErrr.Visible = true; LblErrr.Text = "Failed To Update Comment!!!"; } } public int UpdategvData(InLogDTO b) { DBAccess db = new DBAccess(); SqlParameter objParam = new SqlParameter("@LogdInUsername", b.LogdInUsername); objParam.Direction = ParameterDirection.Input; objParam.Size = 50; db.Parameters.Add(new SqlParameter("@Comments", b.Comments)); db.Parameters.Add(new SqlParameter("@BtnID", b.BtnID)); db.Parameters.Add(objParam); int retval = db.ExecuteNonQuery("UpdategvData"); if (retval &gt;= 1) { int i = 0; return i; } else { return -1; } } </code></pre> <p>stored procedure</p> <pre><code>ALTER PROCEDURE [dbo].[UpdategvData] @LogdInUsername nvarchar(50) , @Comments nvarchar(50), @BtnID int AS Update dbo.Button_Comments Set Comments = @Comments Where LogdInUsername = @LogdInUsername and ViewPreference = 'Public' and Comments = @Comments and BtnID = @BtnID; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload