Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Querystring Variable in List View?

  Date: Sep 24    Category: Sharepoint    Views: 736

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 that?



12 Answers Found

Answer #1    Answered On: Sep 24    

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: Sep 24    

Is there and good sites, samples, tools, and/or resources for writing SharePoint requirements? In example would I document a functional requirement as:: site XYZ will have a calendar, an announcements section, a news section, there will be a list with x# of metadata columns, and a view that displays… Etc. are those typical types of functional requirements you document and what should be assumptions:: AD is setup and functioning, there will be 2 developer resources provided by client...? What am I supposed to document in the requirements without going overboard and without rehashing OOTB functionality? Anything dealing with writing requirements for SharePoint would be helpful.

Answer #3    Answered On: Sep 24    

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

Answer #4    Answered On: Sep 24    

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 #5    Answered On: Sep 24    

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

Answer #6    Answered On: Sep 24    

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

Answer #7    Answered On: Sep 24    

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, PublicKeyToken=71e9bce111e9429c"%>

<%@ 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 = item["Manager_Id_Number"];

object listItemFirst_NameFieldValue = item["First_Name"];

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() == ManagerIdNum.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: Sep 24    

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

Answer #9    Answered On: Sep 24    

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 #10    Answered On: Sep 24    

Just an off-the-cuff reaction, but if you have to stop and define a term
(e.g. "metadata column") to a business user, then it probably shouldn't be
in functional requirements.

Functional reqs are about what the end user needs to accomplish. A good
guide for this is the concept of the User Story, as employed in Agile
project management. The basic format is as follows:

As a _______ (what type of user),

I want _________

so that I can ___________

This kind of requirement requires (heh) that you also define acceptance
criteria, i.e. a list of end results by which you can determine that the
requirement has been fulfilled.

Answer #11    Answered On: Sep 24    

Thanks Peter, that gives me a good start to think about "reverse
engineering" my meeting notes so to speak, for example in our HR Dept.
meeting with the client, they said something along the lines of "I want to
see a database of all our employees, with things like there demographics,
but also want the see the benefits they enrolled in, their spouse &
children's names, etc. right now we are keeping it in a spreadsheet on my
desktop, backed up to the network share" and they went on with that. So what
you are saying is I should review my notes and put it in as requirements
document as follows:

1.1 -------------------
As the HR Department Employee
I want to see a centralized list of all employees records on our department
so I can drill down into a specific employee record.


So where do I put the specifics of the field values they want to see? I am a
developer at heart that has moved into a PM/BA role, so as a developer I

Employee list view trimmed down for above but then I see:
When they click an individual employee id num (which is the title column
linked to the item) they see all the other Emp info in the view .aspx screen

Really just OOTB functionality, but the project specifics need configured
with SP, but I still need to document it as above b/c we are pretending the
developer has no clue there of? Again where do I put the specifics of the
fields? Do I do another functional requirement based on same user
perspective as below like:

1.2 -------------------
As the HR Department Employee
I want to see a list of all employees information such as: SS#, Emp Name,
Emp Num, benefits type, spouse name, etc. (I would list all in FR)
so I can view or choose to edit the employees information

Seems, like I need to play tech stupid and pretend the developer has no idea
of what I am talking about. Am I on the right track there? Another question,
do I then number them and add to a trace matrix for results on test cases of
the other side, to trace back if something got missed? I came from a very
dysfunctional place where we did none of this, it was met and bang it out
quickly, so it's a bit of an adjustment for me. Thanks Peter appreciate it!

Trace matrix would have
1.0 - Employee records list
1.1 View all records
1.2 View individual records

Answer #12    Answered On: Sep 24    

The specifics would go into the acceptance criteria. As the agile guys
will tell you, a user story is really "a reminder to have a conversation".
The user story gives a broad idea of one particular piece of desired
functionality; from there, the appropriate team members should flesh out
the acceptance criteria so you know when the story is completed. In your
case, one particular criterion for the employee detail page story might
look like this:

"The employee detail view shows the following fields: first name, last
name, employee ID number, current sick days, and favorite kind of dog."

The employee list would be a different story from the employee detail.
Each piece of functionality gets its own story to minimize confusion.

There's a whole lot more to Agile methodology than this, but hopefully you
can already see its value in organizing the thoughts of various team

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