Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Querystring Variable in List View?

  Date: Nov 01    Category: Sharepoint    Views: 2006

In SP2007, I am trying to use a querystring variable in a list view. Is it
possible to do this? In the UI or code? As an example, what I am trying to do is
display all invoices for a certain customer in a view. How can I accomplish



8 Answers Found

Answer #1    Answered On: Nov 01    

Are you using Designer for this? You can create a parameter that gets its
value from the querystring param and then filter your XSLT data view based
on that.

There's more flexibility in the SPD approach, but if you need to go with
out-of-the-box components, you should be able to use a querystring filter
web part and connect it to the list view web part.

Answer #2    Answered On: Nov 01    

No, doing this in Visual Studio..............

Answer #3    Answered On: Nov 01    

Oh. Well, I've never tried to filter a list view in Visual Studio, but if
you can do it in SPD, I'm pretty sure there's a way to do it in VS.NET.

Answer #4    Answered On: Nov 01    

Yeah, that was my thought. But my Google searches keep pointing to SPD though.
Time to break out the SP Object Model poster!

Answer #5    Answered On: Nov 01    

I don't find anything on the SP Object Model poster about filters for a view.

Answer #6    Answered On: Nov 01    

The ListViewWebPart (which you are most likely using to display the view)
has a FilterString property. The format appears to be

myListViewWebPart.FilterString = "FilterField1=ID&FilterValue1=557"

(there seems to be some debate about whether that syntax works, so you
might try FilterField and ValueField without the 1)

If that doesn't work for you, then you can jack in at the SPView level and
change its Query property. This involves writing a little bit of CAML, but
it's really not that bad once you get your head around it.

Answer #7    Answered On: Nov 01    

Here is some object model code that may help you but it is not using SharePoint
per say (running on a separate web page using the SP Master page to look like
it's part of the site):

<%@ Assembly Name="Microsoft.SharePoint, Version=, Culture=neutral,

<%@ Page Language="C#" MasterPageFile="~/_layouts/application.master"

Inherits="Microsoft.SharePoint.WebControls.LayoutsPageBase" %>

<%@ Import Namespace="Microsoft.SharePoint" %>

<%@ Import Namespace="Microsoft.SharePoint.WebControls" %>

<script runat="server">

protected int EmpIdNum = 0;

protected int ManagerIdNum = 0;

protected string Manager_Email = "";

protected string First_Name = "";

protected string MI = "";

protected string Last_Name = "";

protected string Email = "";

protected string Job_Title = "";

private void GetListItemByEmail()


SPSite site = this.Site;

SPWeb web = site.OpenWeb();

SPList list = web.Lists["User_Information"];

SPListItemCollection items = list.Items;

int userfoundcount = 0;

foreach (SPListItem item in items)


if (item["Email"].ToString().ToLower() == Email.ToLower())


object listItemEmailFieldValue = item["Email"];

object listItemTitleFieldValue = item["Title"];

object listItemManager_Id_Number_FieldValue =

object listItemFirst_NameFieldValue =

object listItemMIFieldValue = item["MI"];

object listItemLast_NameFieldValue = item["Last_Name"];

object listItemJob_TitleFieldValue = item["Job_Title"];

if (listItemEmailFieldValue != null)

{ lblInfo.Text = item["Email"].ToString(); }

if (listItemTitleFieldValue != null)

{ EmpIdNum = Convert.ToInt32(item["Title"].ToString());

if (listItemManager_Id_Number_FieldValue != null)

{ ManagerIdNum =
Convert.ToInt32(item["Manager_Id_Number"].ToString()); }

if (listItemFirst_NameFieldValue != null)

{ First_Name = item["First_Name"].ToString(); }

if (listItemMIFieldValue != null)

{ MI = item["MI"].ToString(); }

if (listItemLast_NameFieldValue != null)

{ Last_Name = item["Last_Name"].ToString(); }

if (listItemEmailFieldValue != null)

{ Email = item["Email"].ToString(); }

if (listItemJob_TitleFieldValue != null)

{ Job_Title = item["Job_Title"].ToString(); }

//if (item[""].ToString() != null)

//{ }





if (userfoundcount < 1)


lblInfo.Text = "User not found in the list";




foreach (SPListItem itemL in items)


object listItemTitleFieldValue = itemL["Title"];

if (listItemTitleFieldValue != null)


if (listItemTitleFieldValue.ToString() ==


object listItemEmailFieldValue = itemL["Email"];

if (listItemEmailFieldValue != null)

{ Manager_Email = itemL["Email"].ToString(); }

//Manager_Email = "first getlistitembyemail";





tbxEmpIdNum.Text = Convert.ToString(EmpIdNum);

tbxFirst_Name.Text = First_Name;

tbxMI.Text = MI;

tbxLast_Name.Text = Last_Name;

tbxEmail.Text = Email;

tbxJob_Title.Text = Job_Title;

tbxManager_Email.Text = Manager_Email;



I think the key that is missing in this code would be you catching the query
string on the web page but that is basic asp.net stuff, what you are wanting to
do is iterate thru a list and filter it based on a list item column field value
which is what this code does.

Answer #8    Answered On: Nov 01    

You can accomplish this by using a query string filter web part and connections.
Slightly tricky but doable.

Didn't find what you were looking for? Find more on Querystring Variable in List View? Or get search suggestion and latest updates.