Click here to Skip to main content
16,016,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My problem is when i click the update button it is updating the data in the database using sqldatasource associated with it. But the edit fields like textbox, buttons are not refreshing. When i click cancel button only it is showing the data and the textbox and update buttons are closing and postbacking to edit and delete buttons.

My doubt is adding
MultipleActiveResultSets=True
in web.config file this changes will be happened or not because previous page i had similar gridview event but the changes are happened as expected.

What I have tried:

Connection String: I have deleted the common statement like database, initial catalog username and password the only one MultipleActiveResultSets=True is kept here
<connectionStrings>
    <add name="DefaultConnection" connectionString="MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>


I have kept this gridview inside updatepanel having updatemode="conditional" and ChildrenAsTriggers="true"

Gridview:
<asp:GridView ID="gvUsersList" runat="server" AutoGenerateColumns="False" EmptyDataText="No Records Found" AllowPaging="True" GridLines="Vertical" AlternatingRowStyle-CssClass="alt" SkinID="gridviewSkin" Width="100%" CssClass="label" DataSourceID="userDetailsDataSource" DataKeyNames="UserID"                                            OnRowEditing="gvUsersList_RowEditing" OnRowCancelingEdit="gvUsersList_RowCancelingEdit"                                            OnRowUpdating="gvUsersList_RowUpdating" OnSelectedIndexChanged="gvUsersList_SelectedIndexChanged"                                            OnRowDeleting="gvUsersList_RowDeleting" 
OnRowDataBound="gvUsersList_RowDataBound"                                             ShowHeaderWhenEmpty="true" 
OnRowCommand="gvUsersList_RowCommand" 
EnableViewState="false">
         <asp:TemplateField ItemStyle-Width="250px">
             <ItemTemplate>
                 <asp:Button ID="btnEdit" runat="server" Text="Edit" CssClass="btn btn-link text-center" ToolTip="Edit User Details" CommandName="Edit" UseSubmitBehavior="false" OnCommand="btnEdit_Command" OnClick="btnEdit_Click" CausesValidation="false" />

                 <asp:Button ID="btnDelete" runat="server" Text="Delete" CssClass="btn btn-link text-center" ToolTip="Delete User Details" CommandName="Delete" UseSubmitBehavior="false" CausesValidation="false" OnClick="btnDelete_Click" />
            </ItemTemplate>
            <HeaderStyle Width="50px" />
            <EditItemTemplate>
                <asp:Button ID="btnUpdate" runat="server" Text="Update" CommandName="Update" CssClass="btn btn-link" UseSubmitBehavior="false" />
                <asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" UseSubmitBehavior="false" CssClass="btn btn-link" />
            </EditItemTemplate>
        </asp:TemplateField>
</asp:GridView>


Code Behind:
if (!IsPostBack)
{
    gvUsersList.DataSourceID = "userDetailsDataSource";
    gvUsersList.DataBind();
}
Posted
Updated 19-Mar-18 2:30am
Comments
Member 13658881 19-Mar-18 8:04am    
you use any update panel ? and use Bind() function on
if(!ispostback)
{
bind();
}
say clearly ..
Member 8583441 19-Mar-18 8:07am    
I have used it but there is no changes. Please help me sir
Member 13658881 19-Mar-18 8:20am    
Remove update panel else use trigger..wait i will give you example coding

1 solution

if (!IsPostBack)
{
   Bind()  //use bind function ....
}
void Bind()
{
//do grid view data fill work here 
}
this my sample coding you need to change...

if (e.CommandName == "Update")
          {

              butadd.Visible = false;// use visible false true here
              butaddupdate.Visible = true;//

              Button btnUpdate = (Button)e.CommandSource;
              GridViewRow row = (GridViewRow)btnUpdate.NamingContainer;
           //


          }

protected void butaddupdate_Click(object sender, EventArgs e)
       {
           butadd.Visible = true;
           butaddupdate.Visible = false;

           Pruchase.Columns[1].Visible = true;
           Pruchase.Columns[6].Visible = true;
           DataTable dt = new DataTable();

           if (ViewState["produ"] != null)
           {

               dt = (DataTable)ViewState["produ"];
               int rowindex = Convert.ToInt32(Session["rowname"].ToString());

               if (dt.Rows.Count >= 1 && rowindex != -1)
               {
                   dt.Rows[rowindex]["Prod_id"] = Litemid.Text;
                   dt.Rows[rowindex]["prd_name"] = txtitems.Text;
                   dt.Rows[rowindex]["Prod_qty"] = txtqty.Text;
                   dt.Rows[rowindex]["Prod_rate"] = txtrate.Text;
                   //dt.Rows[rowindex]["srid"] = Lsrid.Text;

                   Pruchase.DataSource = dt;
                   Pruchase.DataBind();
               }


           }

           //ViewState["produ"] = dt;


           Litemid.Text = "";
           txtitems.Text = "";
           txtqty.Text = "";
           txtrate.Text = "";
           txttotal.Text = "";

           //decimal total = 0;

           foreach (GridViewRow row in Pruchase.Rows)
           {
               decimal Rate = Convert.ToDecimal(row.Cells[3].Text);
               decimal qty = Convert.ToDecimal(row.Cells[4].Text);

               Decimal Total = Rate * qty;
               row.Cells[5].Text = Convert.ToString(Math.Round(Total, 2));

               Amount = Amount + Total;

               Pruchase.FooterRow.Cells[5].Text = Convert.ToString(Math.Round(Amount, 2));
               Lamt.Text = Pruchase.FooterRow.Cells[5].Text;

           }
           Pruchase.Columns[1].Visible = false;
           Pruchase.Columns[6].Visible = false;

       }
 
Share this answer
 
Comments
Member 8583441 19-Mar-18 8:35am    
for me no need to bind the data from the database it is automatically data from the SqlDataSource fields
Member 13658881 19-Mar-18 8:38am    
oh ok try this..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900