Click here to Skip to main content
15,895,667 members
Articles / Web Development / ASP.NET

SharePoint CAML Query Builder Dialog for your Web Parts

Rate me:
Please Sign up or sign in to vote.
4.65/5 (9 votes)
24 Mar 2009CPOL7 min read 167.7K   847   34  
A SharePoint CAML query builder dialog for your Web Parts
<%@ Page Language="C#" AutoEventWireup="true"  MasterPageFile="~/_layouts/dialog.master" CodeBehind="QueryBuilder.aspx.cs" Inherits="Mullivan.SharePoint.Pages._QueryBuilder,Mullivan.SharePoint.Pages, Version=1.0.1.0, Culture=neutral, PublicKeyToken=c37a514ec27d3057" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register TagPrefix="mul" Namespace="Mullivan.SharePoint.Pages.WebControls" Assembly="Mullivan.SharePoint.Pages, Version=1.0.1.0, Culture=neutral, PublicKeyToken=c37a514ec27d3057" %>

<asp:Content ID="Content1" contentplaceholderid="PlaceHolderDialogHeaderPageTitle" runat="server">
		<asp:Literal runat="server" ID="dialogTitle" />
</asp:Content>
<asp:Content ID="Content2" contentplaceholderid="PlaceHolderAdditionalPageHead" runat="server">
	<SharePoint:ScriptLink ID="ScriptLink1" language="javascript" name="QueryBuilder.js" runat="server" />
	<SharePoint:ScriptLink ID="ScriptLink3" language="javascript" name="FieldValueDialog.js" runat="server" />
	<SharePoint:ScriptLink ID="ScriptLink4" language="javascript" name="MullivanUtility.js" runat="server" />
	<SharePoint:ScriptLink ID="ScriptLink2" language="javascript" name="core.js" runat="server" />
	<script type="text/javascript" language="javascript">
	    function HandleOkClicked() {
	        var strDlgReturnValue = new Array(2);
	        strDlgReturnValue[0] = document.getElementById("<%= qbView.ClientID %>").value;
	        strDlgReturnValue[1] = document.getElementById("<%= qbQuery.ClientID %>").value;
	        var strDlgReturnErr = document.getElementById("<%= qbError.ClientID %>").value;
	        if (strDlgReturnValue[0].length == 0 && strDlgReturnValue[1].length == 0) {
	            alert(QB_NullSelectionText_TEXT);
	        }
	        else {
	            return QB_HandleOkReturnValues(strDlgReturnValue, strDlgReturnErr);
	        }
	    }

	    function OpenFieldValueDialog(ctlColumnId, ctlValueId, siteUrl, list) {

	        var value = document.getElementById(ctlValueId).value;
	        var field = document.getElementById(ctlColumnId).value;

	        var callback = function(results) {
	            FE_SetValue(ctlValueId, results);
	        };

	        value = Mullivan.Utilities.UrlEncode(value);

	        FE_LaunchFieldValueDialog(siteUrl, list, field, value, callback);
	    }

	    function FE_SetValue(ctlValueId, results) {

	        if (results == null || results[0] == null)
	            return;
	            
	        document.getElementById(ctlValueId).value = results[0];

	    }

	</script>
	<SharePoint:FormDigest ID="FormDigest1" runat="server"/>
</asp:Content>
<asp:Content ID="Content3" contentplaceholderid="PlaceHolderDialogImage" runat="server">
	<asp:Image ID="queryBuilderIcon" width="32" height="32" runat="server" />
</asp:Content>
<asp:Content ID="Content4" contentplaceholderid="PlaceHolderDialogDescription" runat="server">
	<asp:Literal runat="server" ID="dialogDescription" />
</asp:Content>
<asp:Content ID="Content5" contentplaceholderid="PlaceHolderHelpLink" runat="server">
</asp:Content>
<asp:Content ID="Content6" contentplaceholderid="PlaceHolderDialogBodyMainSection" runat="server">
	<div id="HiddenFields" >
		<asp:HiddenField ID="qbView" Value="" runat="server" />
		<asp:HiddenField ID="qbQuery" Value="" runat="server" />
		<asp:HiddenField ID="qbError" Value="" runat="server"/>
   </div>
   <div>
   <asp:Panel ID="pnlViewContainer" Visible="false" runat="server">
    <div style="width:100%">
        <div class="ms-dialogbody" style="text-align:left;vertical-align:middle;font-size:9pt;font-weight:bold;color:black;width:100%" >
            &nbsp;View Fields
        </div>
        <div style="padding-top:4px;padding-bottom:4px">
            <table cellpadding="0" cellspacing="0" border="0" >
                <tr>
                    <td>
                        <span>Possible Fields</span>
                    </td>
                    <td rowspan="2" style="vertical-align:middle">
                        <asp:ImageButton ID="ibtnViewFieldsMoveLeft" OnClick="ibtnViewFieldsMoveLeft_Click" runat="server" />
                        <br />
                        <asp:ImageButton ID="ibtnViewFieldsMoveRight" OnClick="ibtnViewFieldsMoveRight_Click" runat="server" />
                    </td>
                    <td>
                        <span >Configured Fields</span>
                    </td>
                    <td rowspan="2" style="vertical-align:middle">
                        <asp:ImageButton ID="ibtnViewFieldsMoveUp" OnClick="ibtnViewFieldsMoveUp_Click" runat="server" />
                        <br />
                        <asp:ImageButton ID="ibtnViewFieldsMoveDown" OnClick="ibtnViewFieldsMoveDown_Click" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:ListBox ID="lboxPossibleViewFields" SelectionMode="Multiple" Width="300" Height="90" runat="server" />
                    </td>
                    <td>
                        <asp:ListBox ID="lboxViewFields" SelectionMode="Multiple"  Width="300" Height="90" runat="server" />
                    </td>
                </tr>
            </table>
        </div>
    </div>
   </asp:Panel>
   <asp:Panel ID="pnlQueryContainer" Visible="false" runat="server">
    <div>
        <div class="ms-dialogbody" style="text-align:left;vertical-align:middle;font-size:9pt;font-weight:bold;color:black;width:100%" >
            &nbsp;Where
        </div>
        <div style="padding-top:4px;padding-left:3px;padding-bottom:4px">
            <table style="width:99%" cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <td rowspan="5">
                        <mul:QueryTreeView ID="tvWhere" Width="300" Height="200"
                            BorderColor="#ece9d8" BorderStyle="Solid" BorderWidth="1"
                            ForeColor="Black" Font-Bold="true" Font-Size="XX-Small"
                            OnSelectedNodeChanged="tvWhere_SelectedNodeChanged" runat="server" NodeIndent="10">
                                <NodeStyle HorizontalPadding="10" />
                                <SelectedNodeStyle BackColor="#ece9d8" HorizontalPadding="10" />
                        </mul:QueryTreeView>
                    </td>
                    <td style="vertical-align:top">
                        <asp:ImageButton ID="ibtnWhereMoveUp" OnClick="ibtnWhereMoveUp_Click" runat="server" />
                    </td>
                    <td rowspan="5" style="vertical-align:middle;width:99%">
                        <asp:Panel style="vertical-align:middle;text-align:center" ID="pnlEditAndOr" Visible="false" runat="server" >
                            <table cellpadding="0" cellspacing="0" border="0">
                                <tr>
                                    <td>
                                        <asp:Label ID="lblNestType" Font-Size="X-Small" Text="Nest Type" runat="server" />
                                        &nbsp;&nbsp;
                                    </td>
                                    <td>
                                        <asp:DropDownList ID="ddlQueryNestType" AutoPostBack="true" runat="server"
                                            OnSelectedIndexChanged="ddlQueryNestType_SelectedIndexChanged">
                                            <asp:ListItem Selected="True" Text="And" Value="And" />
                                            <asp:ListItem Text="Or" Value="Or" />
                                        </asp:DropDownList>
                                    </td>
                                </tr>
                            </table>
                        </asp:Panel>
                        <asp:Panel ID="pnlEditPredicate" style="height:100%;vertical-align:top;padding-top:10px;padding-bottom:10px" Visible="false" runat="server" >
                            <table cellpadding="2" style="font-size:xx-small;height:100%" cellspacing="0" border="0">
                                <tr>
                                    <td style="width:25%;text-align:right;padding-right:5px;">
                                        Column 
                                    </td>
                                    <td>
                                        <asp:DropDownList style="width:230px" ID="ddlQueryColumns"  runat="server" />
                                    </td>
                                </tr>
                                <tr>
                                    <td style="text-align:right;padding-right:5px;">
                                      Comparer
                                    </td>
                                    <td>
                                      <asp:DropDownList ID="ddlQueryComparer" AutoPostBack="true" OnSelectedIndexChanged="ddlQueryComparer_SelectedIndexChanged" runat="server">
                                        <asp:ListItem Text="Begins With" Value="BeginsWith" />
                                        <asp:ListItem Text="Contains" Value="Contains" />
                                        <asp:ListItem Text="=" Value="Eq" />
                                        <asp:ListItem Text="&gt;=" Value="Geq" />
                                        <asp:ListItem Text="&gt;" Value="Gt" />
                                        <asp:ListItem Text="&lt;" Value="Lt" />
                                        <asp:ListItem Text="&lt;=" Value="Leq" />
                                        <asp:ListItem Text="!=" Value="Neq" />
                                        <asp:ListItem Text="Not Null" Value="IsNotNull" />
                                        <asp:ListItem Text="Is Null" Value="IsNull" />
                                      </asp:DropDownList>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="text-align:right;padding-right:5px;">
                                      
                                    </td>
                                    <td>
                                       <asp:CheckBox ID="cboxIsUserInput" Visible="false" Text="User Input" 
                                       runat="server" AutoPostBack="true" OnCheckedChanged="cboxIsUserInput_CheckChanged" />
                                    </td>
                                </tr>
                                <tr style="height:99%">
                                    <td style="text-align:right;padding-right:5px;">
                                      Value
                                    </td>
                                    <td>
                                        <table border="0" cellpadding="0" cellspacing="0">
                                            <tr style="vertical-align:top">
                                                <td>
                                                    <asp:TextBox ID="tboxColumnValue" runat="server" style="width:230px;height:70px" TextMode="MultiLine" />
                                                </td>
                                                <td>
                                                    <asp:Button ID="btnOpenEditDialog" Font-Size="XX-Small" Text="Edit Dialog" runat="server" />
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="text-align:right;padding-right:10px">
                                        <asp:Label ID="lblQuerySaved" Text="Saved" Font-Bold="true" ForeColor="#006600" Font-Size="XX-Small" Visible="False" runat="server" />
                                    </td>
                                    <td style="text-align:right;padding-bottom:5px;vertical-align:bottom;">
                                        <asp:Button ID="btnSaveQuery" Text="Save" Font-Size="XX-Small" Width="60" OnClick="btnSaveQuery_Click" runat="server" />
                                    </td>
                                </tr>
                            </table>
                        </asp:Panel>
                    </td>
                </tr>
                <tr>
                    <td style="vertical-align:top">
                        <asp:ImageButton ID="ibtnWhereMoveDown" OnClick="ibtnWhereMoveDown_Click" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td style="vertical-align:top">
                        <asp:ImageButton ID="ibtnWhereAddNest" ToolTip="Add And/Or" OnClick="ibtnWhereAddNest_Click" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td style="vertical-align:top">
                        <asp:ImageButton ID="ibtnWhereAddPredicate" ToolTip="Add Condition" OnClick="ibtnWhereAddPredicate_Click" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td style="vertical-align:bottom;height:99%;">
                        <asp:ImageButton ID="ibtnWhereRemove" OnClientClick="return confirm('Are you sure you want to delete this item?');" 
                        OnClick="ibtnWhereRemove_Click" runat="server" />
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div>
        <div class="ms-dialogbody" style="text-align:left;vertical-align:middle;font-size:9pt;font-weight:bold;color:black;width:100%" >
            &nbsp;Order By
        </div>
        <div style="padding-top:4px;padding-bottom:4px">
            <table>
                <tr>
                    <td rowspan="3" style="vertical-align:top">
                        <asp:ListBox ID="lboxOrderBy" SelectionMode="Single" style="width:300px;height:60px" runat="server" />
                    </td>
                    <td style="vertical-align:top">
                        <asp:ImageButton ID="ibtnOrderByMoveUp" OnClick="ibtnOrderByMoveUp_Click" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td style="vertical-align:top">
                        <asp:ImageButton ID="ibtnOrderByMoveDown" OnClick="ibtnOrderByMoveDown_Click" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td style="vertical-align:bottom">
                        <asp:ImageButton ID="ibtnOrderByRemove" OnClientClick="return confirm('Are you sure you want to delete this item?');" OnClick="ibtnOrderByRemove_Click" runat="server" />
                    </td>
                </tr>
            </table>
            <table cellpadding="4">
                <tr>
                    <td>
                        <asp:ImageButton ID="ibtnOrderByAdd" OnClick="ibtnOrderByAdd_Click" runat="server" />
                    </td>
                    <td>
                        <asp:DropDownList ID="ddlOrderByColumns" style="width:300px;" runat="server" />
                    </td>
                    <td>
                        <asp:DropDownList ID="ddlOrderByDirection" runat="server" />
                    </td>
                </tr>
            </table>
        </div>
    </div>
   </asp:Panel>
   </div>

</asp:Content>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions