SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can print all list items in the list in the SPGridView:

          SPList list = witryna.Lists["Szczegoly"];
          SPListItemCollection items = list.Items;
          gvListItems.DataSource = items.GetDataTable();

But nothing shows when I want to show specific list items filtered by inputs and dropdowns:

 string SPGridViewQuery = "<Where><And><Eq><FieldRef Name='{0}' /><Value Type='DateTime'>{1}</Value></Eq><Eq><FieldRef Name='Pracownik' /><Value Type='Text'>{2}</Value></Eq></And></Where>";

        var querySzukajacaRekordowTegoSamegoPracownika = new SPQuery();
        if (sprawdzanieUserow())
            querySzukajacaRekordowTegoSamegoPracownika.Query = String.Format(SPGridViewQuery, "Dzien", TextBox3.Text, DropDownList1.SelectedItem.Text);
            querySzukajacaRekordowTegoSamegoPracownika.Query = String.Format(SPGridViewQuery, "Dzien", TextBox3.Text, Microsoft.SharePoint.SPContext.Current.Web.CurrentUser.LoginName.ToLower());
        SPListItemCollection listaRekordowTegoSamegoPracownika = witryna.Lists["Szczegoly"].GetItems(querySzukajacaRekordowTegoSamegoPracownika);

        gvListItems.DataSource = listaRekordowTegoSamegoPracownika.GetDataTable();


I want only retreive the matching list items and show them in SPGridView. How can I do that?

share|improve this question
Your code looks right, do you know which filter is causing no rows to show? Try to simplify the code down til you can narrow down exactly what is going on – Ryan Erickson May 9 '13 at 22:21
First of all I will try look at CAML Query. – Grzegorz Z May 10 '13 at 8:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.