【IT168技术文档】
如何开发自己的查询布局控件:
1)查询布局用户控件可以是任意用户控件,只要实现了CodeArt.SharePoint.SmartQuery.ICamlProvider接口即可。
2)为了简化开发,用户控件可以从 CodeArt.SharePoint.SmartQuery.BaseLayoutControl继承,参考CodeArt_ExampleQueryLayout.ascx的代码:
说明:QueryControl表示一个查询字段,它会按照字段类型呈现不同的样式,如 文本框,下拉列表,时间选择,人员选择等。<%@ Register Tagprefix="codeArt" Namespace="CodeArt.SharePoint.SmartQuery" Assembly="CodeArt.SharePoint.SmartQuery, Version=1.0.0.0, Culture=neutral, PublicKeyToken=df96d56002e5fe16" %> <div> <table> <tr> <td> 标题: </td> <td><codeArt:QueryControl runat="server" FieldName="标题" id="f1" ShowTitle="false" /></td> <td> 截止日期: </td> <td> <codeArt:QueryControl runat="server" FieldName="截止日期" id="f2" ShowTitle="false"/></td> <td> 分配对象: </td> <td> <codeArt:QueryControl runat="server" FieldName="分配对象" id="f3" ShowTitle="false"/></td> <td> 优先级: </td> <td> <codeArt:QueryControl runat="server" FieldName="优先级" id="f4" ShowTitle="false"/></td> <td> <asp:Button runat="Server" Text="查询" ID="btn1" /> </td> </tr> </table> </div>
3)如果要进行更高级的控制,可以重载BaseLayoutControl的QueryExpression属性,来实现自己的查询条件控制。
请参考CodeArt_ExampleQueryLayout2.ascx的代码:
<%@ Control Language="C#" Inherits="CodeArt.SharePoint.SmartQuery.BaseLayoutControl,CodeArt.SharePoint.SmartQuery, Version=1.0.0.0, Culture=neutral, PublicKeyToken=df96d56002e5fe16"%> <%@ Register Tagprefix="codeArt" Namespace="CodeArt.SharePoint.SmartQuery" Assembly="CodeArt.SharePoint.SmartQuery, Version=1.0.0.0, Culture=neutral, PublicKeyToken=df96d56002e5fe16" %> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint" %> <%@ Assembly Name="CodeArt.SharePoint.CamlQuery, Version=1.0.0.0, Culture=neutral, PublicKeyToken=43536cfde91ea799" %> <%@ Import Namespace="CodeArt.SharePoint.CamlQuery" %> <script runat="server"> /// <summary> /// 创建查询表达式 /// </summary> public override CamlExpression QueryExpression { get { CamlExpression expr = null; QueryField title = new QueryField("标题", false); QueryField des = new QueryField("说明", false); if (txtTitle.Text != "") expr = title.Contains(txtTitle.Text); if (txtDes.Text != "") expr = Append( expr , des.Contains( txtDes.Text ) ); return expr ; } } /// <summary> /// 链接查询条件 /// </summary> /// <param name="expr1"></param> /// <param name="expr2"></param> /// <returns></returns> CamlExpression Append( CamlExpression expr1 , CamlExpression expr2 ) { if (expr1 == null) return expr2; else return expr1 && expr2; } </script> <div> <table> <tr> <td> 标题: </td> <td> <asp:TextBox runat="server" ID="txtTitle"></asp:TextBox> </td> <td> 说明: </td> <td> <asp:TextBox runat="server" ID="txtDes"></asp:TextBox></td> <td> <asp:Button runat="Server" Text="查询" ID="btn1" /> </td> </tr> </table> </div>