There are several ways to find one or more polls:
Let’s examine the examples for each of the ways to find one or more polls:
Get poll by searching for a poll with specific ID:
| GetPollById(Guid id) |
Copy Code |
|
// create a new instace of PollManager Telerik.Polls.PollManager pollManager = new Telerik.Polls.PollManager();
// Since we don't know ID of any of the polls we'll get all polls and use the first
one
// to retrieve a specific poll. Typically, this way of getting a poll would be used in conjuction
// with GridView or some similar control, when you get the primary key and then need
// to retrieve a poll based on that primary key.
// The GetAllPolls method returns an object of type IList<IPollItem>,
// so we create a list of all polls. IList<Telerik.Polls.IPollItem> listOfPolls =
pollManager.GetAllPolls(); if (listOfPolls.Count > 0)
{
Telerik.Polls.IPollItem firstPoll = (Telerik.Polls.IPollItem)listOfPolls[0];
// get the ID of the first poll which we will use to retrieve the poll
// (this is a redundant step since we already have the poll, but is used here to
// demonstrate the approach)
Guid pollId = firstPoll.ID;
Telerik.Polls.IPollItem thePoll = pollManager.GetPollById(pollId);
// write the list name to see the result
Response.Write(thePoll.Title);
}
|
Get all polls in the Polls module for the specified provider:
| GetAllPolls() |
Copy Code |
|
// create a new instance of PollManager Telerik.Polls.PollManager pollManager = new Telerik.Polls.PollManager(); // get all polls IList<Telerik.Polls.IPollItem> listOfAllPolls = pollManager.GetAllPolls(); // write the name of every poll to
see the result foreach (Telerik.Polls.IPollItem poll in
listOfAllPolls)
{
Response.Write(poll.Title + "<br />");
}
|
Get a specific subset of polls filtered by a query:
For the following properties of the PollsQueryFilter class: Title, Owner, Culture,
ShowActive, the GetPolls(PollsQueryFilter queryFilter) method uses different operators in order to filter poll items. It
uses the Like operator for Title and Owner, while for the rest of the properties it uses the Equal operator. This means that a filter "My Poll" will match a
poll titled "My Poll" as well as on titled "My Poll 1".
| GetPolls(PollsQueryFilter queryFilter) |
Copy Code |
|
// create a new instance of PollManager Telerik.Polls.PollManager pollManager = new Telerik.Polls.PollManager(); // we need to create a PollsQueryFilter object and
assign a filter query Telerik.Polls.WebControls.PollsQueryFilter pollsQuery = new
Telerik.Polls.WebControls.PollsQueryFilter(); // filter polls by title pollsQuery.Title = "My Poll"; //call GetPolls method overload
with the created query IList<Telerik.Polls.IPollItem> listFilteredPolls =
pollManager.GetPolls(pollsQuery); //display the filtered and ordered polls foreach
(Telerik.Polls.IPollItem filteredPoll in listFilteredPolls
Response.Write(filteredPoll.Title + "<br />");
|
Get a specific subset of polls filtered by a query and sort expression:
| GetPolls(PollsQueryFilter queryFilter, string sortExp) |
Copy Code |
|
// create a new instance of PollManager Telerik.Polls.PollManager pollManager = new Telerik.Polls.PollManager(); // create the query to filter
polls Telerik.Polls.WebControls.PollsQueryFilter pollsQuery = new Telerik.Polls.WebControls.PollsQueryFilter(); // filter polls by title pollsQuery.Title = "My Poll"; // create sorting expression
to sort titles in descending order string sortExpression = "Title
DESC"; // get polls by query and sorting expression IList<Telerik.Polls.IPollItem> listFilteredPolls = pollManager.GetPolls(pollsQuery, sortExpression); //display the filtered and ordered polls foreach (Telerik.Polls.IPollItem
filteredPoll in listFilteredPolls)
Response.Write(filteredPoll.Title + "<br />");
|
See Also