Solved

Getting a gridview to refresh to reflect change in parameters

Posted on 2011-09-30
2
364 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

740 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