Error in Filtering

10 posts, 0 answers
  1. maggi
    maggi avatar
    58 posts
    Member since:
    Mar 2007

    Posted 05 Nov 2008 Link to this post

    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






  2. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 07 Nov 2008 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. maggi
    maggi avatar
    58 posts
    Member since:
    Mar 2007

    Posted 17 Nov 2008 Link to this post

    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
  5. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 17 Nov 2008 Link to this post

    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.
  6. maggi
    maggi avatar
    58 posts
    Member since:
    Mar 2007

    Posted 17 Nov 2008 Link to this post

    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
  7. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 17 Nov 2008 Link to this post

    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.
  8. maggi
    maggi avatar
    58 posts
    Member since:
    Mar 2007

    Posted 17 Nov 2008 Link to this post

    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
  9. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 20 Nov 2008 Link to this post

    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.
  10. maggi
    maggi avatar
    58 posts
    Member since:
    Mar 2007

    Posted 20 Nov 2008 Link to this post

    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
  11. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 24 Nov 2008 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017