SPWeb web
=
SPControl.GetContextWeb(
this
.Context);
SPList tasks = web.Lists[ this .ListName];
SPQuery query = new SPQuery();
query.Query = @" <Where><Contains>
<FieldRef Name='Title'/><Value Type='Text'>DODONG</Value>
</Contains></Where> " ;
SPListItemCollection items = tasks.GetItems(query);
DataTable table = items.GetDataTable();
dgCustomer1.DataSource = table;
dgCustomer1.DataBind();
解释一下:其中<FieldRef Name='Title'/>,其实我PSP表里的字段为Name,在这里不能用<FieldRef Name='Name'/>,否则查询出错,dgCustomer1显示出来为:
SPList tasks = web.Lists[ this .ListName];
SPQuery query = new SPQuery();
query.Query = @" <Where><Contains>
<FieldRef Name='Title'/><Value Type='Text'>DODONG</Value>
</Contains></Where> " ;
SPListItemCollection items = tasks.GetItems(query);
DataTable table = items.GetDataTable();
dgCustomer1.DataSource = table;
dgCustomer1.DataBind();
ID | Title | Modified | Created | Author | Editor | Attachments | LinkTitleNoMenu | LinkTitle | Age | NickName | RealName | |
7 | DODONG1 | 2006-6-30 15:07:31 | 2006-6-28 21:38:29 | DODONG\Administrator | DODONG\Administrator | 0 | DODONG1 | DODONG1 | 290 | Code Test | Test Sample | Test@gmail.com |