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

Error in Filtering

9 Answers 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
maggi
Top achievements
Rank 1
maggi asked on 05 Nov 2008, 11:54 AM
Hi,

     I am having trouble using the filtering in RadGrid. my code is as follows

.aspx

 <radG:RadGrid                                                       
                            
                            ID="RadGrid1"
                            runat="server"
                            EnableAJAX="True"
                            Skin="Glassy"
                            Width="97%"
                            AutoGenerateColumns="False"
                            PageSize="3"
                            AllowSorting="True"
                            AllowPaging="True"
                            AllowFilteringByColumn="True"
                            ShowStatusBar="true"
                            >
                            
                            <PagerStyle Mode="Slider"></PagerStyle>
                            <SelectedItemStyle BackColor="PowderBlue"></SelectedItemStyle>
                            <HeaderStyle  BackColor="#0E0997" Height="25px"></HeaderStyle>
                            
                            
                            <MasterTableView
                                DataKeyNames="AssetID"
                                AllowMultiColumnSorting="True"
                                Width="100%"
                                >
                                <ExpandCollapseColumn><HeaderStyle Width="19px"/></ExpandCollapseColumn>
                                <RowIndicatorColumn Visible="False">
                                <HeaderStyle Width="20px"/></RowIndicatorColumn>
                                
                               
                                 
                                <columns>
                                                                               
                                        
                                        <radG:GridBoundColumn SortExpression="PARTNO" HeaderText="PART NUMBER" HeaderButtonType="TextButton"
                                            DataField="PARTNO" UniqueName="PARTNO">
                                        </radG:GridBoundColumn>
                                        <radG:GridBoundColumn SortExpression="HECI-CLEI" HeaderText="HECI-CLEI" HeaderButtonType="TextButton"
                                            DataField="HECI-CLEI" UniqueName="HECI-CLEI">
                                        </radG:GridBoundColumn>
                                        <radG:GridBoundColumn SortExpression="MANUFACTURE" HeaderText="MANUFACTURER" HeaderButtonType="TextButton"
                                            DataField="MANUFACTURE" UniqueName="MANUFACTURE">
                                        </radG:GridBoundColumn>
                                        <radG:GridBoundColumn SortExpression="QUANTITY" HeaderText="QUANTITY" HeaderButtonType="TextButton"
                                            DataField="QUANTITY" UniqueName="QUANTITY">
                                        </radG:GridBoundColumn>
                                        <radG:GridBoundColumn SortExpression="LOCATION" HeaderText="LOCATION" HeaderButtonType="TextButton"
                                            DataField="LOCATION" UniqueName="LOCATION">
                                        </radG:GridBoundColumn>                                        
                                        
                                </columns>
                                   
                            </MasterTableView>
                            <ClientSettings ReorderColumnsOnClient="True" AllowColumnsReorder="True">
                            <Selecting AllowRowSelect="True" />                            
                            </ClientSettings>
                        </radG:RadGrid>

.cs

protected void Page_Load(object sender, EventArgs e)
    {       
        SqlDataSource1.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];       
        SqlDataSource1.ProviderName = "System.Data.SqlClient";
        SqlDataSource1.SelectCommandType = SqlDataSourceCommandType.Text;
        SqlDataSource1.SelectCommand = "SELECT [AssetID] AS 'AssetID',[AssetName] AS 'PARTNO',[HeciClei] AS 'HECI-CLEI',[AltCode] AS 'ATL-CODE',[Manufacturer]    AS 'MANUFACTURE',[Quantity]    AS QUANTITY,[Location] AS 'LOCATION' FROM tbl_Asset";
                
        RadGrid1.DataSourceID = "SqlDataSource1";
        RadGrid1.MasterTableView.DataSourceID = "SqlDataSource1";
       
    }

The problem is that filtering works only once. I would really appritiate if somebody can tell me a way to use filtering without using asp:SqlDataSource i.e. bind grid in code behind


Thanks
maggi






9 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 07 Nov 2008, 12:02 PM
Hello maggi,

To make sure the filtering works as expected, please set the dataSourceID for the control and the masterTableView in the aspx code, as opposed to setting it in the code-behind. Another option is to use NeedDataSource event handler. Either one of these options will allow the control to function normally.

Sincerely yours,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
maggi
Top achievements
Rank 1
answered on 17 Nov 2008, 11:30 AM
Hi,

         i want to put a check for filtering, if no text is entered in the filter textbox the filter function should not work. Can someone tell me if this is possible.

Thanks!

maggi
0
Yavor
Telerik team
answered on 17 Nov 2008, 11:41 AM
Hello maggi,

One possible implementation in this case would be to assign onclick handlers, to keep track of which textboxes are clicked. Another option is to iterate through all the textboxes in the filtering item, and check if there is any text entered, prior to filtering.

Regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
maggi
Top achievements
Rank 1
answered on 17 Nov 2008, 11:46 AM
Hi Yavor,

    Can you tell me how i can assign onclick handler to each filter textbox, or how can i find these textboxes on the serverside or clientside to iterate through it ??

Thanks

maggi
0
Yavor
Telerik team
answered on 17 Nov 2008, 12:09 PM
Hello maggi,

Attached to this message, is a small example.
I hope it helps.

Kind regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
maggi
Top achievements
Rank 1
answered on 18 Nov 2008, 04:01 AM
Hello Yavor,

    Thanks for the example but the problem is that the filters do not work on button click i need to check this when any filter option is selected in the filter menu itself.

Thanks

maggi
0
Yavor
Telerik team
answered on 20 Nov 2008, 02:37 PM
Hello maggi,

There are two options in this case, in general. One is to assign the filter expression manually, and the other is to use the filtering menu. When the filtering menu is used, it will raise the Itemcommand event handler for the control, giving you additional options for customization.
Can you please elaborate how your target functionality differs from these options.

Kind regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
maggi
Top achievements
Rank 1
answered on 21 Nov 2008, 03:28 AM
Hello Yavor,

   Basically what i want is to be able to use regular expression validation and required field validation on the Filters, could u tell me how to go about this. There is one other thing too, I haven't used radgrids pager instead what i have created dynamic paging i retrieve 50 records per page and paging style is 1 2 3 4 5 ...  i.e i send two more parameters to my select query that is pagesize and pagenumber now what happens is when i use a filter the returned record is correct for an exact match it shows single record but my paging remains the same as 1 to 5, where as should it should be 1 only because its just one record. Can you tell me how the filtering works so that i can manipulate it to be able to get just one record instead of all the records.

Thanks & Regards

maggi
0
Yavor
Telerik team
answered on 24 Nov 2008, 02:44 PM
Hello maggi,

The code below shows one possible way to validate the user input for the filtering:

.cs
 protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)  
    {  
        if (e.CommandName == RadGrid.FilterCommandName && ((System.Web.UI.Pair)(e.CommandArgument)).Second.ToString() == "CustomerID")  
        {  
            GridFilteringItem filteringItem = (GridFilteringItem)e.Item;  
            TextBox box = filteringItem["CustomerID"].Controls[0] as TextBox;  
            if (box.Text != "ALFKI")  
            {  
                e.Canceled = true;  
                Label errorMessage = new Label();  
                errorMessage.Text = "Enter a valid value!!!";  
                filteringItem["CustomerID"].Controls.Add(errorMessage);  
            }  
        }  
    } 

I hope this helps.

Regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
maggi
Top achievements
Rank 1
Answers by
Yavor
Telerik team
maggi
Top achievements
Rank 1
Share this question
or