Gridview not refreshing when I'm calling databind method explicitly within if condition
<p>Can someone explain to me what I am doing wrong? </p>

<p>Issue: Application displays conditional information correctly on clicking [Generate] within gridview if page is loaded for the first time.  However, if user opts to generate a date that is earlier than 30 days and [Generate] again, the gridview does not refresh and displays the same information from before (first time). Help!</p>

<p>Source Code: ASPX Page:</p>

<pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="ErrorLogDemoUsingAjax.aspx.cs" Inherits="ErrorLogDemoUsingAjax" validateRequest="false" EnableEventValidation = "false"%&gt;

&lt;%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %&gt;


&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head runat="server"&gt;
    &lt;title&gt;TouchWorks Error Log Application&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id="form1" runat="server"&gt;
        &amp;nbsp;&lt;strong&gt;&lt;span style="font-size: 22pt"&gt;Touchworks User
            &lt;br /&gt;
            Generated Errors Application&lt;/span&gt;&lt;/strong&gt;&lt;hr style="color: black; height: 8px" /&gt;&lt;span style="font-size: 12pt"&gt;
                &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;
        &lt;div&gt;
            &amp;nbsp;&lt;table style="width: 958px; height: 89px"&gt;
                &lt;tr&gt;
                    &lt;td style="width: 144px; height: 32px;"&gt;
                        &lt;strong&gt;Application User:&lt;/strong&gt;&lt;/td&gt;
                    &lt;td style="height: 32px;"&gt;
                        &lt;asp:ScriptManager ID="ScriptManager1" runat="server"&gt;
                            &lt;Services&gt;
                                &lt;asp:ServiceReference Path="AutoComplete.asmx" /&gt;
                            &lt;/Services&gt;
                        &lt;/asp:ScriptManager&gt;
                        &lt;asp:TextBox ID="acUserName" runat="server" Width="189px" OnTextChanged="acUserName_TextChanged"&gt;&lt;/asp:TextBox&gt;
                        &lt;asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="acUserName"
                            ServicePath="AutoComplete.asmx" ServiceMethod="GetUserName" MinimumPrefixLength="3"
                            CompletionSetCount="10"&gt;
                        &lt;/asp:AutoCompleteExtender&gt;
                    &lt;/td&gt;
                    &lt;td rowspan="5" style="width: 48px"&gt;
                        &lt;asp:Panel ID="pHiddenPanel" runat="server" Visible="False"&gt;
                            tbUserName:
                            &lt;br /&gt;
                            &lt;asp:TextBox ID="tbUserName" runat="server" AutoPostBack="True"&gt;&lt;/asp:TextBox&gt;&lt;br /&gt;
                            tbHidden (Description):
                            &lt;asp:TextBox ID="tbHidden" runat="server" AutoPostBack="True"&gt;&lt;/asp:TextBox&gt;&lt;br /&gt;
                            tbStart:
                            &lt;asp:TextBox ID="tbStart" runat="server" AutoPostBack="True"&gt;&lt;/asp:TextBox&gt;&lt;br /&gt;
                            tbEnd:
                            &lt;asp:TextBox ID="tbEnd" runat="server" AutoPostBack="True"&gt;&lt;/asp:TextBox&gt;&lt;br /&gt;
                            &lt;br /&gt;
                            Tmp Error Date:
                            &lt;asp:TextBox ID="tmpErrorDate" runat="server" AutoPostBack="True"&gt;&lt;/asp:TextBox&gt;
                            &lt;br /&gt;
                            Tmp User Name:
                            &lt;asp:TextBox ID="tmpUserName" runat="server" AutoPostBack="True"&gt;&lt;/asp:TextBox&gt;&lt;br /&gt;
                            tmpDescription:
                            &lt;asp:TextBox ID="tmpDescription" runat="server" AutoPostBack="True"&gt;&lt;/asp:TextBox&gt;
                            &amp;nbsp;&amp;nbsp;&lt;br /&gt;
                            tmpRDODesc:
                            &lt;asp:TextBox ID="tmpRDODesc" runat="server" AutoPostBack="True"&gt;&lt;/asp:TextBox&gt;&lt;br /&gt;
                            &lt;br /&gt;
                            Converted Start:
                            &lt;asp:TextBox ID="cnvtdStart" runat="server" AutoPostBack="True"&gt;&lt;/asp:TextBox&gt;&lt;br /&gt;
                            Converted End:
                            &lt;asp:TextBox ID="cnvtdEnd" runat="server" AutoPostBack="True"&gt;&lt;/asp:TextBox&gt;&lt;br /&gt;
                            &lt;br /&gt;
                            maxStart:
                            &lt;asp:TextBox ID="tbMaxStart" runat="server" AutoPostBack="True"&gt;&lt;/asp:TextBox&gt;&lt;br /&gt;
                            maxEnd:
                            &lt;asp:TextBox ID="tbMaxEnd" runat="server" AutoPostBack="True"&gt;&lt;/asp:TextBox&gt;&lt;br /&gt;
                            &amp;nbsp;&lt;asp:TextBox ID="tbRowCount" runat="server" AutoPostBack="True"&gt;&lt;/asp:TextBox&gt;&lt;/asp:Panel&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td style="width: 144px; height: 40px;"&gt;
                        &lt;strong&gt;Seach Error Description:&lt;/strong&gt;&lt;/td&gt;
                    &lt;td style="height: 40px;"&gt;
                        &lt;asp:TextBox ID="tbDescription" runat="server"&gt;&lt;/asp:TextBox&gt;&amp;nbsp;
                    &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td style="width: 144px"&gt;
                        &lt;strong&gt;Start Date:&lt;/strong&gt;&lt;/td&gt;
                    &lt;td&gt;
                        &lt;asp:TextBox ID="tbStartDate" runat="server"&gt;&lt;/asp:TextBox&gt;
                        &lt;asp:Button ID="btnSD" runat="server" OnClick="btnSD_Click" Text="..." /&gt;&lt;br /&gt;
                        &lt;asp:Calendar ID="cdrCalendar" runat="server" BackColor="White" BorderColor="#3366CC"
                            BorderWidth="1px" CellPadding="1" DayNameFormat="Shortest" Font-Names="Verdana"
                            Font-Size="8pt" ForeColor="#003399" Height="200px" OnSelectionChanged="cdrCalendar_SelectionChanged"
                            Visible="False" Width="220px"&gt;
                            &lt;SelectedDayStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" /&gt;
                            &lt;SelectorStyle BackColor="#99CCCC" ForeColor="#336666" /&gt;
                            &lt;WeekendDayStyle BackColor="#CCCCFF" /&gt;
                            &lt;TodayDayStyle BackColor="#99CCCC" ForeColor="White" /&gt;
                            &lt;OtherMonthDayStyle ForeColor="#999999" /&gt;
                            &lt;NextPrevStyle Font-Size="8pt" ForeColor="#CCCCFF" /&gt;
                            &lt;DayHeaderStyle BackColor="#99CCCC" ForeColor="#336666" Height="1px" /&gt;
                            &lt;TitleStyle BackColor="#003399" BorderColor="#3366CC" BorderWidth="1px" Font-Bold="True"
                                Font-Size="10pt" ForeColor="#CCCCFF" Height="25px" /&gt;
                        &lt;/asp:Calendar&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td style="width: 144px"&gt;
                        &lt;strong&gt;End Date: &lt;/strong&gt;
                    &lt;/td&gt;
                    &lt;td&gt;
                        &lt;asp:TextBox ID="tbEndDate" runat="server"&gt;&lt;/asp:TextBox&gt;
                        &lt;asp:Button ID="btnED" runat="server" OnClick="btnED_Click" Text="..." /&gt;
                        &lt;asp:Calendar ID="EndCalendar" runat="server" BackColor="White" BorderColor="#3366CC"
                            BorderWidth="1px" CellPadding="1" DayNameFormat="Shortest" Font-Names="Verdana"
                            Font-Size="8pt" ForeColor="#003399" Height="200px" OnSelectionChanged="EndCalendar_SelectionChanged"
                            Visible="False" Width="220px"&gt;
                            &lt;SelectedDayStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" /&gt;
                            &lt;SelectorStyle BackColor="#99CCCC" ForeColor="#336666" /&gt;
                            &lt;WeekendDayStyle BackColor="#CCCCFF" /&gt;
                            &lt;TodayDayStyle BackColor="#99CCCC" ForeColor="White" /&gt;
                            &lt;OtherMonthDayStyle ForeColor="#999999" /&gt;
                            &lt;NextPrevStyle Font-Size="8pt" ForeColor="#CCCCFF" /&gt;
                            &lt;DayHeaderStyle BackColor="#99CCCC" ForeColor="#336666" Height="1px" /&gt;
                            &lt;TitleStyle BackColor="#003399" BorderColor="#3366CC" BorderWidth="1px" Font-Bold="True"
                                Font-Size="10pt" ForeColor="#CCCCFF" Height="25px" /&gt;
                        &lt;/asp:Calendar&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td style="width: 144px"&gt;
                        &lt;strong&gt;Generate Error Log:&lt;/strong&gt;&lt;/td&gt;
                    &lt;td&gt;
                        &lt;asp:Button ID="btnGenerate" runat="server" Height="27px" OnClick="btnGenerate_Click"
                            Text="Generate" Width="103px" /&gt;
                        &lt;asp:Button ID="Button2" runat="server" Height="26px" OnClick="btnClear_Click" Text="Clear"
                            Width="98px" /&gt;
                        &lt;asp:Button ID="btnExport" runat="server" Height="26px" OnClick="btnExport_Click"
                            Text="Export All to Excel" /&gt;
                        &lt;/td&gt;
                &lt;/tr&gt;
            &lt;/table&gt;
            &lt;br /&gt;
        &lt;/div&gt;
        &lt;hr style="color: black" /&gt;
        &amp;nbsp;&amp;nbsp; &lt;strong&gt;&lt;span&gt;
            &lt;asp:GridView ID="gvDisplayErrorLogData" runat="server" AllowPaging="True" AllowSorting="True"
                AutoGenerateColumns="False" DataSourceID="DisplayErrorLogDataObjectDataSource"
                EmptyDataText="No data exists for current entries" BorderColor="Blue" AlternatingRowStyle-BackColor="#C2D69B"
                HeaderStyle-BackColor="green" BorderStyle="Inset" BorderWidth="5px" OnSelectedIndexChanged="gvDisplayErrorLogData_SelectedIndexChanged"
                Width="1236px" Font-Bold="False" Font-Size="11pt" EnableViewState="False"&gt;
                &lt;Columns&gt;
                    &lt;asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" /&gt;
                    &lt;asp:BoundField DataField="ErrorDate" HeaderText="ErrorDate" ReadOnly="True" SortExpression="ErrorDate" /&gt;
                    &lt;asp:BoundField DataField="Description" HeaderText="Description" ReadOnly="True"
                        SortExpression="Description" /&gt;
                    &lt;asp:BoundField DataField="RDOErrDescription3" HeaderText="RDOErrDescription3" ReadOnly="True"
                        SortExpression="RDOErrDescription3" /&gt;
                    &lt;asp:CommandField SelectText="View" ShowSelectButton="True" /&gt;
                &lt;/Columns&gt;
                &lt;HeaderStyle BackColor="Green" /&gt;
                &lt;AlternatingRowStyle BackColor="#C2D69B" /&gt;
            &lt;/asp:GridView&gt;
            &lt;asp:ObjectDataSource ID="DisplayErrorLogDataObjectDataSource" runat="server" OldValuesParameterFormatString="original_{0}"
                SelectMethod="GetErrorLogData" TypeName="ErrorLogDataSetTableAdapters.Error_LogTableAdapter"&gt;
                &lt;SelectParameters&gt;
                    &lt;asp:ControlParameter ControlID="tbUserName" Name="Username" PropertyName="Text"
                        Type="String" /&gt;
                    &lt;asp:ControlParameter ControlID="tbStartDate" Name="StartDate" PropertyName="Text"
                        Type="DateTime" /&gt;
                    &lt;asp:ControlParameter ControlID="tbEndDate" Name="EndDate" PropertyName="Text" Type="DateTime" /&gt;
                    &lt;asp:ControlParameter ControlID="tbHidden" Name="Description" PropertyName="Text"
                        Type="String" /&gt;
                &lt;/SelectParameters&gt;
            &lt;/asp:ObjectDataSource&gt;
            &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;
            &lt;br /&gt;
            &lt;asp:GridView ID="gvDisplayCompleteDetails" runat="server" AutoGenerateColumns="False"
                DataSourceID="DisplayDetailsObjectDataSource" Font-Size="11pt" EmptyDataText="No Data"
                BorderColor="Blue" BorderStyle="Inset" BorderWidth="5px" Width="1236px" Font-Bold="False"&gt;
                &lt;Columns&gt;
                    &lt;asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" /&gt;
                    &lt;asp:BoundField DataField="Error Date" HeaderText="Error Date" ReadOnly="True" SortExpression="Error Date" /&gt;
                    &lt;asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" /&gt;
                    &lt;asp:BoundField DataField="RDOErrDescription3" HeaderText="RDOErrDescription3" SortExpression="RDOErrDescription3" /&gt;
                &lt;/Columns&gt;
                &lt;AlternatingRowStyle BackColor="#C2D69B" /&gt;
                &lt;HeaderStyle BackColor="Green" /&gt;
            &lt;/asp:GridView&gt;
        &lt;/span&gt;&lt;/strong&gt;
        &lt;asp:ObjectDataSource ID="DisplayDetailsObjectDataSource" runat="server" OldValuesParameterFormatString="original_{0}"
            SelectMethod="GetErrorLogDetailsData" TypeName="ErrorLogDetailsDataSetTableAdapters.Error_LogTableAdapter"&gt;
            &lt;SelectParameters&gt;
                &lt;asp:ControlParameter ControlID="tmpUserName" Name="Username" PropertyName="Text"
                    Type="String" /&gt;
                &lt;asp:ControlParameter ControlID="tmpErrorDate" Name="tmpDateTime" PropertyName="Text"
                    Type="DateTime" /&gt;
                &lt;asp:ControlParameter ControlID="tmpDescription" Name="Description" PropertyName="Text"
                    Type="String" /&gt;
            &lt;/SelectParameters&gt;
        &lt;/asp:ObjectDataSource&gt;
        &amp;nbsp;&amp;nbsp;&amp;nbsp;
        &lt;asp:Panel ID="pHidden" runat="server" Visible="False"&gt;
            &lt;asp:GridView ID="gvFullGridView" runat="server" AutoGenerateColumns="False" DataSourceID="DisplayErrorLogDataObjectDataSource"
                Width="1236px" AlternatingRowStyle-BackColor="#C2D69B" HeaderStyle-BackColor="green"&gt;
                &lt;Columns&gt;
                    &lt;asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" /&gt;
                    &lt;asp:BoundField DataField="ErrorDate" HeaderText="ErrorDate" ReadOnly="True" SortExpression="ErrorDate" /&gt;
                    &lt;asp:BoundField DataField="Expr1" HeaderText="Description" SortExpression="Expr1" /&gt;
                    &lt;asp:BoundField DataField="Expr3" HeaderText="RDODescription3" SortExpression="Expr3" /&gt;
                &lt;/Columns&gt;
                &lt;HeaderStyle BackColor="Green" /&gt;
                &lt;AlternatingRowStyle BackColor="#C2D69B" /&gt;
            &lt;/asp:GridView&gt;
            &lt;asp:ObjectDataSource ID="DisplayFullErrorLogObjectDataSource" runat="server" OldValuesParameterFormatString="original_{0}"
                SelectMethod="GetErrorLogData" TypeName="ErrorLogDataSetTableAdapters.Error_LogTableAdapter"&gt;
                &lt;SelectParameters&gt;
                    &lt;asp:ControlParameter ControlID="tbUserName" Name="Username" PropertyName="Text"
                        Type="String" /&gt;
                    &lt;asp:ControlParameter ControlID="tbStartDate" Name="StartDate" PropertyName="Text"
                        Type="DateTime" /&gt;
                    &lt;asp:ControlParameter ControlID="tbEndDate" Name="EndDate" PropertyName="Text" Type="DateTime" /&gt;
                    &lt;asp:ControlParameter ControlID="tbHidden" Name="Description" PropertyName="Text"
                        Type="String" /&gt;
                &lt;/SelectParameters&gt;
            &lt;/asp:ObjectDataSource&gt;
        &lt;/asp:Panel&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Source Code: C# Page:</p>

<pre><code>using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


public partial class ErrorLogDemoUsingAjax : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            // Check if page is loaded for the first time
            if (!IsPostBack)
            {
                SetDefaultDates();
                gvDisplayErrorLogData.Visible = false;
                gvDisplayCompleteDetails.Visible = false;
                btnExport.Visible = false;
            }
            else 
            {
                //All application processing will be performed within the Generate function.
                //Generate();
            }
        }
        catch 
        {}
    }

    protected void Generate()
    {
        //Grab the dates from the controls on the page
        DateTime dt1 = Convert.ToDateTime(tbStartDate.Text.Trim());
        DateTime dt2 = Convert.ToDateTime(tbEndDate.Text.Trim());

        //DateTime dt1 = Convert.ToDateTime)
        string tmp1 = dt1.ToShortDateString();
        string tmp2 = dt2.ToShortDateString();

        cnvtdStart.Text = tmp1;
        cnvtdEnd.Text = tmp2;

        DateTime tmp3 = DateTime.Now.AddDays(-30);
        DateTime tmp4 = DateTime.Now;

        string tmp5 = tmp3.ToShortDateString();
        string tmp6 = tmp4.ToShortDateString();

        DateTime maxSD = Convert.ToDateTime(tmp5);
        DateTime maxED = Convert.ToDateTime(tmp6);

        tbMaxStart.Text = maxSD.ToShortDateString();
        tbMaxEnd.Text = maxED.ToShortDateString();

        //Ensure date search is valid and does not exceed 30day search window.
        try
        {
            if ((dt1 &lt; maxSD) || (dt2 &gt; maxED))
            {
                if (dt1 &lt; maxSD)
                {
                    gvDisplayErrorLogData.EmptyDataText = "The start dates exceeds a 30-day window";
                    gvDisplayErrorLogData.Visible = true;
                    btnExport.Visible = false;
                    DisplayErrorLogDataObjectDataSource.DataBind(); //Refresh of data in datasource
                    gvDisplayErrorLogData.DataBind();               //Refresh of data in gridview
                    return;
                }
                else if (dt2 &gt; maxED)
                {
                    gvDisplayErrorLogData.EmptyDataText = "End date cannot exceed current date";
                    gvDisplayErrorLogData.Visible = true;
                    btnExport.Visible = false;
                    return;
                }
            }
        }
        catch
        { }

        // Check if this is a date based search
        if ((acUserName.Text == "") &amp;&amp; (tbDescription.Text == ""))
        {
            tbUserName.Text = "%";
            tbHidden.Text = "%";
        }
        // Check if this is a description based search
        else if ((acUserName.Text == "") &amp;&amp; (tbDescription.Text != ""))
        {
            tbUserName.Text = "%";
            tbHidden.Text = "%" + tbDescription.Text + "%";
        }
        // Check if this is user based search
        else if ((acUserName.Text != "") &amp;&amp; (tbDescription.Text == ""))
        {
            tbUserName.Text = "%" + acUserName.Text + "%";
            tbHidden.Text = "%" + tbDescription.Text + "%";
        }
        // Check if this is normal user/description based search
        else if ((acUserName.Text != "") &amp;&amp; (tbDescription.Text != ""))
        {
            tbUserName.Text = "%" + acUserName.Text + "%";
            tbHidden.Text = "%" + tbDescription.Text + "%";
        }

        tbRowCount.Text = gvDisplayErrorLogData.Rows.Count.ToString();

        // Do not display the export button if the dataset returned an empty set
        if (gvDisplayErrorLogData.Rows.Count == 0)
        {
            btnExport.Visible = false;
        }
        else
        {
            btnExport.Visible = true;

        }

        gvDisplayErrorLogData.Visible = true; 
        return;
    }

    protected void SetDefaultDates()
    {
        DateTime dtSD = DateTime.Now.AddDays(-30);
        DateTime dtED = DateTime.Now;

        //Dates are to be displayed in mm/dd/yyyy format
        tbStartDate.Text = dtSD.ToShortDateString();
        tbEndDate.Text = dtED.ToShortDateString();

        //Provide dummy dates for the initial query to run which will return no data results
        tbStart.Text = tbStartDate.Text;
        tbEnd.Text = tbEndDate.Text;
    }

    protected void btnSD_Click(object sender, EventArgs e)
    {
        try
        {
            if (tbStartDate.Text.Trim() != "")
                cdrCalendar.SelectedDate = Convert.ToDateTime(tbStartDate.Text);
        }
        catch
        { }
        cdrCalendar.Visible = true;  
    }
    protected void btnED_Click(object sender, EventArgs e)
    {
        try
        {
            if (tbEndDate.Text.Trim() != "")
                EndCalendar.SelectedDate = Convert.ToDateTime(tbEndDate.Text);
        }
        catch
        { }
        EndCalendar.Visible = true;  

    }
    protected void cdrCalendar_SelectionChanged(object sender, EventArgs e)
    {
        string start = cdrCalendar.SelectedDate.ToString("MM/dd/yyyy");
        tbStartDate.Text = start;
        tbStart.Text = tbStartDate.Text;
        cdrCalendar.Visible = false;
    }
    protected void EndCalendar_SelectionChanged(object sender, EventArgs e)
    {
        try
        {
            string end = EndCalendar.SelectedDate.ToString("MM/dd/yyyy");
            tbEndDate.Text = end;
            tbEnd.Text = tbEndDate.Text;
            EndCalendar.Visible = true;  
        }
        catch
        { }
    }

    protected void btnGenerate_Click(object sender, EventArgs e)
    {
        try
        {
            Generate();
            tbRowCount.Text = gvDisplayErrorLogData.Rows.Count.ToString();
            if (gvDisplayErrorLogData.Rows.Count == 0)
            {
                btnExport.Visible = false;
            }
            else
            {
                gvDisplayErrorLogData.Visible = true;
                btnExport.Visible = true;
            }
        }
        catch
        { } 
    }

    protected void btnClear_Click(object sender, EventArgs e)
    {
       tbDescription.Text = "";
       acUserName.Text = "";
       tbHidden.Text = "";
       tbUserName.Text = "";
       acUserName.Text = "";
       tmpUserName.Text = "";
       tmpErrorDate.Text = "";
       tmpDescription.Text = "";
       tmpRDODesc.Text = "";
       tbRowCount.Text = "";

       cdrCalendar.Visible = false;
       EndCalendar.Visible = false;
       btnExport.Visible = false;

       gvDisplayErrorLogData.Visible = false;
       gvDisplayCompleteDetails.Visible = false;
       SetDefaultDates();
   }
    protected void gvDisplayErrorLogData_SelectedIndexChanged(object sender, EventArgs e)
    {
        try 
        { 
            string selectedItemText1 = gvDisplayErrorLogData.SelectedRow.Cells[0].Text;
            string selectedItemText2 = gvDisplayErrorLogData.SelectedRow.Cells[1].Text;
            string selectedItemText3 = gvDisplayErrorLogData.SelectedRow.Cells[2].Text; 
            string selectedItemText4 = gvDisplayErrorLogData.SelectedRow.Cells[3].Text; 

            gvDisplayCompleteDetails.Visible = true;
            tmpUserName.Text = selectedItemText1;
            tmpErrorDate.Text = selectedItemText2;
            tmpDescription.Text = "%"+selectedItemText3+"%";
            tmpRDODesc.Text = "%"+ selectedItemText4+"%";

            //DisplayErrorLogDataObjectDataSource.DataBind(); //Refresh of data in datasource
            //gvDisplayErrorLogData.DataBind();               //Refresh of data in gridview
        }
        catch 
        {}
     }
    protected void acUserName_TextChanged(object sender, EventArgs e)
    {
    }

    public override void VerifyRenderingInServerForm(Control control)
    {
    }

    private void ExportToExcel(string strFileName, GridView dg)
    {
        Response.Clear();
        Response.Buffer = true;
        Response.ContentType = "application/vnd.ms-excel";
        Response.Charset = "";
        this.EnableViewState = false;
        System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

        gvFullGridView.RenderControl(oHtmlTextWriter);

        Response.Write(oStringWriter.ToString());
        Response.End();
    }

    protected void btnExport_Click(object sender, EventArgs e)
    {
        ExportToExcel("Error_Log.xls", gvFullGridView);
    }
}
</code></pre>
