Hi all,
I have a Calendar wp that I have modified to allow result filtering via a Views 
dropdown. I'm trying to pass the selected View's title to the SPQuery in order 
to pre-filter the results. But she ain't working.
This is my query.
void cal_DataBinding(object sender, EventArgs e)
{
    if (!string.IsNullOrEmpty(WebId) && !string.IsNullOrEmpty(listName))
    {
        using (SPWeb web = SPContext.Current.Site.OpenWeb(new Guid(WebId)))
        {
            // Check/Get supplied list view
            SPView view = web.Lists[listName].Views[viewName];
            // Pass list view to the query
            SPQuery query = new SPQuery(view);
            query.CalendarDate = cal.VisibleDate;
            query.ExpandRecurrence = true;
            query.Query = "<Where>" +
                "<DateRangesOverlap>" +
                "<FieldRef Name=\"" + dateField + "\"></FieldRef>" +
                "<FieldRef Name=\"" + endDateField + "\"></FieldRef>" +
                "<FieldRef Name=\"RecurrenceID\"></FieldRef>" +
                "<Value Type=\"DateTime\"><Month/></Value>" +
                "</DateRangesOverlap></Where>";
            events = web.Lists[listName].GetItems(query);
        }
    }
}
I'm receiving the following exception, irrespective of which view is selected.
System.ArgumentException: Value does not fall within the expected range.
at Microsoft.SharePoint.SPFieldMap.GetColumnNumber(String strFieldName)
at Microsoft.SharePoint.SPListItemCollection.GetRawValue(String fieldname, 
Int32 iIndex)
at Microsoft.SharePoint.SPListItem.GetValue(SPField fld, Int32 columnNumber, 
Boolean bRaw)
at Microsoft.SharePoint.SPListItem.get_Item(Guid fieldId)
at CalendarWebpart.CalendarWebpart.cal_DayRender(Object sender, 
DayRenderEventArgs e)

The viewName is a string which gets its value from the following dropdown:

cboView.Items.Add(new ListItem(view.Title, view.Title));

If I remove the view from the SPQuery everything works fine.

          SPQuery query = new SPQuery(view);

Regards,

Paul

--
Online Developer/SharePoint Administrator,
ICT Infrastructure Team
CEO Sydney


_______________________________________________
ozmoss mailing list
ozmoss@ozmoss.com
http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss

Reply via email to