Monday 11 February 2013

Create Assembly from user controls(Web User Control in an assembly )


In order to create Assembly from user controls , please follw the below steps:

our assembly name is (Amer.UserControlsLibrary).



1.Create web application using vs2008 or vs 2005 and name it (Amer.UserControlsLibrary).



2.delete Default.aspx and Web.config from (Amer.UserControlsLibrary) application



3.Add new web user control and name it (Login.ascx).

if you look at html code you will see

<%@ Control Language="C#" AutoEventWireup="true"

CodeBehind="Login.ascx.cs" Inherits="Amer.UserControlsLibrary.Login" %>


and if you look at code behined you will see the name space

namespace Amer.UserControlsLibrary



4.change the CodeBehind attribute name to ClassName then add CodeFile="Login.ascx.cs" to step 3.

to get new user control directive like this :

<%@ Control Language="C#" AutoEventWireup="true"

CodeFile="Login.ascx.cs" Inherits="Amer.UserControlsLibrary.UICode.Login"

ClassName="Amer.UserControlsLibrary.UI.Login" %>.



please note from step 4 that

CodeFile="Login.ascx.cs"

ClassName="Amer.UserControlsLibrary.UI.Login"

Inherits="Amer.UserControlsLibrary.UICode.Login"





5.Create New Web User Control and name it UserProfile.ascx and make sure the user control directive is

<%@ Control Language="C#" AutoEventWireup="true"

CodeFile="UserProfile.ascx.cs"

Inherits="Amer.UserControlsLibrary.UICode.UserProfile"

ClassName="Amer.UserControlsLibrary.UI.UserProfile" %>





6.

Saturday 9 February 2013

Paging With SPListItemCollectionPosition

During search about how to implement custom paging in SharePoint List i found many articles like:

http://blogs.msdn.com/b/colbyafrica/archive/2009/02/19/learning-sharepoint-part-vi-list-pagination.aspx

while reading the above article i saw comment from a guy 

Similar example with source code
Step by Step Guide to implement Paging and sorting with SPQuery and SPListItemCollectionPosition

but when i went there (Similar example with source code) and start reading and applying the code i found that there is problem in Previous button and it's not working probably so i start changing the code :





  1. Next and Previous is working very well
  2. sorting using gridview sorting(not dropdownlist)
  3. You can use it without sorting columns ( just remove the  OnSorting="gvTasks_OnSorting") from html Code

Note: to runt the code you must has a List with name Tasks and columns:
  1. Title
  2. Status
  3. StartDate


Here is the Code:


<%--HTML Code--%>

<SharePoint:SPGridView ShowFooter="true" runat="server" AllowSorting="true" OnSorting="gvTasks_OnSorting"  ID="gvTasks" AllowPaging="true"
    PageSize="4" AutoGenerateColumns="false">
    <Columns>
        <asp:BoundField DataField="Title" SortExpression="Title" HeaderText="Task Name" />
        <asp:BoundField DataField="Status" SortExpression="Status" HeaderText="TaskStatus" />
        <asp:BoundField DataField="StartDate" HeaderText="Start Date" />
    </Columns>
</SharePoint:SPGridView>

<table style="float:right; width:100px">
    <tr>
        <td>
            <asp:LinkButton ID="LinkButtonPrevious" runat="server"
                onclick="LinkButtonPrevious_Click"><<</asp:LinkButton>
        </td>
        <td>
           <asp:Label ID="LabelPaging" runat="server" Text="Label"></asp:Label></td>
        <td>
            <asp:LinkButton ID="LinkButtonNext" runat="server"
                onclick="LinkButtonNext_Click">>></asp:LinkButton>
        </td>
    </tr>
</table>



<C# code>