I found something that when i bind SPGridView using SharePoint object model.
The strange thing is that if I use this code everything works fine
SPDataSource dataSource = GetTravelExpenses();
string sCommand = @"<Query><Where>
<Eq>
<FieldRef Name='Travel_x0020_Request' />
<Value Type='Lookup'>" + ddlTravelRequest.SelectedItem.Text + "</Value> </Eq> </Where></Query>";
dataSource.SelectCommand = sCommand;
spGrid.DataSource = dataSource;
spGrid.DataBind();
But when I use this code the CAML query is failing to get data from Travel Request List
SPDataSource dataSource = GetTravelExpenses();
string sCommand = @"<Where>
<Eq>
<FieldRef Name='Travel_x0020_Request' />
<Value Type='Lookup'>" + ddlTravelRequest.SelectedItem.Text + "</Value> </Eq> </Where>";
dataSource.SelectCommand = sCommand;
spGrid.DataSource = dataSource;
spGrid.DataBind();
I found the reason that the <Query></Query> element is missing in the second scenario finally I decided to check this with SPQuery i was shocked that everything works fine
SPQuery query = new SPQuery();
query.Query = @"<Where>
<Eq>
<FieldRef Name='Travel_x0020_Request' />
<Value Type='Lookup'>" + ddlTravelRequest.SelectedItem.Text + "</Value> </Eq> </Where>";
My question is why SPDataSource.SelectCommand is failing to get data from Travel Request List when i use CAML query without <Query></Query> element
If anybody knows answer please…………. share with me…
Tuesday, May 26, 2009
10:36 PM
No comments
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment