We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Filter gridview using ajax calendarextender

arcross
arcross asked
on
Medium Priority
2,091 Views
Last Modified: 2012-05-07
Hello,
ive got  a gridview that has an objectdatasource with a parameter to filter by a date.
Also, i ve added an ajax calendar extender.
Id like to click that calendar and my object source to see that it has change and the filter it.

any ideas?
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
What type of parameter is the date filter on the ObjectDataSource?  Does clicking on the calendar post-back the page?  Do you have asych post-back triggers?

Author

Commented:
no it doesnt post the page back.
What it does it selects the date from the calendar and inserts it into a textbox. All that is implemented by the ajax calendar extender.
So i would need somehow to trigger the selection and postback the page?? or something like that
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
Can you show me the HTML for the calendar extender, and the ObjectDataSource?

Author

Commented:
It is the third example in this page:
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/Calendar/Calendar.aspx


 <asp:TextBox ID="txt_date" runat="server" Height="22px" Width="90px"></asp:TextBox>
        <cc1:CalendarExtender ID="TextBox1_CalendarExtender" 
            runat="server" 
            CssClass="Mycalendar" 
            Enabled="True" 
            TargetControlID="txt_date"
            PopupButtonID="imgbtn_calendar">
        </cc1:CalendarExtender>

Open in new window

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
Code-behind:  


Imports System.Data
 
Partial Class _Default
    Inherits System.Web.UI.Page
 
    Protected Sub SqlDataSource1_Selecting(ByVal sender As Object, ByVal e As SqlDataSourceSelectingEventArgs)
        If e.Command.Parameters(0).Value Is Nothing Then
            e.Command.Parameters(0).Value = ""
        End If
    End Sub
 
    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
        Dim dv As DataView = TryCast(Me.SqlDataSource1.[Select](DataSourceSelectArguments.Empty), DataView)
        Dim drv As DataRowView = dv(Me.GridView1.SelectedIndex)
        Dim dt As DateTime = DateTime.Parse(drv("StartDate").ToString())
 
        Me.txt_date.Text = dt.ToShortDateString()
    End Sub
 
    Protected Sub ClearButton_Click(ByVal sender As Object, ByVal e As EventArgs)
        Me.txt_date.Text = ""
    End Sub
 
End Class

Open in new window

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
CSS style sheet:


.Mycalendar .ajax__calendar_container
{
	color: Blue;
	background-color: White;
	border:1px solid #646464;
}
 
.Mycalendar .ajax__calendar_other 
{
	color:  Green;
	background-color:  Yellow;
}
 
.Mycalendar .ajax__calendar_days
{
	color:  Black;
	background-color:  #f0f0f0;
}

Open in new window

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
Points of interest:

1) Set the TextBox.AutoPostBack = True

2) Set the Asynchronous post-back for the UpdatePanel to the TextBox:

        <Triggers>
          <asp:AsyncPostBackTrigger ControlID="txt_date" />
        </Triggers>

3) When the TextBox.Text value changes, the page will post back, and rebind the SqlDataSource to the GridView, with the new date value in the SelectCommand's parameters.

Author

Commented:
hey thanks! thats looking good.
ill try it tomorrow

Author

Commented:
that worked very good!! ...but it gives me a problem..ive got delete and edit commands in that grid and now they are not reacting...

any ideas?

Author

Commented:
it does work now after i recreated it.
thanks!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.