0

I have created a grid view which is binded to a list. I have also created a list view for this particular list with some filtered data. I want to know whether is it possible to bind the sharepoint grid view with a list view instead of binding it to a normal list?

Update I have used this link

to bind my grid view to list

4
  • If i understood you question, you have created a view in a list and you want to bind your grid to this newly created list. Please correct me if i am wrong. Could you please share how you are binding a grid view to a list view?
    – 404
    Apr 29, 2015 at 5:31
  • @404 you are right. I want to bind this grid view to the list view I have created.
    – A Beginner
    Apr 29, 2015 at 6:04
  • Could you please share the code how you have bind the list to grid view please. so i can suggest modification within?
    – 404
    Apr 29, 2015 at 6:37
  • @404 I have updated my question
    – A Beginner
    Apr 29, 2015 at 7:42

2 Answers 2

2

Please update the code of bindToGrid() as below:

protected void bindToGrid()
{
    SPWeb web = SPContext.Current.Web;
    //SPList list = web.Lists["Employee"];
    SPView spView = web.Lists["Employee"].Views[<YOURVIEWNAME>];
    SPQuery spQuery = new SPQuery(spView);
    //SPListItemCollection items = list.Items;
    SPListItemCollection items = web.Lists["Employee"].GetItems(spQuery);
    DataTable dt = new DataTable();
    dt = bindToDataTable(items);
    grid.DataSource = dt;
    grid.DataBind();
}

Basically instead of fetching data from default view, we are making use of SPQuery to specify the view which we want to use. Replace <YOURVIEWNAME> in code with the name of view you want to use.

0

Step By step Simple tutoria is below hope this might be a help

http://sharepoint.kerenapura.com/2013/09/display-sharepoint-list-data-gridview/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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