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

When I try to filter a column in my RadGrid it comes back empty (no rows)

30 Answers 1469 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Acadia
Top achievements
Rank 1
Iron
Acadia asked on 03 Sep 2008, 01:53 PM
I can't seem to find any examples of how to filter Rad Grid rows using the built-in filters.  I have the filters setup but they empty my grid.  I just want to be able to perform simple filters on all rows.  Any help would be appreciated.

Thanks

30 Answers, 1 is accepted

Sort by
0
Kevin Babcock
Top achievements
Rank 1
answered on 03 Sep 2008, 06:34 PM
Hello Acadia,

Have you tried the online demos? They offer some great filtering examples, which you can use as a starting point for getting filtering into your RadGrid. You can also check out these help articles which offer great tutorials on how to implement filtering in your RadGrid.

I hope this helps. If you have a more specific questions, I'd be glad to help you further.

Regards,
Kevin Babcock
0
Shinu
Top achievements
Rank 2
answered on 04 Sep 2008, 05:32 AM
Hi Acadia,

How do you bind the Grid? The built-in filtering feature is not supported when you use Simple data-Binding (calling DataBind()). You can refer the following online demo to get more details about AdvanceDataBinding techniques.
Advanced data-binding

Shinu


0
Acadia
Top achievements
Rank 1
Iron
answered on 04 Sep 2008, 10:52 AM
Darn, I use straight databinding.  Why doesn't it work with this type of databinding?  I don't really know of any other way to databind my grids that we use here and I don't want to overcomplicate things.

Public Sub GetData()

Dim ds As New DataSet

Dim OraDa As New OracleDataAdapter("Procedure1", dbConnect.OraCianbroC9i)

OraDa.SelectCommand.CommandType = CommandType.StoredProcedure

'Output Parameters

OraDa.SelectCommand.Parameters.Add(

New OracleParameter("pResults", OracleType.Cursor)).Direction = ParameterDirection.Output

OraDa.SelectCommand.Parameters.Add(

New OracleParameter("pNum", OracleType.VarChar)).Value = rcCn.SelectedValue

OraDa.Fill(ds)

'Set Datasource

rgT.DataSource = ds.Tables(0)

rgT.Rebind()

End Sub

0
Acadia
Top achievements
Rank 1
Iron
answered on 04 Sep 2008, 10:56 AM
Actually I think I know how to do this based on one of those articles.  I'll try it out later.  Thanks to both of you!
0
Princy
Top achievements
Rank 2
answered on 04 Sep 2008, 11:16 AM
Hi Acadia,

Try binding the Grid in the NeedDataSource event. This event will be fired on the filtering the columns. Also set AllowFilteringByColumn to true in the aspx.

telerik:radgrid id="RadGrid1"  AllowFilteringByColumn="True"   runat="server"  onneeddatasource="RadGrid1_NeedDataSource" > 
          


Regards
Princy.
0
Robert Schoen
Top achievements
Rank 1
answered on 09 Jan 2009, 10:20 PM
I have a similar problem.  My project has been upgraded from.Net2.0 to 3.5.   When I upgraded my controls the filter on the grid no longer functioned.  When I would try to filter the results I would not get any results.  My grid is bound to an Object datasource that is connected to a typestrong dataadapter.  I don't have any source code in the form that references the grid.  As a shot in the dark I changed the Telerik.Web.UI.dll from 2008.3.1308.35 to 2008.3.1308.20 and this seems to have worked.  I am assuming that this is just a work around and masking the real problem.  I suspect that I am missing a reference do to me upgrading my project.    Can someone give me feed back on this.
0
Yavor
Telerik team
answered on 10 Jan 2009, 07:17 AM
Hello Robert,

Changing the reference back to 2008.3.1308.20  simply causes the old version of the controls, the classic controls, to be used.
I think the source of the issue is the way the control is populated with data - this is also demonstrated by the problem that you described.
If the issue persists, you can open a formal support ticket, and send the problematic code, in the form of a small working project, to us, for further investigation.

Sincerely yours,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jurgen
Top achievements
Rank 1
answered on 26 Jan 2009, 11:21 AM
I have the same problem. I am currently evaluating a trial-version of the ASP.NET AJAX control set.

I declare my grid in the ASPX file and when a button is hit, i populate the grid according to some options that are set.
My grid is embedded in a multipageview and is ajaxified.
I do the binding as follows:

List<CustomObject> ProductionQuantity = new List<CustomObject> .... ;   
//populate list
Grid.DataSource = ProductionQuantity;  
Grid.DataBind(); 

Everything seems to be normal, but when i use the built-in filter, I got no result and the grid is empty.

When I run trough the above code again, the grid shows the results as it should, with the filter applied as I wanted.
I have the same problem with sorting, paging... 
I think it has something to do with the databinding and client-side events. 

I've already spent a lot of time reading manuals and demo's
Can someone help me out?

thx
0
Yavor
Telerik team
answered on 26 Jan 2009, 02:48 PM
Hi Jurgen,

Indeed, in this case the control will not be filtered as expected. The reason for this is that you are using simple databinding. You can either use the advanced databinding approach, or a declarative datasource.

Greetings,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jurgen
Top achievements
Rank 1
answered on 27 Jan 2009, 02:12 PM
Thx, but you inspired me to solve it differently

After I assigned the datasource to the grid, I save the datasource object in a session variable.
In the NeedDataSource event, I assign it again to the grid.
Everything works out fine.


Greetz
0
newbie
Top achievements
Rank 1
answered on 06 Mar 2009, 10:53 PM
I am having a similar problem.

I use the Rebind() to bind my grid to a datasource on click of a search button.

I also put my datasource in view state and tried assigning the datasource to the grid again on NeedDatasource event.
But my filter still does not apply.
My grid loads with the initial values.

how can I solve this?
0
Yavor
Telerik team
answered on 09 Mar 2009, 07:40 AM
Hi,

Based on this information, it is hard to determine what may be causing the filters to fails.
If the issue persists, you can open a formal support ticket, and send us the problematic code, in the form of a small working project, for additional testing.

Kind regards,
Yavor
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.
0
Kevin Kembel
Top achievements
Rank 1
answered on 17 Nov 2009, 03:51 AM
I'm having a similar issue, but I'm using the NeedDataSource eventhandler, and I'm assigning the data source an IQueryable<> object.  It works fine except for the filter, no matter what I filter on, the grid turns up blank (and setting it back to No Filter will show the entire result set again).  Stepping through it, when I filter, the eventhandler is fired correctly, and the datasource is set completely (I don't filter it programmatically, I assumed the grid did that).
0
Yavor
Telerik team
answered on 19 Nov 2009, 08:57 AM
Hello Kevin,

To properly pinpoint the source of the problem, please send us a small project, demonstrating your setup, in a formal support ticket. Upon reviewing it, we will get back to you with additional information.

Kind regards,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Kevin Kembel
Top achievements
Rank 1
answered on 07 Dec 2009, 12:05 AM
Sorry, kind of embarrassing, but I didn't realize the search would be case sensitive (since when binding to SQL Server, my collation is case-insensitive).  It works fine filtering, and changing the GroupSettings of the RadGrid makes the filter case insensitive.

Kevin
0
Robert Schoen
Top achievements
Rank 1
answered on 19 Apr 2011, 06:02 PM

Here is my big lesson learned.   There were 2 things that I needed to do to get the filters to work the way I needed them to.  
First is I needed to specify the data types for each column that I needed to filter.  This is what actually solved my initial problem.   

Second was that I needed to turn off the LINQ Expressions (EnableLinqExpressions = "False").   The second was not related to my initial question but it was important to know.   By turning off the LINQ Expressions the searches are no longer case sensitive. 

0
Kamal
Top achievements
Rank 1
answered on 06 Nov 2014, 07:35 AM
Hello Kevin

I have same problem in my grid.
I've followed the online demos. Sorting, paging, editing works properly. But I'm hitting the wall for last 2-3 days while applying filters and the "Add new record" does not work (no popup and all). I'll deeply appreciate if point me to right direction. Here is the attached file (isolated to some extent). Please help.
0
Kamal
Top achievements
Rank 1
answered on 06 Nov 2014, 07:46 AM
No able to attached file. Its a 6 kb zipped file but getting "The selected file(s) cannot be attached because it may exceed the maximum attachment size (2 MB) or is from not allowed type (allowed: .gif, .jpg, .jpeg, .png)."

Anyways, here is the code:

[Applications.aspx]       
<form id="form1" runat="server">
<div>
<asp:CheckBox ID="chkshowinactive" runat="server" Visible="true"
                Text="Show Inactive" CausesValidation="false"
                Checked="false" OnCheckedChanged="rad_needpermssion_SelectedIndexChanged"
                AutoPostBack="True" CssClass="Checkbox" />
            <br />
            <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
            <telerik:RadSkinManager ID="QsfSkinManager" runat="server" ShowChooser="true" />
            <telerik:RadFormDecorator ID="QsfFromDecorator" runat="server" DecoratedControls="All" EnableRoundedCorners="false" />
            <p id="divMsgs" runat="server">
                <asp:Label ID="Label1" runat="server" EnableViewState="False" Font-Bold="True" ForeColor="#FF8080">
                </asp:Label>
                <asp:Label ID="Label2" runat="server" EnableViewState="False" Font-Bold="True" ForeColor="#00C000">
                </asp:Label>
            </p>
            <telerik:RadCodeBlock ID="RadCodeBlock2" runat="server">
                <script type="text/javascript">
                    function RowDblClick(sender, eventArgs) {
                        sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());
                    }

                    function onPopUpShowing(sender, args) {
                        args.get_popUp().className += " popUpEditForm";
                    }
                </script>
            </telerik:RadCodeBlock>
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="RadGrid1">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
                            <telerik:AjaxUpdatedControl ControlID="divMsgs"></telerik:AjaxUpdatedControl>
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>
            <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
            <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" ShowFooter="True"
                AllowSorting="True" AutoGenerateColumns="False" ShowStatusBar="True"
                OnPreRender="RadGrid1_PreRender" OnNeedDataSource="RadGrid1_NeedDataSource" OnUpdateCommand="RadGrid1_UpdateCommand"
                OnInsertCommand="RadGrid1_InsertCommand" OnDeleteCommand="RadGrid1_DeleteCommand" OnItemDataBound="RadGrid1_ItemDataBound" 
                AllowFilteringByColumn="True" CellSpacing="-1" GridLines="Both" OnItemCommand="RadGrid1_ItemCommand">
                <PagerStyle Mode="NextPrevAndNumeric" />
                <HeaderStyle Font-Bold="true" />
                <MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="AppID">
                    <EditFormSettings>
                        <PopUpSettings Modal="true" />
                    </EditFormSettings>
                    <Columns>
                        <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" />
                        <telerik:GridBoundColumn Visible="false" SortExpression="AppID" DataField="AppID"
                            HeaderText="AppID" ItemStyle-VerticalAlign="Top" />
                        <telerik:GridBoundColumn Visible="true" SortExpression="AppName" DataField="AppName"
                            HeaderText="Application Name" ItemStyle-VerticalAlign="Top" />
                        <telerik:GridBoundColumn Visible="true" SortExpression="NoOfPermTypes" DataField="NoOfPermTypes"
                            HeaderText="# of Permission Types" ItemStyle-VerticalAlign="Top" />
                        <telerik:GridBoundColumn Visible="true" SortExpression="Active" DataField="Active"
                            HeaderText="Active" ItemStyle-VerticalAlign="Top" />
                        <telerik:GridBoundColumn Visible="true" SortExpression="WebBased" DataField="WebBased"
                            HeaderText="Web Based" ItemStyle-VerticalAlign="Top" />
                        <telerik:GridBoundColumn Visible="true" SortExpression="ModifiedOn" DataField="ModifiedOn"
                            HeaderText="Modified On" ItemStyle-VerticalAlign="Top" />
                        <telerik:GridBoundColumn Visible="true" SortExpression="ModifiedBy" DataField="ModifiedBy"
                            HeaderText="Modified By" ItemStyle-VerticalAlign="Top" />
                    </Columns>
                    <EditFormSettings EditFormType="Template">
                        <FormTemplate>
                            <table id="Table2" cellspacing="2" cellpadding="1" width="100%" border="0" rules="none"
                                style="border-collapse: collapse;">
                                <tr>
                                    <td>
                                        <table id="Table3" cellspacing="1" cellpadding="1" border="0" class="module">
                                            <tr>
                                                <td></td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td>Application Name:</td>
                                                <td>
                                                    <asp:TextBox ID="txtAppName" runat="server" Text='<%# Bind("AppName") %>' />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>Web Based:
                                                </td>
                                                <td>
                                                    <asp:CheckBox ID="chkWebBased" runat="server" Checked='<%# Bind("WebBased") %>' TabIndex="7" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>Active:
                                                </td>
                                                <td>
                                                    <asp:CheckBox ID="chkActive" runat="server" Checked='<%# Bind("Active") %>' TabIndex="7" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>Notes:
                                                </td>
                                                <td>
                                                    <asp:TextBox ID="txtModifiedDescription" Text='<%# Bind("ModifiedDescription") %>' runat="server" TextMode="MultiLine"
                                                        Rows="5" Columns="40" TabIndex="5">
                                                    </asp:TextBox>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right" colspan="2">
                                        <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                            runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'></asp:Button>
                                        &nbsp;
                                        <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                                            CommandName="Cancel"></asp:Button>
                                        </td>
                                </tr>
                            </table>
                        </FormTemplate>
                    </EditFormSettings>
                </MasterTableView>
                <ClientSettings>
                    <ClientEvents OnRowDblClick="RowDblClick" OnPopUpShowing="onPopUpShowing" />
                </ClientSettings>
            </telerik:RadGrid>
</div>
    </form>












0
Kamal
Top achievements
Rank 1
answered on 06 Nov 2014, 08:21 AM
AppPermission objApp = new AppPermission();
        Users objusers = new Users();
        string strFilters = "";

        public DataTable BindApplications()
        {
            DataTable dtApp;

            //the table index (.Tables[1]) in the below statement is done 
            //for TEMPORARY SUPPORT of old UPM and must changed back to (.Tables[0]) 
            //after this new UPM is rolled OUT
            /********************************************************************************************************************************************/
            dtApp = objApp.ListApplications().Tables[1];
            /********************************************************************************************************************************************/

            string SortExpression = "";
            string SortDirection = "";

            if (Session["ASE"] != null)
                SortExpression = Session["ASE"].ToString();
            if (Session["ASD"] != null)
                SortDirection = Session["ASD"].ToString();
            if (SortExpression == "")
                SortExpression = "AppName";
            if (SortDirection == "Descending")
                SortDirection = "Desc";
            else
                SortDirection = "Asc";

            DataView aView = dtApp.DefaultView;
            if (SortExpression != "")
                aView.Sort = SortExpression + " " + SortDirection;

            bool bActive = true;
            bActive = (chkshowinactive.Checked) ? false : true;
            aView.RowFilter = "Active='" + bActive.ToString() + "'";

            dtApp = aView.ToTable();

            //RadGrid1.DataSource = dtApp;
            //RadGrid1.DataBind();
            Session["dtApp"] = dtApp;
            return dtApp;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadDataForRadGrid1();
            }
        }

        private void LoadDataForRadGrid1()
        {
            DataView aView = this.Applications.DefaultView;
            aView.RowFilter = strFilters;
            DataTable dtFiltered = aView.ToTable();

            this.RadGrid1.DataSource = dtFiltered;
            //dtFiltered.PrimaryKey = new DataColumn[] { dtFiltered.Columns["AppID"] };
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            RadGrid1.MasterTableView.EditMode = (GridEditMode)Enum.Parse(typeof(GridEditMode), "PopUp");
            GridFilterMenu menu = RadGrid1.FilterMenu;
            int i = 0;
            while (i < menu.Items.Count)
            {
                if (menu.Items[i].Text == "NoFilter" ||
                    menu.Items[i].Text == "Contains" ||
                    menu.Items[i].Text == "DoesNotContain" ||
                    menu.Items[i].Text == "StartsWith" ||
                    menu.Items[i].Text == "EndsWith" ||
                    menu.Items[i].Text == "EqualTo" ||
                    menu.Items[i].Text == "NotEqualTo"
                    )
                    i++;
                else
                    menu.Items.RemoveAt(i);
            }
        }

        protected void rad_needpermssion_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindApplications();
        }

        protected void RadGrid1_PreRender(object sender, System.EventArgs e)
        {
            if (!this.IsPostBack && this.RadGrid1.MasterTableView.Items.Count > 1)
            {
                //this.RadGrid1.MasterTableView.Items[1].Edit = true;
                //RadGrid1.EditIndexes.Add(0);
                this.RadGrid1.MasterTableView.Rebind();
            }
        }

        private DataTable GetDataTable(string queryString)
        {
            DataTable myDataTable = (DataTable)Session["dtApp"];
            return myDataTable;
        }

        private DataTable Applications
        {
            get
            {
                object obj = this.Session["Applications"];
                if (obj != null)
                    return (DataTable)obj;

                DataTable myDataTable = new DataTable();
                myDataTable = BindApplications();//GetDataTable("SELECT * FROM Applications");
                this.Session["Applications"] = myDataTable;
                return myDataTable;
            }
        }

        protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            //DataTable datasource;
            //if (strFilters != "")
            //{
            //    //DataRow[] drArr = datasource.Select(strFilters);
            //    //DataTable dtFiltered = datasource.Clone();

            //    //foreach (DataRow dr in drArr)
            //    //    dtFiltered.ImportRow(dr);
            //    datasource = this.Applications;
            //    DataView aView = datasource.DefaultView;
            //    aView.RowFilter = strFilters;

            //    datasource = aView.ToTable();
            //}
            //else
            //    datasource = this.Applications;
            DataView aView = this.Applications.DefaultView;
            aView.RowFilter = strFilters;
            DataTable dtFiltered = aView.ToTable();

            this.RadGrid1.DataSource = dtFiltered;
            dtFiltered.PrimaryKey = new DataColumn[] { dtFiltered.Columns["AppID"] };
        }

        protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;
            TextBox txtAppName = (TextBox)e.Item.FindControl("txtAppName");
            CheckBox chkWebBased = (CheckBox)e.Item.FindControl("chkWebBased");
            CheckBox chkActive = (CheckBox)e.Item.FindControl("chkActive");
            TextBox txtModifiedDescription = (TextBox)e.Item.FindControl("txtModifiedDescription");

            //Prepare new row to add it in the DataSource
            DataRow[] changedRows = this.Applications.Select("AppID = " + editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["AppID"]);

            if (changedRows.Length != 1)
            {
                RadGrid1.Controls.Add(new LiteralControl("Unable to locate the Appication for updating."));
                e.Canceled = true;
                return;
            }

            //Update new values
            Hashtable newValues = new Hashtable();

            newValues["AppName"] = txtAppName.Text;
            newValues["WebBased"] = chkWebBased.Checked;
            newValues["Active"] = chkActive.Checked;
            newValues["ModifiedDescription"] = txtModifiedDescription.Text;

            changedRows[0].BeginEdit();
            try
            {
                foreach (DictionaryEntry entry in newValues)
                    changedRows[0][(string)entry.Key] = entry.Value;

                changedRows[0].EndEdit();
                this.Applications.AcceptChanges();
                //LoadDataForRadGrid1();
            }
            catch (Exception ex)
            {
                changedRows[0].CancelEdit();

                Label lblError = new Label();
                lblError.Text = "Unable to update Applications. Reason: " + ex.Message;
                lblError.ForeColor = System.Drawing.Color.Red;
                RadGrid1.Controls.Add(lblError);

                e.Canceled = true;
            }
        }

        protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;
            TextBox txtAppName = (TextBox)e.Item.FindControl("txtAppName");
            CheckBox chkWebBased = (CheckBox)e.Item.FindControl("chkWebBased");
            CheckBox chkActive = (CheckBox)e.Item.FindControl("chkActive");
            TextBox txtModifiedDescription = (TextBox)e.Item.FindControl("txtModifiedDescription");

            //Create new row in the DataSource
            DataRow newRow = this.Applications.NewRow();

            //Insert new values
            Hashtable newValues = new Hashtable();

            newValues["AppName"] = txtAppName.Text;
            newValues["WebBased"] = chkWebBased.Checked;
            newValues["Active"] = chkActive.Checked;
            newValues["ModifiedDescription"] = txtModifiedDescription.Text;

            //make sure that unique primary key value is generated for the inserted row
            newValues["AppID"] = (int)this.Applications.Rows[this.Applications.Rows.Count - 1]["AppID"] + 1;
            try
            {
                foreach (DictionaryEntry entry in newValues)
                    newRow[(string)entry.Key] = entry.Value;
                this.Applications.Rows.Add(newRow);
                this.Applications.AcceptChanges();
            }
            catch (Exception ex)
            {
                Label lblError = new Label();
                lblError.Text = "Unable to insert Applications. Reason: " + ex.Message;
                lblError.ForeColor = System.Drawing.Color.Red;
                RadGrid1.Controls.Add(lblError);

                e.Canceled = true;
            }
        }

        protected void RadGrid1_DeleteCommand(object source, GridCommandEventArgs e)
        {
            string ID = (e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["AppID"].ToString();
            DataTable ApplicationTable = this.Applications;
            if (ApplicationTable.Rows.Find(ID) != null)
            {
                ApplicationTable.Rows.Find(ID).Delete();
                ApplicationTable.AcceptChanges();
            }
        }

        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                //Get the instance of the right type
                GridDataItem dataBoundItem = e.Item as GridDataItem;

                //Check the formatting condition
                if (dataBoundItem["Active"].Text.ToLower() == "true")
                {
                    dataBoundItem["Active"].Text = "YES";
                    dataBoundItem["Active"].ForeColor = Color.Green;
                    dataBoundItem["Active"].Font.Bold = true;
                }
                else
                {
                    dataBoundItem["Active"].Text = "NO";
                    dataBoundItem["Active"].ForeColor = Color.Red;
                }
                if (dataBoundItem["WebBased"].Text.ToLower() == "true")
                {
                    dataBoundItem["WebBased"].Text = "YES";
                    dataBoundItem["WebBased"].ForeColor = Color.Green;
                    dataBoundItem["WebBased"].Font.Bold = true;
                }
                else
                {
                    dataBoundItem["WebBased"].Text = "NO";
                    dataBoundItem["WebBased"].ForeColor = Color.Red;
                }
            }
        }

        protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.FilterCommandName)
            {
                Pair filterPair = (Pair)e.CommandArgument;
                string s1 = "Current Filter function: '" + filterPair.First + "' for column '" + filterPair.Second + "'";
                TextBox filterBox = (e.Item as GridFilteringItem)[filterPair.Second.ToString()].Controls[0] as TextBox;
                string s2 = "<br> Entered pattern for search: " + filterBox.Text;


                if (strFilters != "")
                {
                    switch (filterPair.First.ToString())
                    {
                        case "Contains":
                            strFilters = strFilters + " and " + filterPair.Second + " like '%" + filterBox.Text + "%'";
                            break;
                        case "DoesNotContain":
                            strFilters = strFilters + " and " + filterPair.Second + " not like '%" + filterBox.Text + "%'";
                            break;
                        case "StartsWith":
                            strFilters = strFilters + " and " + filterPair.Second + " like '%>" + filterBox.Text + "%'";
                            break;
                        case "EndsWith":
                            strFilters = strFilters + " and " + filterPair.Second + " like '%" + filterBox.Text + "</%'";
                            break;
                        case "EqualTo":
                            strFilters = strFilters + " and " + filterPair.Second + " like '%>" + filterBox.Text + "</%'";
                            break;
                        case "NotEqualTo":
                            strFilters = strFilters + " and " + filterPair.Second + " not like '%>" + filterBox.Text + "</%'";
                            break;
                    }
                    //strFilters = strFilters + " and " + filterExpressions[i].FieldName + " like '%" + filterExpressions[i].FieldValue + "%'";
                }
                else
                {
                    switch (filterPair.First.ToString())
                    {
                        case "Contains":
                            strFilters = filterPair.Second + " like '%" + filterBox.Text + "%'";
                            break;
                        case "DoesNotContain":
                            strFilters = filterPair.Second + " not like '%" + filterBox.Text + "%'";
                            break;
                        case "StartsWith":
                            strFilters = filterPair.Second + " like '%>" + filterBox.Text + "%'";
                            break;
                        case "EndsWith":
                            strFilters = filterPair.Second + " like '%" + filterBox.Text + "</%'";
                            break;
                        case "EqualTo":
                            strFilters = filterPair.Second + " like '%>" + filterBox.Text + "</%'";
                            break;
                        case "NotEqualTo":
                            strFilters = filterPair.Second + " not like '%>" + filterBox.Text + "</%'";
                            break;
                    }
                    //strFilters = filterExpressions[i].FieldName + " like '%" + filterExpressions[i].FieldValue + "%'";
                }
                this.RadGrid1.MasterTableView.Rebind();
                //LoadDataForRadGrid1();
            }
        }
0
Kostadin
Telerik team
answered on 10 Nov 2014, 01:51 PM
Hi Kamal,

Could you please check whether a JavaScript error is thrown when you click on Add new record button which might prevent opening the popup window? Additionally I examined the provided code and I noticed that you are binding the grid on PageLoad and then OnNeedDataSource. Keep in mind that when using an advanced databinding through NeedDataSource you shouldn't bind the grid on PageLoad.

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Kamal
Top achievements
Rank 1
answered on 11 Nov 2014, 11:21 AM
Hello Kostadin and all experts

Thanks a lot. I appreciate your help.
I was able to fix the "Add new record" popup issue. You are right. There was a javascript error which was not showing up (may be disabled from the browser). Below is what I did in ASPX only to fix that in case someone is facing similar problem. 
........
                                            <tr>
                                                <td>Web Based:
                                                </td>
                                                <td>
                                                    <asp:CheckBox ID="chkWebBased" runat="server" Enabled='<%# (Container is GridEditFormInsertItem) ? false : true %>' Checked='<%# (DataBinder.Eval(Container.DataItem,"WebBased")==DBNull.Value ? true:Eval("WebBased"))%>'/>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>Active:
                                                </td>
                                                <td>
                                                    <asp:CheckBox ID="chkActive" runat="server" Enabled='<%# (Container is GridEditFormInsertItem) ? false : true %>' Checked='<%# (DataBinder.Eval(Container.DataItem,"Active")==DBNull.Value ? true:Eval("Active"))%>'/>
                                                </td>
                                            </tr>
.......

 

But I'm still not able to apply in-built filters or in fact any filters on my grid. I followed these two demos in mix:

http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/edit-form-types/defaultcs.aspx#qsf-demo-source
http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/form-template-update/defaultcs.aspx
ASPX code remaining unchanged, below is my complete CS code:
----------------------------------------------
using System;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using UPMLibrary;

namespace UserPermissionManager
{
    public partial class ApplicationsTelerik : Page
    {
        AppPermission objApp = new AppPermission();
        Users objusers = new Users();
        string strFilters = "";

        public DataTable BindApplications()
        {
            DataTable dtApp;

            //the table index (.Tables[1]) in the below statement is done 
            //for TEMPORARY SUPPORT of old UPM and must changed back to (.Tables[0]) 
            //after this new UPM is rolled OUT
            /********************************************************************************************************************************************/
            dtApp = objApp.ListApplications().Tables[1];
            /********************************************************************************************************************************************/

            string SortExpression = "";
            string SortDirection = "";

            if (Session["ASE"] != null)
                SortExpression = Session["ASE"].ToString();
            if (Session["ASD"] != null)
                SortDirection = Session["ASD"].ToString();
            if (SortExpression == "")
                SortExpression = "AppName";
            if (SortDirection == "Descending")
                SortDirection = "Desc";
            else
                SortDirection = "Asc";

            DataView aView = dtApp.DefaultView;
            //if (SortExpression != "")
            //    aView.Sort = SortExpression + " " + SortDirection;

            bool bActive = true;
            bActive = (chkshowinactive.Checked) ? false : true;
            aView.RowFilter = "Active='" + bActive.ToString() + "'";

            dtApp = aView.ToTable();

            //RadGrid1.DataSource = dtApp;
            //RadGrid1.DataBind();
            return dtApp;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            { }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            //RadGrid1.DataSource = Applications;
            //RadGrid1.DataBind();
            //Applications.PrimaryKey = new DataColumn[] { Applications.Columns["AppID"] };
                
            RadGrid1.MasterTableView.EditMode = (GridEditMode)Enum.Parse(typeof(GridEditMode), "PopUp");
            GridFilterMenu menu = RadGrid1.FilterMenu;
            int i = 0;
            while (i < menu.Items.Count)
            {
                if (menu.Items[i].Text == "NoFilter" ||
                    menu.Items[i].Text == "Contains" ||
                    menu.Items[i].Text == "DoesNotContain" ||
                    menu.Items[i].Text == "StartsWith" ||
                    menu.Items[i].Text == "EndsWith" ||
                    menu.Items[i].Text == "EqualTo" ||
                    menu.Items[i].Text == "NotEqualTo"
                    )
                    i++;
                else
                    menu.Items.RemoveAt(i);
            }
        }

        protected void rad_needpermssion_SelectedIndexChanged(object sender, EventArgs e)
        {
            RadGrid1.MasterTableView.Rebind();
        }

        protected void RadGrid1_PreRender(object sender, System.EventArgs e)
        {
            if (!IsPostBack && RadGrid1.MasterTableView.Items.Count > 1)
            {
                //RadGrid1.MasterTableView.Items[1].Edit = true;
                //RadGrid1.EditIndexes.Add(0);
                //RadGrid1.MasterTableView.Rebind();
                //RadGrid1.Rebind();
            }
        }

        private DataTable Applications
        {
            get
            {
                object obj = Session["Applications"];
                DataTable myDataTable = new DataTable();
                if (obj != null)
                {
                    myDataTable = (DataTable)obj;

                    bool bActive = true;
                    bActive = (chkshowinactive.Checked) ? false : true;
                    myDataTable.DefaultView.RowFilter = "Active='" + bActive.ToString() + "'";
                    myDataTable = myDataTable.DefaultView.ToTable();
                    return myDataTable;
                }
                else
                    myDataTable = BindApplications();
                
                DataView aView = myDataTable.DefaultView;
                aView.RowFilter = strFilters;

                //myDataTable = aView.ToTable();

                //DataTable datasource;
                //if (strFilters != "")
                //{
                DataRow[] drArr = myDataTable.Select(strFilters);
                DataTable dtFiltered = myDataTable.Clone();

                foreach (DataRow dr in drArr)
                    dtFiltered.ImportRow(dr);

                //    datasource = Applications;
                //    DataView aView = datasource.DefaultView;
                //    aView.RowFilter = strFilters;

                //    datasource = aView.ToTable();
                //}
                //else
                //    datasource = Applications;
                //DataView aView = Applications.DefaultView;
                //aView.RowFilter = strFilters;
                //DataTable dtFiltered = aView.ToTable();

                Session["Applications"] = myDataTable;
                return myDataTable;
            }
        }

        protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            RadGrid1.DataSource = Applications;
            Applications.PrimaryKey = new DataColumn[] { Applications.Columns["AppID"] };
        }

        protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;
            TextBox txtAppName = (TextBox)e.Item.FindControl("txtAppName");
            CheckBox chkWebBased = (CheckBox)e.Item.FindControl("chkWebBased");
            CheckBox chkActive = (CheckBox)e.Item.FindControl("chkActive");

            //Prepare new row to add it in the DataSource
            string sAppID = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["AppID"].ToString();
            DataRow[] changedRows = Applications.Select("AppID = " + sAppID);

            if (changedRows.Length != 1)
            {
                RadGrid1.Controls.Add(new LiteralControl("Unable to locate the Appication for updating."));
                e.Canceled = true;
                return;
            }

            //Update new values
            Hashtable newValues = new Hashtable();

            if (txtAppName.Text == "")
            {
                Label lblError = new Label();
                lblError.Text = "Application name cannot be empty.";
                lblError.ForeColor = Color.Red;
                RadGrid1.Controls.Add(lblError);

                e.Canceled = true;

                return;
            } 
            
            newValues["AppName"] = txtAppName.Text;
            newValues["WebBased"] = chkWebBased.Checked;
            newValues["Active"] = chkActive.Checked;
            newValues["ModifiedOn"] = DateTime.Now;
            newValues["ModifiedBy"] = "";

            changedRows[0].BeginEdit();
            try
            {
                foreach (DictionaryEntry entry in newValues)
                    changedRows[0][(string)entry.Key] = entry.Value;

                changedRows[0].EndEdit();
                Applications.AcceptChanges();
                objApp.APPID = Convert.ToInt32(sAppID);
                objApp.AppName = txtAppName.Text;
                objApp.WebBased = (chkWebBased.Checked) ? 1 : 0;
                objApp.AppStatus = (chkActive.Checked) ? 1 : 0;
                objApp.CurrentUser = "";

                bool ischanged = objApp.ChangeAppStatus();
            }
            catch (Exception ex)
            {
                changedRows[0].CancelEdit();

                Label lblError = new Label();
                lblError.Text = "Unable to update Applications. Reason: " + ex.Message;
                lblError.ForeColor = System.Drawing.Color.Red;
                RadGrid1.Controls.Add(lblError);

                e.Canceled = true;
            }
        }

        protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;
            TextBox txtAppName = (TextBox)e.Item.FindControl("txtAppName");
            CheckBox chkWebBased = (CheckBox)e.Item.FindControl("chkWebBased");
            CheckBox chkActive = (CheckBox)e.Item.FindControl("chkActive");

            //Create new row in the DataSource
            DataRow newRow = Applications.NewRow();

            //Insert new values
            Hashtable newValues = new Hashtable();

            if (txtAppName.Text == "")
            {
                Label lblError = new Label();
                lblError.Text = "Application name cannot be empty.";
                lblError.ForeColor = Color.Red;
                RadGrid1.Controls.Add(lblError);

                e.Canceled = true;

                return;
            }
            newValues["AppName"] = txtAppName.Text;
            newValues["WebBased"] = chkWebBased.Checked;
            newValues["Active"] = chkActive.Checked;
            newValues["ModifiedOn"] = DateTime.Now;
            newValues["ModifiedBy"] = "";

            //make sure that unique primary key value is generated for the inserted row
            newValues["AppID"] = (int)Applications.Rows[Applications.Rows.Count - 1]["AppID"] + 1;
            try
            {
                foreach (DictionaryEntry entry in newValues)
                    newRow[(string)entry.Key] = entry.Value;
                Applications.Rows.Add(newRow);
                Applications.AcceptChanges();

                objApp.APPID = -1;
                objApp.AppName = txtAppName.Text;
                objApp.WebBased = (chkWebBased.Checked) ? 1 : 0;
                objApp.AppStatus = (chkActive.Checked) ? 1 : 0;
                objApp.CurrentUser = "";

                bool ischanged = objApp.ChangeAppStatus();
            }
            catch (Exception ex)
            {
                Label lblError = new Label();
                lblError.Text = "Unable to insert Applications. Reason: " + ex.Message;
                lblError.ForeColor = System.Drawing.Color.Red;
                RadGrid1.Controls.Add(lblError);

                e.Canceled = true;
            }
        }

        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                //Get the instance of the right type
                GridDataItem dataBoundItem = e.Item as GridDataItem;

                //Check the formatting condition
                if (dataBoundItem["Active"].Text.ToLower() == "true")
                {
                    dataBoundItem["Active"].Text = "YES";
                    dataBoundItem["Active"].ForeColor = Color.Green;
                    dataBoundItem["Active"].Font.Bold = true;
                }
                else
                {
                    dataBoundItem["Active"].Text = "NO";
                    dataBoundItem["Active"].ForeColor = Color.Red;
                }
                if (dataBoundItem["WebBased"].Text.ToLower() == "true")
                {
                    dataBoundItem["WebBased"].Text = "YES";
                    dataBoundItem["WebBased"].ForeColor = Color.Green;
                    dataBoundItem["WebBased"].Font.Bold = true;
                }
                else
                {
                    dataBoundItem["WebBased"].Text = "NO";
                    dataBoundItem["WebBased"].ForeColor = Color.Red;
                }
            }
        }

        protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.FilterCommandName)
            {
                Pair filterPair = (Pair)e.CommandArgument;
                string s1 = "Current Filter function: '" + filterPair.First + "' for column '" + filterPair.Second + "'";
                TextBox filterBox = (e.Item as GridFilteringItem)[filterPair.Second.ToString()].Controls[0] as TextBox;
                string s2 = "<br> Entered pattern for search: " + filterBox.Text;


                if (strFilters != "")
                {
                    switch (filterPair.First.ToString())
                    {
                        case "Contains":
                            strFilters = strFilters + " and " + filterPair.Second + " like '%" + filterBox.Text + "%'";
                            break;
                        case "DoesNotContain":
                            strFilters = strFilters + " and " + filterPair.Second + " not like '%" + filterBox.Text + "%'";
                            break;
                        case "StartsWith":
                            strFilters = strFilters + " and " + filterPair.Second + " like '%>" + filterBox.Text + "%'";
                            break;
                        case "EndsWith":
                            strFilters = strFilters + " and " + filterPair.Second + " like '%" + filterBox.Text + "</%'";
                            break;
                        case "EqualTo":
                            strFilters = strFilters + " and " + filterPair.Second + " like '%>" + filterBox.Text + "</%'";
                            break;
                        case "NotEqualTo":
                            strFilters = strFilters + " and " + filterPair.Second + " not like '%>" + filterBox.Text + "</%'";
                            break;
                    }
                    //strFilters = strFilters + " and " + filterExpressions[i].FieldName + " like '%" + filterExpressions[i].FieldValue + "%'";
                }
                else
                {
                    switch (filterPair.First.ToString())
                    {
                        case "Contains":
                            strFilters = filterPair.Second + " like '%" + filterBox.Text + "%'";
                            break;
                        case "DoesNotContain":
                            strFilters = filterPair.Second + " not like '%" + filterBox.Text + "%'";
                            break;
                        case "StartsWith":
                            strFilters = filterPair.Second + " like '%>" + filterBox.Text + "%'";
                            break;
                        case "EndsWith":
                            strFilters = filterPair.Second + " like '%" + filterBox.Text + "</%'";
                            break;
                        case "EqualTo":
                            strFilters = filterPair.Second + " like '%>" + filterBox.Text + "</%'";
                            break;
                        case "NotEqualTo":
                            strFilters = filterPair.Second + " not like '%>" + filterBox.Text + "</%'";
                            break;
                    }
                    //strFilters = filterExpressions[i].FieldName + " like '%" + filterExpressions[i].FieldValue + "%'";
                }
                //RadGrid1.MasterTableView.FilterExpression = strFilters;
                //RadGrid1.MasterTableView.Rebind();
                Applications.DefaultView.RowFilter = strFilters;
                RadGrid1.DataSource = Applications.DefaultView.ToTable();
                RadGrid1.MasterTableView.Rebind();
            }
            else if (e.CommandName == RadGrid.InitInsertCommandName) //"Add new" button clicked
            {
                GridEditCommandColumn editColumn = (GridEditCommandColumn)RadGrid1.MasterTableView.GetColumn("EditCommandColumn");
                editColumn.Visible = false;
            }
            else if (e.CommandName == RadGrid.RebindGridCommandName && e.Item.OwnerTableView.IsItemInserted)
            {
                e.Canceled = true;
            }
            else
            {
                GridEditCommandColumn editColumn = (GridEditCommandColumn)RadGrid1.MasterTableView.GetColumn("EditCommandColumn");
                if (!editColumn.Visible)
                    editColumn.Visible = true;
            }
        }
    }
}

----------------------------------------------
The Application property which returns DataTable; I try to apply filter there. My page does not even load, and I get

"PrimaryKey columns do not belong to this table.
....
Line 159: Applications.PrimaryKey = new DataColumn[] { Applications.Columns["AppID"] };
....."
I tried by moving the filtering routine at several different places (you may notice that from commented code), but I still get above error. I'm sure there must be a solution and I'm doing this in a wrong way. Please help me get on track.

Thanks a lot
Kamal



0
Kamal
Top achievements
Rank 1
answered on 13 Nov 2014, 07:38 AM
Hello
Please someone help me to fix the filters referring to my previous post. I'm able to fix the Primary key issue. But still applying inbuilt filters makes the grid blank. But when I debugged the code, I clearly see the filtered DataTable but the grid becomes blank.
Please help.
0
Kostadin
Telerik team
answered on 14 Nov 2014, 08:01 AM
Hi Kamal,

I noticed that you are trying to a custom filtering. Note that in this case you need to cancel the built-in filter function by setting Canceled property from the  argument  to false (e.Canceled  = true). I would recommend you to examine the following help article which elaborates more on this matter. Otherwise if you need to use the built-in filter then it is not necessary to apply a FilterExpressions as they will be created automatically. I would suggest you to examine this two topics which provide more information about the built-in filtering.
Basic Filtering
Filter Template

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Kamal
Top achievements
Rank 1
answered on 02 Dec 2014, 08:38 AM
Hello Kostadin, 
I commented and removed the "RadGrid1_ItemCommand" from my grid. I referred to the shared links. Grid still becomes blank. Here is the changed code.

ASPX code  :- 
<!------------------------------------------------------------------------------------------------------------------->
<%@ Page Language="C#" MasterPageFile="~/Main.master" AutoEventWireup="true" Inherits="UserPermissionManager.Applications" CodeBehind="Applications.aspx.cs" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="CTP" runat="Server">
    <asp:UpdatePanel ID="UpdatePanel2" runat="server">
        <ContentTemplate>
            <table align="center" cellspacing="10px" border="0">
                <tr align="center">
                    <td>
                        <input runat="server" type="hidden" id="hdUserName" name="hdUserName" />
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <div id="divlist" runat="server" visible="true" style="border: 1px solid #666666; background-color: #ffffff; font-size: 11px; overflow: scroll; height: 579px; width: 1860px;">
                            <asp:CheckBox ID="chkshowinactive" runat="server" Visible="true"
                                Text="Show Inactive" CausesValidation="false"
                                Checked="false" OnCheckedChanged="rad_needpermssion_SelectedIndexChanged"
                                AutoPostBack="True" CssClass="Checkbox" />
                            <br />
                            <%--<telerik:RadScriptManager runat="server" ID="RadScriptManager1" />--%>
                            <%--<telerik:RadSkinManager ID="QsfSkinManager" runat="server" ShowChooser="true" />--%>
                            <%--<telerik:RadFormDecorator ID="QsfFromDecorator" runat="server" DecoratedControls="All" EnableRoundedCorners="false" />--%>
                            <telerik:RadCodeBlock ID="RadCodeBlock2" runat="server">
                                <script type="text/javascript">
                                    function RowDblClick(sender, eventArgs) {
                                        sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());
                                    }

                                    function onPopUpShowing(sender, args) {
                                        args.get_popUp().className += " popUpEditForm";
                                    }
                                </script>
                            </telerik:RadCodeBlock>
                            <telerik:RadAjaxManagerProxy ID="RadAjaxManager1" runat="server">
                                <AjaxSettings>
                                    <telerik:AjaxSetting>
                                        <UpdatedControls>
                                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
                                        </UpdatedControls>
                                    </telerik:AjaxSetting>
                                </AjaxSettings>
                            </telerik:RadAjaxManagerProxy>
                            <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" ShowFooter="True"
                                AllowSorting="True" AutoGenerateColumns="False" ShowStatusBar="True"
                                OnPreRender="RadGrid1_PreRender" OnNeedDataSource="RadGrid1_NeedDataSource" OnUpdateCommand="RadGrid1_UpdateCommand"
                                OnInsertCommand="RadGrid1_InsertCommand" OnItemDataBound="RadGrid1_ItemDataBound"
                                AllowFilteringByColumn="true" CellSpacing="-1" GridLines="Both">
                                <PagerStyle Mode="NextPrevAndNumeric" Position="TopAndBottom" />
                                <HeaderStyle Font-Bold="true" />
                                <MasterTableView CommandItemDisplay="Top" DataKeyNames="AppID" PageSize="15">
                                    <EditFormSettings>
                                        <PopUpSettings Modal="true" />
                                    </EditFormSettings>
                                    <Columns>
                                        <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" />
                                        <telerik:GridBoundColumn Visible="true" SortExpression="AppName" DataField="AppName"
                                            HeaderText="Application Name" ItemStyle-VerticalAlign="Top" />
                                        <telerik:GridHyperLinkColumn DataTextField="NoOfPermTypes" SortExpression="NoOfPermTypes" HeaderText="# of Permission Types" DataNavigateUrlFields="AppID"
                                            DataNavigateUrlFormatString="ApplicationPermission.aspx?AppID={0}" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Left" />
                                        <telerik:GridBoundColumn Visible="true" SortExpression="Active" DataField="Active"
                                            HeaderText="Active" ItemStyle-VerticalAlign="Top" AllowFiltering="false" />
                                        <telerik:GridBoundColumn Visible="true" SortExpression="WebBased" DataField="WebBased"
                                            HeaderText="Web Based" ItemStyle-VerticalAlign="Top" AllowFiltering="false" />
                                        <telerik:GridBoundColumn Visible="true" SortExpression="ModifiedOn" DataField="ModifiedOn"
                                            HeaderText="Modified On" ItemStyle-VerticalAlign="Top" DataFormatString="{0:d-MMM-yyyy hh:mm tt}" />
                                        <telerik:GridBoundColumn Visible="true" SortExpression="ModifiedBy" DataField="ModifiedBy"
                                            HeaderText="Modified By" ItemStyle-VerticalAlign="Top" />
                                    </Columns>
                                    <EditFormSettings EditFormType="Template" CaptionFormatString="Add/Edit Application">
                                        <FormTemplate>
                                            <table id="Table2" cellspacing="2" cellpadding="1" width="100%" border="0" rules="none"
                                                style="border-collapse: collapse;">
                                                <tr>
                                                    <td>
                                                        <table id="Table3" cellspacing="1" cellpadding="1" border="0" class="module">
                                                            <tr>
                                                                <td>Application Name:</td>
                                                                <td>
                                                                    <asp:TextBox ID="txtAppName" runat="server" Text='<%# Bind("AppName") %>' />
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>Web Based:
                                                                </td>
                                                                <td>
                                                                    <asp:CheckBox ID="chkWebBased" runat="server" Enabled='<%# (Container is GridEditFormInsertItem) ? false : true %>'
                                                                        Checked='<%# (DataBinder.Eval(Container.DataItem,"WebBased")==DBNull.Value ? true:Eval("WebBased"))%>' />
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>Active:
                                                                </td>
                                                                <td>
                                                                    <asp:CheckBox ID="chkActive" runat="server" Enabled='<%# (Container is GridEditFormInsertItem) ? false : true %>'
                                                                        Checked='<%# (DataBinder.Eval(Container.DataItem,"Active")==DBNull.Value ? true:Eval("Active"))%>' />
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="left">
                                                        <asp:Label ID="lblError1" ForeColor="Red" runat="server"></asp:Label>
                                                    </td>
                                                    <td align="right">
                                                        <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                                            runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'></asp:Button>
                                                        &nbsp;
                                                        <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                                                            CommandName="Cancel"></asp:Button>
                                                    </td>
                                                </tr>
                                            </table>
                                        </FormTemplate>
                                    </EditFormSettings>
                                </MasterTableView>
                                <ClientSettings>
                                    <ClientEvents OnRowDblClick="RowDblClick" OnPopUpShowing="onPopUpShowing" />
                                </ClientSettings>
                            </telerik:RadGrid>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <font color="#666666">* Red color represents the applications that does not need permissions.</font><br />
                        <font color="#666666">* Green color represents the applications that needs permissions.</font>
                    </td>
                </tr>
            </table>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
<!------------------------------------------------------------------------------------------------------------------->

CodeBehind :- 

/***************************************************************************************************/
using System;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Web.UI;
using System.Linq;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using UPMLibrary;

namespace UserPermissionManager
{
    public partial class Applications : Page
    {
        AppPermission objApp = new AppPermission();
        Users objusers = new Users();
        string strFilters = "";

        public DataTable BindApplications()
        {
            //the table index (.Tables[1]) in the below statement is done 
            //for TEMPORARY SUPPORT of old UPM and must changed back to (.Tables[0]) 
            //after this new UPM is rolled OUT
            /********************************************************************************************************************************************/
            DataView aView = objApp.ListApplications().Tables[1].DefaultView;
            /********************************************************************************************************************************************/

            aView.RowFilter = "Active=" + ((chkshowinactive.Checked) ? false : true).ToString();
            return aView.ToTable();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            ((HtmlGenericControl)this.Master.FindControl("liApps")).Attributes.Add("class", "SelectedMainMenu");

            if (!IsPostBack)
            {
                if (Session["PERMISSIONLOGONUSER"] != null)
                    objApp.CurrentUser = Session["PERMISSIONLOGONUSER"].ToString();
                else
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "document.getElementById('CTP_hdUserName').value = document.getElementById('lblSupplier').innerText;", true);
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            //RadGrid1.DataSource = ApplicationsTable;
            //RadGrid1.DataBind();
            //ApplicationsTable.PrimaryKey = new DataColumn[] { ApplicationsTable.Columns["AppID"] };
                
            RadGrid1.MasterTableView.EditMode = (GridEditMode)Enum.Parse(typeof(GridEditMode), "PopUp");
            //GridFilterMenu menu = RadGrid1.FilterMenu;
            //int i = 0;
            //while (i < menu.Items.Count)
            //{
            //    if (menu.Items[i].Text == "NoFilter" ||
            //        menu.Items[i].Text == "Contains" ||
            //        menu.Items[i].Text == "DoesNotContain" ||
            //        menu.Items[i].Text == "StartsWith" ||
            //        menu.Items[i].Text == "EndsWith" ||
            //        menu.Items[i].Text == "EqualTo" ||
            //        menu.Items[i].Text == "NotEqualTo"
            //        )
            //        i++;
            //    else
            //        menu.Items.RemoveAt(i);
            //}
        }

        protected void rad_needpermssion_SelectedIndexChanged(object sender, EventArgs e)
        {
            Session["Applications"] = null;
            RadGrid1.MasterTableView.Rebind();
        }

        protected void RadGrid1_PreRender(object sender, System.EventArgs e)
        {
            if (!IsPostBack && RadGrid1.MasterTableView.Items.Count > 1)
            {
                //RadGrid1.MasterTableView.Items[1].Edit = true;
                //RadGrid1.EditIndexes.Add(0);
                //RadGrid1.MasterTableView.Rebind();
                //RadGrid1.Rebind();
            }
        }

        private DataTable ApplicationsTable
        {
            get
            {
                object obj = Session["Applications"];
                DataTable myDataTable = new DataTable();
                if (obj != null)
                {
                    myDataTable = (DataTable)obj;

                    //bool bActive = true;
                    //bActive = (chkshowinactive.Checked) ? false : true;
                    //myDataTable.DefaultView.RowFilter = "Active='" + bActive.ToString() + "'";
                    //myDataTable = myDataTable.DefaultView.ToTable();
                    //return myDataTable;
                }
                else
                    myDataTable = BindApplications();

                DataView aView = myDataTable.DefaultView;
                aView.RowFilter = strFilters;

                //myDataTable = aView.ToTable();

                //DataTable datasource;
                //if (strFilters != "")
                //{
                DataRow[] drArr = myDataTable.Select(strFilters);
                DataTable dtFiltered = myDataTable.Clone();

                foreach (DataRow dr in drArr)
                    dtFiltered.ImportRow(dr);

                //    datasource = ApplicationsTable;
                //    DataView aView = datasource.DefaultView;
                //    aView.RowFilter = strFilters;

                //    datasource = aView.ToTable();
                //}
                //else
                //    datasource = ApplicationsTable;
                //DataView aView = ApplicationsTable.DefaultView;
                //aView.RowFilter = strFilters;
                //DataTable dtFiltered = aView.ToTable();

                Session["Applications"] = myDataTable;
                return myDataTable;
            }
        }

        protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            RadGrid1.DataSource = ApplicationsTable;
            ApplicationsTable.PrimaryKey = new DataColumn[] { ApplicationsTable.Columns["AppID"] };
        }

        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                //Get the instance of the right type
                GridDataItem dataBoundItem = e.Item as GridDataItem;

                //Check the formatting condition
                if (dataBoundItem["Active"].Text.ToLower() == "true")
                {
                    dataBoundItem["Active"].Text = "YES";
                    dataBoundItem["Active"].ForeColor = Color.Green;
                    dataBoundItem["Active"].Font.Bold = true;
                    dataBoundItem["AppName"].ForeColor = Color.Green;
                    dataBoundItem["AppName"].Font.Bold = true;
                }
                else
                {
                    dataBoundItem["Active"].Text = "NO";
                    dataBoundItem["Active"].ForeColor = Color.Red;
                    dataBoundItem["AppName"].ForeColor = Color.Red;
                }
                if (dataBoundItem["WebBased"].Text.ToLower() == "true")
                {
                    dataBoundItem["WebBased"].Text = "YES";
                    dataBoundItem["WebBased"].ForeColor = Color.Green;
                    dataBoundItem["WebBased"].Font.Bold = true;
                }
                else
                {
                    dataBoundItem["WebBased"].Text = "NO";
                    dataBoundItem["WebBased"].ForeColor = Color.Red;
                }
            }
            if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode))
            {
                GridEditableItem editform = (GridEditableItem)e.Item;
                TextBox txtAppName = (TextBox)editform.FindControl("txtAppName");
                Button btnUpdate = (Button)editform.FindControl("btnUpdate");
                Label lblError1 = (Label)editform.FindControl("lblError1");
                //btnUpdate.Attributes.Add("onclick", "return clientValidation(" + txtAppName.ClientID + "," + lblError1.ClientID + ");");
                btnUpdate.Attributes.Add("onclick", "if(document.getElementById('" + txtAppName.ClientID + "').value == '') { document.getElementById('" +
                    lblError1.ClientID + "').innerText = 'Application name cannot be empty.'; document.getElementById('" + txtAppName.ClientID + "').focus(); return false; }");
                txtAppName.Attributes.Add("onkeydown", "document.getElementById('" + lblError1.ClientID + "').innerText = '';");
            }
        }

        protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;
            TextBox txtAppName = (TextBox)editedItem.FindControl("txtAppName");
            CheckBox chkWebBased = (CheckBox)editedItem.FindControl("chkWebBased");
            CheckBox chkActive = (CheckBox)editedItem.FindControl("chkActive");
            Label lblError1 = (Label)editedItem.FindControl("lblError1");
            
            //Prepare new row to add it in the DataSource
            string sAppID = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["AppID"].ToString();
            DataRow[] changedRows = ApplicationsTable.Select("AppID = " + sAppID);

            Label lblError = new Label();
            RadGrid1.Controls.Add(lblError);

            if (changedRows.Length != 1)
            {
                lblError1.Text = "Unable to locate the Application for updating.";
                e.Canceled = true;
                return;
            }
            if (txtAppName.Text == "")
            {
                lblError1.Text = "Application name cannot be empty.";
                txtAppName.Focus();
                e.Canceled = true;
                return;
            }

            //Update new values
            Hashtable newValues = new Hashtable();
            newValues["AppName"] = txtAppName.Text;
            newValues["WebBased"] = chkWebBased.Checked;
            newValues["Active"] = chkActive.Checked;
            newValues["ModifiedOn"] = DateTime.Now;
            newValues["ModifiedBy"] = "";

            changedRows[0].BeginEdit();
            try
            {
                foreach (DictionaryEntry entry in newValues)
                    changedRows[0][(string)entry.Key] = entry.Value;

                changedRows[0].EndEdit();
                ApplicationsTable.AcceptChanges();

                objApp.APPID = Convert.ToInt32(sAppID);
                objApp.AppName = txtAppName.Text;
                objApp.WebBased = (chkWebBased.Checked) ? 1 : 0;
                objApp.AppStatus = (chkActive.Checked) ? 1 : 0;
                objApp.CurrentUser = "";

                int ischanged = objApp.ChangeAppStatus();

                lblError.Text = "Application is updated successfully!";
                lblError.ForeColor = Color.Green;
            }
            catch (Exception ex)
            {
                changedRows[0].CancelEdit();
                lblError1.Text = "Unable to update Application. Reason: " + ex.Message;
                e.Canceled = true;
            }
        }

        protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;
            TextBox txtAppName = (TextBox)editedItem.FindControl("txtAppName");
            CheckBox chkWebBased = (CheckBox)editedItem.FindControl("chkWebBased");
            CheckBox chkActive = (CheckBox)editedItem.FindControl("chkActive");
            Label lblError1 = (Label)editedItem.FindControl("lblError1");

            //Create new row in the DataSource
            DataRow newRow = ApplicationsTable.NewRow();

            Label lblError = new Label();
            RadGrid1.Controls.Add(lblError);
            
            if (txtAppName.Text == "")
            {
                lblError1.Text = "Application name cannot be empty.";
                txtAppName.Focus();
                e.Canceled = true;
                return;
            }
            
            //Insert new values
            Hashtable newValues = new Hashtable();
            newValues["AppName"] = txtAppName.Text;
            newValues["WebBased"] = chkWebBased.Checked;
            newValues["Active"] = chkActive.Checked;
            newValues["ModifiedOn"] = DateTime.Now;
            newValues["ModifiedBy"] = "";

            //make sure that unique primary key value is generated for the inserted row
            try
            {
                objApp.APPID = 0;
                objApp.AppName = txtAppName.Text;
                objApp.WebBased = (chkWebBased.Checked) ? 1 : 0;
                objApp.AppStatus = (chkActive.Checked) ? 1 : 0;
                objApp.CurrentUser = "";

                newValues["AppID"] = objApp.ChangeAppStatus();

                foreach (DictionaryEntry entry in newValues)
                    newRow[(string)entry.Key] = entry.Value;
                ApplicationsTable.Rows.Add(newRow);
                ApplicationsTable.AcceptChanges();

                lblError.Text = "<font color=Green>Application is inserted successfully!</font>";
                lblError.ForeColor = Color.Green;
            }
            catch (Exception ex)
            {
                lblError1.Text = "Unable to insert Application. Reason: " + ex.Message;
                e.Canceled = true;
            }
        }

        protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
        {
            //if (e.CommandName == RadGrid.FilterCommandName)
            //{
            //    Pair filterPair = (Pair)e.CommandArgument;
            //    string s1 = "Current Filter function: '" + filterPair.First + "' for column '" + filterPair.Second + "'";
            //    TextBox filterBox = (e.Item as GridFilteringItem)[filterPair.Second.ToString()].Controls[0] as TextBox;
            //    string s2 = "<br> Entered pattern for search: " + filterBox.Text;


            //    if (strFilters != "")
            //    {
            //        switch (filterPair.First.ToString())
            //        {
            //            case "Contains":
            //                strFilters = strFilters + " and " + filterPair.Second + " like '%" + filterBox.Text + "%'";
            //                break;
            //            case "DoesNotContain":
            //                strFilters = strFilters + " and " + filterPair.Second + " not like '%" + filterBox.Text + "%'";
            //                break;
            //            case "StartsWith":
            //                strFilters = strFilters + " and " + filterPair.Second + " like '%>" + filterBox.Text + "%'";
            //                break;
            //            case "EndsWith":
            //                strFilters = strFilters + " and " + filterPair.Second + " like '%" + filterBox.Text + "</%'";
            //                break;
            //            case "EqualTo":
            //                strFilters = strFilters + " and " + filterPair.Second + " like '%>" + filterBox.Text + "</%'";
            //                break;
            //            case "NotEqualTo":
            //                strFilters = strFilters + " and " + filterPair.Second + " not like '%>" + filterBox.Text + "</%'";
            //                break;
            //        }
            //        //strFilters = strFilters + " and " + filterExpressions[i].FieldName + " like '%" + filterExpressions[i].FieldValue + "%'";
            //    }
            //    else
            //    {
            //        switch (filterPair.First.ToString())
            //        {
            //            case "Contains":
            //                strFilters = filterPair.Second + " like '%" + filterBox.Text + "%'";
            //                break;
            //            case "DoesNotContain":
            //                strFilters = filterPair.Second + " not like '%" + filterBox.Text + "%'";
            //                break;
            //            case "StartsWith":
            //                strFilters = filterPair.Second + " like '%>" + filterBox.Text + "%'";
            //                break;
            //            case "EndsWith":
            //                strFilters = filterPair.Second + " like '%" + filterBox.Text + "</%'";
            //                break;
            //            case "EqualTo":
            //                strFilters = filterPair.Second + " like '%>" + filterBox.Text + "</%'";
            //                break;
            //            case "NotEqualTo":
            //                strFilters = filterPair.Second + " not like '%>" + filterBox.Text + "</%'";
            //                break;
            //        }
            //        //strFilters = filterExpressions[i].FieldName + " like '%" + filterExpressions[i].FieldValue + "%'";
            //    }
            //    //RadGrid1.MasterTableView.FilterExpression = strFilters;
            //    //RadGrid1.MasterTableView.Rebind();
            //    //ApplicationsTable.DefaultView.RowFilter = strFilters;
            //    //RadGrid1.DataSource = ApplicationsTable.DefaultView.ToTable();
            //    Session["Applications"] = null;
            //    RadGrid1.MasterTableView.Rebind();
            //}
        }
    }
}

/*************************************************************************************************/

Please guide...











0
Kostadin
Telerik team
answered on 04 Dec 2014, 01:24 PM
Hello Kamal,

I modified your code a little in order to make it runnable and on my side the built-in filtering is working properly. Could you please check out the attached sample and let me know how it behaves on your end? Also I would appreciate if you can try replicating the issue there in order to investigate it further.

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Kamal
Top achievements
Rank 1
answered on 06 Dec 2014, 01:26 PM
Thanks Kostadin, the modified sample works on my machine. But there is a problem.

I calculated that everything else remaining same in the code...Just this method plugged in the code from your supplied sample works well in my page with filters.

But if I comment   only  this line   "//        return table;" in the
code (i.e. the method is returns original DataTable from target DB), the filters
make the grid blank... :( :( ....I'm not sure why grid wont work with my actual DataTable.


/******************************************************************************/
public DataTable BindApplications()
{
            DataTable table = new DataTable();

            table.Columns.Add("AppName");
            table.Columns.Add("NoOfPermTypes", typeof(int));
            table.Columns.Add("AppID", typeof(int));
            table.Columns.Add("Active");
            table.Columns.Add("WebBased");
            table.Columns.Add("ModifiedOn", typeof(DateTime));
            table.Columns.Add("ModifiedBy");

            for (int i = 1; i < 20; i++)
                table.Rows.Add("AppName" + i, i, i, true, "WebBased" + i, new DateTime(2014, 12, i), "ModifiedBy" + i);
           
            return table;

            //the table index (.Tables[1]) in the below statement is done
            //for TEMPORARY SUPPORT of old UPM and must changed back to (.Tables[0])
            //after this new UPM is rolled OUT
            /********************************************************************************************************************************************/
            DataView aView = objApp.ListApplications().Tables[1].DefaultView;
            /********************************************************************************************************************************************/

            aView.RowFilter = "Active=" + ((chkshowinactive.Checked) ? false : true).ToString();
            return aView.ToTable();
}
/******************************************************************************/
0
Kostadin
Telerik team
answered on 10 Dec 2014, 01:25 PM
Hello Kamal,

Could you please check the data in the table when you call ToTable() method? Since you have applied a filter the table might become empty. Nevertheless your code looks correct but you can try using an AutoGenerateColumns and check whether the grid will populate with data.

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
cevdet
Top achievements
Rank 1
answered on 24 Feb 2015, 09:33 AM
Hi Kostadin,

I want to filter RadGrid InSensitive mode, how can I achieve this ?
Thank for future helps.
0
cevdet
Top achievements
Rank 1
answered on 25 Feb 2015, 07:45 AM
Hi again,

I mean, It is not working when I try to filter turkish characters "ı,i,ö,ü,ş,ç,ğ,I,İ,Ö,Ü,Ş,Ç,Ğ" in RadGrid.
For exammple :
Record => Kitap,  Filter => Ä°  (Ä° is uppercase)
Record => KÄ°TAP, Filter => i (i is lowercase)
0
Kostadin
Telerik team
answered on 27 Feb 2015, 06:41 AM
Hello cevdet,

Please try setting the CaseSensitive property to false that will allow you to filter the grid no matter whether the type of the characters. The property is located in the GroupingSettings.
<GroupingSettings CaseSensitive="false" />

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Acadia
Top achievements
Rank 1
Iron
Answers by
Kevin Babcock
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Acadia
Top achievements
Rank 1
Iron
Princy
Top achievements
Rank 2
Robert Schoen
Top achievements
Rank 1
Yavor
Telerik team
Jurgen
Top achievements
Rank 1
newbie
Top achievements
Rank 1
Kevin Kembel
Top achievements
Rank 1
Kamal
Top achievements
Rank 1
Kostadin
Telerik team
cevdet
Top achievements
Rank 1
Share this question
or