This is a migrated thread and some comments may be shown as answers.

Filter Template

6 Answers 73 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nelson
Top achievements
Rank 1
Nelson asked on 23 May 2012, 09:27 AM
Hi, 

I created a date range filter template in the grid and i would like to check the date range whether it is larger than a year or not when user click on the button on RadToolBar to do the export. The system should allow user to select the date range larger than a year if they only view the data on screen but not doing the export. How can i get the value in the datepicker in the filter template in the javascript?

javascript coding as below (seem TryCast(Container,GridItem) cannot reference to the datepicker in filter template)

    function OnClientButtonClickingHandler(sender, eventArgs) {
        if (eventArgs.get_item().get_value() == "Excel") {
            var startDate = $find('<%# TryCast(Container,GridItem).FindControl("dfFromDate").ClientID %>');
            var endDate = $find('<%# TryCast(Container,GridItem).FindControl("dfToDate").ClientID %>');
            //alert(startDate.get_selectedDate())
            var NoOfMonth = DateDiff.inMonths(startDate, endDate);


            if (NoOfMonth >= 6) {
                alert('Please select the date range within  A YEAR for export purpose!');
                eventArgs.set_cancel(true);
            }
        }
    }   

Thanks.

Cheers, 
Nelson

6 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 28 May 2012, 09:00 AM
Hi,

You should not have problems using this approach. The same approach is used in this online demo application.

Could you share your RadGrid declaration? Thus anyone who wants to help you will have better understanding of your project.

All the best,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Nelson
Top achievements
Rank 1
answered on 28 May 2012, 09:46 AM
Hi,

The following is the error that i got

Value of type 'System.Web.UI.Page' cannot be converted to 'Telerik.Web.UI.GridItem'.

I think the main problem is on "TryCast(Container,GridItem)" as i placed this javascript code outside the Grid Control. If i placed the javscript within the "<FilterTemplate>" tab, the "Container" is referring to the "GridItem". But if i placed it outside the grid control, the container is referring to the page object. So my question is how can i refer to the grid item just outside the grid control?

Thanks.

Cheers, 
Nelson
0
Andrey
Telerik team
answered on 29 May 2012, 01:48 PM
Hello,

The Container property as its name suggest gives the container of the element. If the control is placed directly on the page, then it is normal the Page to be returned as a container.

It is best to access GridItems in Grid events like ItemDataBound/ItemCreated because they are raised for every item in RadGrid. Thus you could easily access all the information that is stored in the GridItem object.

If you want to access Grid items outside of RadGrid event you need to make sure that you are accessing the items late enough so they are created and bound, for example Page_PreRender:

protected void Page_PreRender(object sender, EventArgs e)
{
    foreach (GridFilteringItem filteringItem in RadGrid1.MasterTableView.Items)
    {
        //do your custom logic here....
    }
}

However, placing the filter templates controls outside of RadGrid is meaningless because then they will not be loaded in the filter template and you will get into a lot more trouble only to get the filtering working.

Greetings,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Nelson
Top achievements
Rank 1
answered on 30 May 2012, 02:10 AM
Hi,

Maybe i am not making it clear enough and let me make it short. 

I have a radtoolbar and a radgrid with a date range filter template within there. I would like to check whether the date range is within a year when user click on the button in radtoolbar, can i do that? Please give me some sample code if it can.

Thanks a lot.

Cheers, 
Nelson
0
Accepted
Andrey
Telerik team
answered on 31 May 2012, 04:40 PM
Hi,

You could use the approach shown in this online demo application(Look for the FromDateSelected function) . Once you get the both dates you could find their difference as shown in this online resource. Thus you will be able to check whether the date range is within an year.

All the best,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Nelson
Top achievements
Rank 1
answered on 01 Jun 2012, 03:08 AM
Thks.....solved finally.

Cheers, 
Nelson
Tags
Grid
Asked by
Nelson
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Nelson
Top achievements
Rank 1
Share this question
or