Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calendar Control to Filter GridView . . .

Status
Not open for further replies.

proximity

Technical User
Sep 19, 2002
132
GB
Hi,

I want to filter records in a grid view using the calendar control . . . . I can get it to work using a text box, but using the calendar is totally eluding me :(
Any assistance will be greatly appreciated . . .

If it helps, the date (REPOT_DATE) is returned like this example: 23-11-2012

This is what my page looks like:

<asp:Calendar ID="calRepotDate"
runat="server"
FirstDayOfWeek="Sunday"
SelectionMode="DayWeek"
ShowGridLines="True"
ShowNextPrevMonth="False">
</asp:Calendar>

<asp:GridView ID="grdRepotDailySummary" runat="server"
AutoGenerateColumns="False" DataSourceID="odsRepotDailySummary" AllowPaging="True">
<Columns>
<asp:BoundField DataField="PAL_FACTOR" HeaderText="PAL_FACTOR" SortExpression="PAL_FACTOR" />
<asp:BoundField DataField="PICK_MIN" HeaderText="PICK_MIN" SortExpression="PICK_MIN" />
<asp:BoundField DataField="REPOT_DATE" HeaderText="REPOT_DATE" SortExpression="REPOT_DATE" />
</Columns>
</asp:GridView>

<asp:ObjectDataSource ID="odsRepotDailySummary" runat="server"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
TypeName="RepotsTableAdapters.REPOTS_DAILY_SUMMARY"
FilterExpression="REPOT_DATE = '{0}' ">

<FilterParameters>
<asp:ControlParameter Name="REPOT_DATE" ControlID="calRepotDate" PropertyName="SelectedDate" />
</FilterParameters>
</asp:ObjectDataSource>
 
This is why I stay away from those lousy DataSource controls. They are only good in the most simplest of tasks. Once you deviate, and something becomes a bit more complex, they either fail, or are just to complicated to use.

My suggestion: Write a stored procedure. In the stored procedure, do your filtering and sorting. Much simpler and easier to maintain.
 
It looks like you're treating a date as a string. You will need to ensure the calendar control's selected date is in the format you're expecting. I suspect it is not. I don't know of a format property in the control, but you can make up a hidden field in the page and set it to the formatted date on selected date changed in the calendar control, then have your data source use that.

good luck!


-Mark

 
Hi - thanks for the replies: they pointed me in the right direction. What I did was have a text box and a calendar icon. Click the icon, calendar opens. Choose date, it goes to the text box and that feeds the filter. Works nicely.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top