Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting a gridview to refresh to reflect change in parameters

Posted on 2011-09-30
2
Medium Priority
?
370 Views
Last Modified: 2013-12-16
I have a gridview that uses an object data source that has parameters linked to two date fields on the page.  

 I set the date values in page load, but when the page first loads, the query in the object data source, GetIssueDetails, says the date is 1/1/0001.  

Then I set the dates on the form and click a button that does a databind for the gridview, and the date in GetIssueDetails is still 1/1/001.  

If is set the dates in GetIssueDetails, the gridview shows the data for that date range.

How come GetIssueDetails isn't seeing the date values I expect?

    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
        OldValuesParameterFormatString="original_{0}" SelectMethod="GetIssueDetails"
        TypeName="Issues">
        <SelectParameters>
            <asp:FormParameter DefaultValue="" FormField="txtStartDate" Name="StartDate"
                Type="DateTime" />
            <asp:FormParameter FormField="txtEndDate" Name="EndDate" Type="DateTime" />
        </SelectParameters>
    </asp:ObjectDataSource>

    <asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1"
        EnableModelValidation="True">
    </asp:GridView>

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.txtStartDate.Text = DateTime.Today.ToShortDateString();
            this.txtEndDate.Text = DateTime.Today.ToShortDateString();
        }
    }
    protected void btnViewDetails_Click(object sender, EventArgs e)
    {
        this.GridView1.DataBind();
    }

    public static DataSet GetIssueDetails(DateTime StartDate, DateTime EndDate)
    {
        DateTime MinDate = DateTime.Parse("1/1/2011");
        string selectSQL;

        if (DateTime.Compare(StartDate, MinDate) < 0)
        {
            StartDate = DateTime.Today;
            EndDate = StartDate;
        }
0
Comment
Question by:Barry Sweezey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 36897007
I usually find that most of my problems with ASP.NET is when I forget about the page life cycle.  Since I don't use the ObjectDataSource, I am not sure when it calls the SelectMethod, but my guess from your testing is that it is before the values are set.

...or...

When the page is first loaded, there will not be a form field, and on post-back, the value is retrieved from the view state.
0
 
LVL 8

Accepted Solution

by:
jagrut_patel earned 2000 total points
ID: 36908183
1. Subscribe to the OnSelecting event of the ObjectDataSource

<asp:ObjectDataSource ID="ObjectDataSource1"..... OnSelecting="ObjectDataSource1_Selecting">

Open in new window


2. Implement ObjectDataSource1_Selecting

protected void ObjectDataSource1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
    e.InputParameters["StartDate"] = this.txtStartDate.Text;
    e.InputParameters["EndDate"] = this.txtEndDate.Text;
}

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question