Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8855159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:04:07+00:00 2026-06-14T14:04:07+00:00

I am using ObjectDataSource to Bind and update the grid .It is working fine

  • 0

I am using ObjectDataSource to Bind and update the grid .It is working fine and the records are updating in the database but after updating ,it is still showing the same records in the grid (Previous Values). Please help me that what i will do so that after database updation, The grid will display updated records ,not the old records.Please modify my code also in case if any one found the solution.

Thanks in Advance.

Please find the code below.

GridView Code:-

<asp:Panel ID="pnlGrdShift" runat="server" ScrollBars="Auto" Width="900px" Height="520px" CssClass="srcColor">
            <cc1:GridView  ID="gvShift" runat="server" AutoGenerateColumns="False" AllowSorting="True"
               CssClass="grid"
               OnDataBound="gvShift_DataBound" 
               DataSourceID="odsShiftDetails" 
               AllowPaging="True" 
               ShowFooter="false"
               onrowcancelingedit="gvShift_RowCancelingEdit" 
               onrowcommand="gvShift_RowCommand" 
               onrowdeleting="gvShift_RowDeleting" 
               onrowediting="gvShift_RowEditing" 
               onrowupdating="gvShift_RowUpdating" 
               OnSelectedIndexChanged="gvShift_SelectedIndexChanged" 
               OnRowDataBound="gvShift_RowDataBound">        
                <AlternatingRowStyle CssClass="altrowstyle"  />
                <HeaderStyle CssClass="headerstyle" />
                <RowStyle CssClass="rowstyle" Wrap="false"  />
                <EmptyDataRowStyle BackColor="#edf5ff" Height="300px" VerticalAlign="Middle" HorizontalAlign="Center" />
                <EmptyDataTemplate >
                    No Records Found
                </EmptyDataTemplate> 
                <Columns>
                    <asp:TemplateField HeaderText="E Code" SortExpression="userecode" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Names="Calibre" HeaderStyle-ForeColor="White">
                        <ItemTemplate>
                            <asp:Label ID="lblUserECode" runat="server" Text='<%#Eval("userecode") %>' CssClass="GridContent" />                    
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:Label ID="lblEditUserECode" runat="server" Text='<%#Eval("userecode") %>' style="width:50px;" CssClass="GridContent" />                    
                        </EditItemTemplate>
                    </asp:TemplateField>                       

                    <asp:TemplateField HeaderText="User Name" SortExpression="username" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Names="Calibre" HeaderStyle-ForeColor="White">
                        <ItemTemplate>
                            <asp:Label ID="lblUserName" runat="server" Text='<%#Eval("username") %>' CssClass="GridContent" />                    
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:Label ID="lblEditUserName" runat="server" Text='<%#Eval("username") %>' style="width:100px;" CssClass="GridContent"/>                    
                        </EditItemTemplate>
                    </asp:TemplateField>


                    <asp:TemplateField HeaderText="Shift Start Time" SortExpression="ShiftStartTime" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Names="Calibre" HeaderStyle-ForeColor="White">
                         <ItemTemplate>
                            <asp:Label ID="lblShiftStartTime" runat="server" Text='<%#Eval("ShiftStartTime") %>'  CssClass="GridContent"/>                    
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="ddlShiftStartTime" runat="server" Text='<%#Eval("ShiftStartTime") %>' style="width:65px;" CssClass="GridContent" />
                            <asp:RegularExpressionValidator ID="RegularExpValidatorddlShiftStartTime" runat="server" ControlToValidate="ddlShiftStartTime" ValidationExpression="^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$" ErrorMessage="*" Font-Bold="true" ForeColor="Red" ToolTip="Must be in HH:MM" />                            

                        </EditItemTemplate>                            
                    </asp:TemplateField>  

                    <asp:TemplateField HeaderText="Shift End Time" SortExpression="ShiftEndTime" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Names="Calibre" HeaderStyle-ForeColor="White">
                        <ItemTemplate>
                            <asp:Label ID="lblShiftEndTime" runat="server" Text='<%#Eval("ShiftEndTime") %>' CssClass="GridContent" />                    
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="ddlShiftEndTime" runat="server" Text='<%#Eval("ShiftEndTime") %>' style="width:65px;" CssClass="GridContent"  />
                            <asp:RegularExpressionValidator ID="RegularExpValidatorddlShiftEndTime" runat="server" ControlToValidate="ddlShiftEndTime" ValidationExpression="^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$" ErrorMessage="*" Font-Bold="true" ForeColor="Red" ToolTip="Must be in HH:MM" />                            

                        </EditItemTemplate>                            
                    </asp:TemplateField>
                        <%--<asp:BoundField DataField="ShiftEndTIme" HeaderText="Shift End Time" SortExpression="ShiftEndTIme"/>--%>
                    <asp:TemplateField HeaderText="Saturday Shift Start Time" SortExpression="WeekendShiftStartTime" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Names="Calibre" HeaderStyle-ForeColor="White">
                        <ItemTemplate>
                            <asp:Label ID="lblWeekendShiftStartTime" runat="server" Text='<%#Eval("WeekendShiftStartTime") %>' CssClass="GridContent" />                    
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="ddlWeekendShiftStartTime" runat="server" Text='<%#Eval("WeekendShiftStartTime") %>' style="width:65px;" CssClass="GridContent" />  
                            <asp:RegularExpressionValidator ID="RegularExpValidatorddlWeekendShiftStartTime" runat="server" ControlToValidate="ddlWeekendShiftStartTime" ValidationExpression="^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$" ErrorMessage="*" Font-Bold="true" ForeColor="Red" ToolTip="Must be in HH:MM" />                          

                        </EditItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Saturday Shift End Time" SortExpression="weekendshiftendtime" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Names="Calibre" HeaderStyle-ForeColor="White">
                    <ItemTemplate>
                            <asp:Label ID="lblWeekendShiftEndTime" runat="server" Text='<%#Eval("weekendshiftendtime") %>' CssClass="GridContent"/>                    
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="ddlWeekendShiftEndTime" runat="server" Text='<%#Eval("weekendshiftendtime") %>' style="width:65px;" CssClass="GridContent" /> 
                            <asp:RegularExpressionValidator ID="RegularExpValidatorddlWeekendShiftEndTime" runat="server" ControlToValidate="ddlWeekendShiftEndTime" ValidationExpression="^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$" ErrorMessage="*" Font-Bold="true" ForeColor="Red" ToolTip="Must be in HH:MM" />                           

                        </EditItemTemplate>                           
                    </asp:TemplateField>

                    <asp:TemplateField  ShowHeader="False" > 
                        <EditItemTemplate> 
                          <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update" ForeColor="White"></asp:LinkButton> 
                          <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" ForeColor="White"></asp:LinkButton> 
                        </EditItemTemplate> 
                        <ItemTemplate> 
                          <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" ForeColor="White"></asp:LinkButton> 
                        </ItemTemplate> 
                </asp:TemplateField>                    
           </Columns>
                <PagerTemplate >
                     <table width="100%" >
                        <tr>
                            <td style="text-align:  left">
                                Page Size: 
                                    <asp:DropDownList ID="ddPageSize" runat="server" EnableViewState="true" OnSelectedIndexChanged="ddPageSize_SelectedIndexChanged" AutoPostBack="true" style="width:50px;">
                                    <asp:ListItem Text="10" ></asp:ListItem>
                                    <asp:ListItem Text="20" ></asp:ListItem>
                                    <asp:ListItem Text="30" ></asp:ListItem>
                                    <asp:ListItem Text="40" ></asp:ListItem>
                                    <asp:ListItem Text="50" ></asp:ListItem>
                                </asp:DropDownList>
                            </td>
                            <td style="text-align: right">
                                <asp:Label ID="lblPageCount" runat="server"></asp:Label>
                            </td>
                        </tr>
                    </table>
                </PagerTemplate>
                </cc1:GridView>      
         </asp:Panel>


 <asp:ObjectDataSource ID="odsShiftDetails" runat="server" 
                SelectMethod="GetShiftInfoSortedPage" TypeName="EQ.DAL.ShiftInfoDB"
                EnablePaging="True" SelectCountMethod="GetShiftInfoCount" 
                SortParameterName="sortExpression" UpdateMethod="UpdateShift">
                <UpdateParameters>
                <asp:Parameter Name="sql"/>
                </UpdateParameters>
                <SelectParameters>
                    <asp:ControlParameter  ControlID="hfSearchCriteria"  Name="searchCriteria" Direction="Input"  />
                </SelectParameters>                                            
            </asp:ObjectDataSource>

Code Behind for Update:-

protected void gvShift_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        try
        {
            TextBox txtShiftStartTime = (TextBox)gvShift.Rows[e.RowIndex].FindControl("ddlShiftStartTime");
            TextBox txtShiftEndTime = (TextBox)gvShift.Rows[e.RowIndex].FindControl("ddlShiftEndTime");
            TextBox txtWeekendShiftStartTime = (TextBox)gvShift.Rows[e.RowIndex].FindControl("ddlWeekendShiftStartTime");
            TextBox txtWeekendShiftEndTime = (TextBox)gvShift.Rows[e.RowIndex].FindControl("ddlWeekendShiftEndTime");
            Label lblUserecode = (Label)gvShift.Rows[e.RowIndex].FindControl("lblEditUserECode");

            string userecode = lblUserecode.Text.ToString();
            string _ShiftStart = txtShiftStartTime.Text.ToString();
            string _ShiftEnd = txtShiftEndTime.Text.ToString();
            string _WeekendShiftStart = txtWeekendShiftStartTime.Text.ToString();
            string _WeekendShiftend = txtWeekendShiftEndTime.Text.ToString();

            EmployeeQuotientCL.Entities.ConfigurationVariables _configVariables = new ConfigurationVariables();
            string databaseConnectionString = _configVariables.ConnectionString;
            SqlConnection sqlConnection = null;
            if (((databaseConnectionString + string.Empty) != string.Empty))
            {

                DBConnect dbConnect = new DBConnect(_configVariables.ConnectionString);
                sqlConnection = dbConnect.SQLConnection;
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = sqlConnection;
                string sql=null;
                cmd.CommandText = "UPDATE UserInfo SET ShiftStartTime ='" + _ShiftStart + "',ShiftEndTime='" + _ShiftEnd.ToString() + "',Weekendshiftstarttime='" + _WeekendShiftStart.ToString() + "',Weekendshiftendtime='" + _WeekendShiftend.ToString() + "'   WHERE UserECode=" + userecode.ToString();
                odsShiftDetails.UpdateParameters["sql"].DefaultValue = cmd.CommandText;
                odsShiftDetails.Update();
            }
        }
        catch (Exception ex)
        {
        }
    }

ShiftInfoDBCache.cs

public class ShiftInfoDB
{
    private const string SHIFTINFO_CACHE_KEY = "SHIFTINFO_DATA";
    private const string SHIFTINFOCOUNT_CACHE_KEY = "SHIFTINFO_COUNT";
    static EmployeeQuotientCL.Entities.ConfigurationVariables _config = new EmployeeQuotientCL.Entities.ConfigurationVariables();
    static int _SupervisorecodeforShift;


    public static  DataTable GetShiftInfoSortedPage(int maximumRows, int startRowIndex, string sortExpression, string searchCriteria)
    {
        _SupervisorecodeforShift=EmployeeQuotientCL.Entities.StaticGlobalValue.UserId;

        if (string.IsNullOrEmpty(sortExpression))
            sortExpression = "userecode";
        try
        {
            if (ShiftInfoDBCache.isRecordsCached(SHIFTINFO_CACHE_KEY))
                return ShiftInfoDBCache.GetData(SHIFTINFO_CACHE_KEY, startRowIndex + 1, maximumRows, sortExpression, searchCriteria);

            SqlConnection dbConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnectionString"].ToString());
            string sql = "select distinct MP.userecode,UI.username,UI.ShiftStartTime,UI.ShiftEndTime,UI.WeekendShiftStartTime,UI.weekendshiftendtime from AssociateSupervisorMapping MP inner join UserInfo UI on MP.Userecode=UI.Userecode where supervisorecode=" + _SupervisorecodeforShift.ToString();

            SqlCommand custCommand = new SqlCommand(sql, dbConnection);

            custCommand.CommandType = CommandType.Text;

            SqlDataAdapter ad = new SqlDataAdapter(custCommand);
            DataTable dtCustomers = new DataTable();
            ad.Fill(dtCustomers);
            dbConnection.Close();


            //Cache records
            ShiftInfoDBCache.Add(SHIFTINFO_CACHE_KEY, dtCustomers);

        }
        catch (Exception e)
        {

            throw;
        }
        return ShiftInfoDBCache.GetData(SHIFTINFO_CACHE_KEY, startRowIndex + 1, maximumRows, sortExpression, null);
    }

    public static int GetShiftInfoCount(string searchCriteria)
    {
         _SupervisorecodeforShift=EmployeeQuotientCL.Entities.StaticGlobalValue.UserId;
        int custCount = 0;
        try
        {
            SqlConnection dbConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnectionString"].ToString());
            string sql = "select Count(*)from (select distinct MP.userecode,UI.username,UI.ShiftStartTime,UI.ShiftEndTime,UI.WeekendShiftStartTime,UI.weekendshiftendtime from AssociateSupervisorMapping MP inner join UserInfo UI on  MP.Userecode=UI.Userecode   where supervisorecode="+_SupervisorecodeforShift.ToString()+")AS internalQuery";

            if (!string.IsNullOrEmpty(searchCriteria))
                sql = sql + " where " + searchCriteria;

            SqlCommand sqlCommand = new SqlCommand(sql, dbConnection);
            sqlCommand.Connection = dbConnection;
            dbConnection.Open();
            sqlCommand.CommandType = CommandType.Text;

            custCount = Convert.ToInt32(sqlCommand.ExecuteScalar());

            dbConnection.Close();

            if (ShiftInfoDBCache.Get(SHIFTINFOCOUNT_CACHE_KEY) != null)
            {
                // remove customers data if customers count has changed since first cache
                if (Convert.ToInt32(ShiftInfoDBCache.Get(SHIFTINFOCOUNT_CACHE_KEY)) != custCount && string.IsNullOrEmpty(searchCriteria))
                {
                    ShiftInfoDBCache.Remove(SHIFTINFO_CACHE_KEY);
                }
            }

            if (string.IsNullOrEmpty(searchCriteria))
                ShiftInfoDBCache.Add(SHIFTINFOCOUNT_CACHE_KEY, custCount);
        }
        catch (Exception e)
        {
            throw;
        }
        return custCount;

    }

    public static void UpdateShift(string sql)
    {
        SqlConnection dbConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnectionString"].ToString());
        SqlCommand sqlCommand = new SqlCommand(sql, dbConnection);
        sqlCommand.CommandType=CommandType.Text;
        sqlCommand.CommandText=sql;
        dbConnection.Open();
        sqlCommand.Connection = dbConnection;
        //sqlCommand.CommandType = CommandType.Text;
        sqlCommand.ExecuteNonQuery();
        dbConnection.Close();
    }



}

ShiftInfoDBCache.cs

public  class ShiftInfoDBCache
{
    public static bool isRecordsCached(string cacheKey)
    {
        Cache dbCache = HttpContext.Current.Cache;

        if (dbCache[cacheKey] == null)
            return false;

        return true;
    }

    public static void Add(string key, object value)
    {
        Cache dbCache = HttpContext.Current.Cache;

        dbCache.Add(key, value, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Default, null);

    }

    public static object Get(string key)
    {
        Cache dbCache = HttpContext.Current.Cache;

        return dbCache[key];
    }

    public static object Remove(string key)
    {
        Cache dbCache = HttpContext.Current.Cache;

        return dbCache.Remove(key);
    }

    public static DataTable GetData(string cacheKey, int startRowIndex, int maximumRowNumber, string sortExpression, string searchCriteria)
    {
        Cache dbCache = HttpContext.Current.Cache;

        if (dbCache[cacheKey] != null)
        {

            DataTable dtble = dbCache[cacheKey] as DataTable;
            DataTable dtblNew = dtble.Clone();

            DataRow[] rows = dtble.Select(searchCriteria, sortExpression);

            if (rows != null)
            {
                if (rows.Count() > 0)
                {
                    if (startRowIndex > rows.Count())
                    {
                        startRowIndex = rows.Count() - maximumRowNumber;

                        if (startRowIndex < 0)
                        {
                            startRowIndex = 1;
                            maximumRowNumber = rows.Count();
                        }
                    }

                    for (int i = startRowIndex - 1; i < (startRowIndex + maximumRowNumber - 1); i++)
                    {
                        if (i < rows.Count())
                            dtblNew.ImportRow(rows[i]);
                    }

                    return dtblNew;
                }
            }

            return dtblNew;

        }

        return null;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:04:10+00:00Added an answer on June 14, 2026 at 2:04 pm
    public static void UpdateShift(string sql)
        {
            SqlConnection dbConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnectionString"].ToString());
            SqlCommand sqlCommand = new SqlCommand(sql, dbConnection);
            sqlCommand.CommandType=CommandType.Text;
            sqlCommand.CommandText=sql;
            dbConnection.Open();
            sqlCommand.Connection = dbConnection;
            //sqlCommand.CommandType = CommandType.Text;
            sqlCommand.ExecuteNonQuery();
            dbConnection.Close();
            ShiftInfoDBCache.Remove(SHIFTINFO_CACHE_KEY);
    
    
        }
    

    Modifying UpdateShift Method in ShiftInfoDB.cs fixed my issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using an ObjectDataSource to bind data to a GridView; it works fine except
Is there a way to update more than one Database having same schema using
I'm using an ObjectDataSource to bind an object to a GridView. In the OnRowDataBound
I'm using a FormView with an ObjectDataSource and binding using <%# Bind(WhateverProp) %> -
I'm creating a gridview using an objectdatasource and it works fine when pulling all
I used bind all GridViews , DetailViews etc. on my page using an ObjectDataSource
How can I access the values passed after an update using the following asp.net
I am using an ASP.NET RadioButton List which is bind with ObjectDatasource as given
I'm using an ObjectDataSource with a 2008 ReportViewer control and Linq to CSV. The
I'm considering using an ObjectDataSource as an intermediate between my page controls and my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.