1

I have sp grid view in my application page, I am binding some data to the sp grid vie, now I want to apply filtering for this grid. I am googling on this one since 2 days, I am unable to get the exact link to my question. Please any suggest me some links.

Here the grid view binding code

protected void BindToDataTable()
        {
            string siteUrl = SPContext.Current.Web.Url;
            using (SPSite oSite = new SPSite(siteUrl))
            {
                using (SPWeb oWeb = oSite.OpenWeb())
                {
                    SPList oListSCat = oWeb.Lists["listHelpDesk"];
                    SPListItemCollection olistItemColl = oListSCat.Items;
                    if (!dt.Columns.Contains("Functional Area"))
                    {
                        dt.Columns.Add("FunctionalArea");
                    }
                    if (!dt.Columns.Contains("Category"))
                    {
                        dt.Columns.Add("Category");
                    }
                    if (!dt.Columns.Contains("SubCategory"))
                    {
                        dt.Columns.Add("SubCategory");
                    }
                    if (!dt.Columns.Contains("Tier"))
                    {
                        dt.Columns.Add("Tier");
                    }
                    if (!dt.Columns.Contains("Region"))
                    {
                        dt.Columns.Add("Region");
                    }
                    if (!dt.Columns.Contains("Subject"))
                    {
                        dt.Columns.Add("Subject");
                    }
                    if (!dt.Columns.Contains("Description"))
                    {
                        dt.Columns.Add("Description");
                    }
                    if (!dt.Columns.Contains("Attachments"))
                    {
                        dt.Columns.Add("Attachments");
                    }
                    foreach (SPListItem listItem in olistItemColl)
                    {
                        DataRow dr = dt.NewRow();

                        string fncArea = listItem["Functional Area"].ToString();
                        dr["FunctionalArea"] = fncArea.Split('#')[1];
                        string cat = listItem["Category"].ToString();
                        dr["Category"] = cat.Split('#')[1];
                        string scat = listItem["Subcategory"].ToString();
                        dr["SubCategory"] = scat.Split('#')[1];
                        string tier = listItem["Tier"].ToString();
                        dr["Tier"] = tier.Split('#')[1];
                        string region = listItem["Region"].ToString();
                        dr["Region"] = region.Split('#')[1];
                        dr["Subject"] = listItem["Subject"].ToString();
                        dr["Description"] = listItem["Description"].ToString();
                        dr["Attachments"] = "Download link";
                        dt.Rows.Add(dr);

                    }
                    ViewState["dt"] = dt; 
                    spgrdView.PagerTemplate = null;
                    //spgrdView.DataBind();
                }
            }
        }


 public void BindToGridFromSession()
        {
            spgrdView.PagerTemplate = null;
            DataTable dt = (DataTable)ViewState["dt"];
            spgrdView.DataSource = dt;
            spgrdView.DataBind();
        }
1

You can try the below code,

oGrid.AllowFiltering = true;
oGrid.FilterDataFields = "Title"; //tells the SPGridView what columns we want to be able to  filter on.
oGrid.FilteredDataSourcePropertyName = "FilterExpression";
oGrid.FilteredDataSourcePropertyFormat = "{1} like '{0}'"; //property provides the format for our filter expression in a SQL-like syntax.

Hope this helps you.

0

Check out this link for filter implementation in SPGrid

http://reversealchemy.nl/building-a-spgridview-control-part-2-filtering/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.