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

[Solved] CommandItemTemplate & Parameter

1 Answer 140 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 10 Jun 2009, 10:15 AM
Hi,
I have a commanditemtemplate which contains 2 raddatepickers.
Is is possible to use the values of these datepickers as parameter values for the datasource of the grid ?

I set the grid datasource within Page_load
        With myDataSource  
            .ConnectionString = dataConnectionString  
            .SelectCommand = "usp_GRID_Maintenance" 
            .SelectCommandType = SqlDataSourceCommandType.StoredProcedure  
            .SelectParameters.Clear()  
            .SelectParameters.Add("Start", System.TypeCode.String, FormatDateTime(dtpLower.SelectedDate, DateFormat.ShortDate))  
            .SelectParameters.Add("End", System.TypeCode.String, FormatDateTime(dtpUpper.SelectedDate, DateFormat.ShortDate))  
            .SelectParameters.Add("option", System.TypeCode.Boolean, optRenewal.Checked)  
        End With 

I realise i can access the controls within the grid_ItemCreated, however this is called after the above code!
The reason for attempting this is so i can remove any controls within the page that relate to the grid, and purely use the grid with its own controls.

Mark

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 12 Jun 2009, 02:12 PM
Hello Mark,

The functionality you are describing is achievable, but you need to ensure that there is a default value for the parameter you are using that is given from the date pickers. The reason for this is that RadGrid binds to its data source before throwing the ItemCreated and ItemDataBound events. This means that the GridCommandItem is created only after binding to RadGrid. Therefore, you need to have some default values before initializing your date picker.

Most commonly, the approach is to set a Session variable that RadDatePicker  would change. But when binding RadGrid, if your session variable is null, you need to use some default data to bind RadGrid to.

This approach is demonstrated in the sample project I am attaching. You can see that in RadGrid's NeedDataSource event I am checking if I have a selectedDate property already set by RadDatePicker. If not, I am binding to all the data items from the data source, otherwise I am filtering by this property.

Best wishes,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or