Geeks With Blogs
Gaurav Taneja Great dreams... never even get out of the box. It takes an uncommon amount of guts to put your dreams on the line, to hold them up and say, "How good or how bad am I?" That's where courage comes in.
Here is an Example

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Text;
using System.IO;
using System.Net;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


public partial class ProfileApproval_PhotoGalleryApproval : System.Web.UI.Page
{
    // variables decleration
    ApprovalUserDetailsBAL objUserDetailBAL = null;
    string strUserType = string.Empty;
    public string strHeadVal = string.Empty;
    public string strImagePath = string.Empty;
    string strUserId = string.Empty;
    string strBack = string.Empty;
    DataTable dtImageGallery;
    private int intPageCount = 0;
   


    protected void Page_Load(object sender, EventArgs e)
    {
        if (ScriptManager.GetCurrent(Page).IsInAsyncPostBack)
        {
            lblMsg.Text = "";
        }   

        if (!IsPostBack)
        {
            lblMsg.Text = "";
            BindUserPhotoGallery(strUserId);
            GetPageNumber();
        }
    }

    /// <summary>
    /// Row command fired on Clicking User Name
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void dlUserGallery_ItemCommand(object source, DataListCommandEventArgs e)
    {
        string strImageId = string.Empty;
        string strMasterId = string.Empty;
        string strPostDate = string.Empty;
        string strCaption = string.Empty;
        HiddenField HdnCaptionVal = null;
        DateTime dtPosted = new DateTime();
        Hashtable htblHederData = new Hashtable();
        objUserDetailBAL = new ApprovalUserDetailsBAL();
        lblMsg.Text = "";

        //performs operation on Approve button click
        if (e.CommandName == AdminConstantKeys.ProfileApproveDetail)
        {
            strImageId = e.CommandArgument.ToString();
            HdnCaptionVal = (HiddenField)e.Item.FindControl(AdminConstantKeys.ProfilehdCaptionVal);
            htblHederData.Add(AdminConstantKeys.AbuseUserIdParam, strUserId);
            htblHederData.Add(AdminConstantKeys.ProfileUserTypeParam, strUserType);
            strCaption = HdnCaptionVal.Value.ToString();
            htblHederData.Add(AdminConstantKeys.ProfileCaptionParamNew, strCaption);

            if (CommonFunction.CheckHeaderStatus(AdminConstantKeys.ProfileHeaderArtistImageApproval))
            {
                lblMsg.Text = objUserDetailBAL.UpdateUserPhotoGalleryImageStatus
                (strImageId, AdminConstantKeys.StatusApproved,
                Convert.ToInt32(Session[AdminConstantKeys.UserID]), AdminConstantKeys.ProfileHeaderArtistImageApproval, htblHederData);
            }
            else
            {
                lblMsg.Text = CommonFunction.GetErrorMessage("ERR4721");
            }

            GetPageNumber();

            if (dlUserGallery.Items.Count == 1)
            {
                if (CurrentPage > 0) CurrentPage -= 1;
            }
            BindUserPhotoGallery(strUserId);
        }

        //performs operation on Decline button click
        if (e.CommandName == AdminConstantKeys.ProfileDeclineDetail)
        {
            strImageId = e.CommandArgument.ToString();
            HdnCaptionVal = (HiddenField)e.Item.FindControl(AdminConstantKeys.ProfilehdCaptionVal);
            htblHederData.Add(AdminConstantKeys.AbuseUserIdParam, strUserId);
            htblHederData.Add(AdminConstantKeys.ProfileUserTypeParam, strUserType);
            strCaption = HdnCaptionVal.Value.ToString();
            htblHederData.Add(AdminConstantKeys.ProfileCaptionParamNew, strCaption);

            if (CommonFunction.CheckHeaderStatus(AdminConstantKeys.ProfileHeaderArtistImageDecline))
            {
                lblMsg.Text = objUserDetailBAL.UpdateUserPhotoGalleryImageStatus(strImageId,
               AdminConstantKeys.StatusDeclined,
               Convert.ToInt32(Session[AdminConstantKeys.UserID]), AdminConstantKeys.ProfileHeaderArtistImageDecline, htblHederData);
            }
            else
            {
                lblMsg.Text = CommonFunction.GetErrorMessage("ERR4722");
            }

            GetPageNumber();

            // checks the count
            if (dlUserGallery.Items.Count == 1)
            {
                if (CurrentPage > 0) CurrentPage -= 1;
            }
            BindUserPhotoGallery(strUserId);

        }
    }

    /// <summary>
    /// Item data Bound functionality for check the image exist or not
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void dlUserGallery_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        bool blnImageExist = true;
        HttpWebRequest myHttpWebRequest;
        HttpWebResponse myHttpWebResponse;

        // checks if the ListItemType is Item or Alternating Item
        if (e.Item.ItemType == ListItemType.Item ||
                e.Item.ItemType == ListItemType.AlternatingItem)
        {           
            Image imgPhoto = (Image)e.Item.FindControl
                (AdminConstantKeys.ProfilelblPhotograph);
            string strPath = imgPhoto.ImageUrl;         

        }
    }


    /// <summary>
    /// functionality on the Decline Button
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDeclineAll_Click(object sender, EventArgs e)
    {
        HiddenField HdnImageVal = null;
        HiddenField HdnCaptionVal = null;
        string strImage = string.Empty;
        string strMsg = string.Empty;
        StringBuilder strCaption = new StringBuilder();
        //StringBuilder strImage = new StringBuilder();
        Hashtable htblHederData = new Hashtable();
        objUserDetailBAL = new ApprovalUserDetailsBAL();
        htblHederData.Add(AdminConstantKeys.AbuseUserIdParam, strUserId);
        htblHederData.Add(AdminConstantKeys.ProfileUserTypeParam, strUserType);
        //traversing all items
        foreach (DataListItem dlPhoto in dlUserGallery.Items)
        {
            HdnImageVal = (HiddenField)dlPhoto.FindControl
                (AdminConstantKeys.ProfilehdImageVal);
            HdnCaptionVal = (HiddenField)dlPhoto.FindControl
                (AdminConstantKeys.ProfilehdCaptionVal);
            strImage += HdnImageVal.Value + ",";
            // strImage.Append(strImage.Value + ",");
            strCaption.Append(HdnCaptionVal.Value + ",");
        }
        htblHederData.Add(AdminConstantKeys.ProfileCaptionParamNew, strCaption);
        if (CommonFunction.CheckHeaderStatus(AdminConstantKeys.ProfileHeaderImageDeclineAll))
        {

            lblMsg.Text = objUserDetailBAL.UpdateAllPhotoGalleryImageStatus
             (strImage, AdminConstantKeys.StatusDeclined,
             Convert.ToInt32(Session[AdminConstantKeys.UserID]), AdminConstantKeys.ProfileHeaderImageDeclineAll, htblHederData);

        }
        else
        {
            lblMsg.Text = CommonFunction.GetErrorMessage("ERR4718");

        }

        if (CurrentPage > 0) CurrentPage -= 1;
        BindUserPhotoGallery(strUserId);


    }

    /// <summary>
    /// functionality on the Approve Button
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnApproveAll_Click(object sender, EventArgs e)
    {
        HiddenField HdnImageVal = null;
        HiddenField HdnCaptionVal = null;
        string strImage = string.Empty;
        //string strCaption = string.Empty;
        string strMsg = string.Empty;
        StringBuilder strCaption = new StringBuilder();
        //StringBuilder strImage = new StringBuilder();
        Hashtable htblHederData = new Hashtable();

        objUserDetailBAL = new ApprovalUserDetailsBAL();
        htblHederData.Add(AdminConstantKeys.AbuseUserIdParam, strUserId);
        htblHederData.Add(AdminConstantKeys.ProfileUserTypeParam, strUserType);
        foreach (DataListItem dlPhoto in dlUserGallery.Items)
        {
            HdnImageVal = (HiddenField)dlPhoto.FindControl(AdminConstantKeys.ProfilehdImageVal);
            HdnCaptionVal = (HiddenField)dlPhoto.FindControl(AdminConstantKeys.ProfilehdCaptionVal);
            strImage += HdnImageVal.Value + ",";

            strCaption.Append(HdnCaptionVal.Value + ",");
        }
        htblHederData.Add(AdminConstantKeys.ProfileCaptionParamNew, strCaption);

        if (CommonFunction.CheckHeaderStatus(AdminConstantKeys.ProfileHeaderImageApprovalAll))
        {

            lblMsg.Text = objUserDetailBAL.UpdateAllPhotoGalleryImageStatus
            (strImage, AdminConstantKeys.StatusApproved,
            Convert.ToInt32(Session[AdminConstantKeys.UserID]), AdminConstantKeys.ProfileHeaderImageApprovalAll, htblHederData);

        }
        else
        {
            lblMsg.Text = CommonFunction.GetErrorMessage("ERR4716");
        }

        if (CurrentPage > 0) CurrentPage -= 1;
        BindUserPhotoGallery(strUserId);
    }

    /// <summary>
    /// Assing the CurrentPage value to View State
    /// </summary>
    public int CurrentPage
    {
        get
        {
            int intCurrentPage = 0;
            // checks the viewstate is null or not
            if ((ViewState[AdminConstantKeys.ProfileCurrentPageViewState] != null)
                && (Convert.ToString(ViewState[AdminConstantKeys.ProfileCurrentPageViewState]) != string.Empty))
                intCurrentPage = Convert.ToInt32(
                    ViewState[AdminConstantKeys.ProfileCurrentPageViewState]);
            return intCurrentPage;
        }
        set
        {
            ViewState.Add(AdminConstantKeys.ProfileCurrentPageViewState, value);
        }
    }

    /// <summary>
    /// functionality on the Approve Button
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("../ProfileApproval/UserPhotoGalleryListing.aspx?Type=A");
    }

    /// <summary>
    /// Binds the data dispalying all the photos of User
    /// </summary>
    /// <param name="strUserId">string type</param>
    //private void GetData(int Flag) BindUserPhotoGallery(strUserId)
    protected void BindUserPhotoGallery(string strUserId)
    {
        DataTable dtbUser;
        dtbUser = new DataTable();
        objUserDetailBAL = new ApprovalUserDetailsBAL();

        dtbUser = objUserDetailBAL.GetUserPhotoList(strUserId);
        dtImageGallery = dtbUser;
        PagedDataSource ObjPDS = new PagedDataSource();

        ObjPDS.DataSource = dtImageGallery.DefaultView;
        ObjPDS.AllowPaging = true;
        ObjPDS.PageSize = Convert.ToInt32(ConfigurationManager.AppSettings
            [AdminConstantKeys.ProfileDatalistPageSize].ToString());
        ObjPDS.CurrentPageIndex = CurrentPage;

        // checks if the datable if row count greater than zero
        if (dtImageGallery.Rows.Count > 0)
        {
            dlUserGallery.DataSource = ObjPDS;
            dlUserGallery.DataBind();
            lblNorec.Visible = false;
        }
        else
        {
            dlUserGallery.DataSource = ObjPDS;
            dlUserGallery.DataBind();
            lblNorec.Visible = true;
            buttonRow.Visible = false;
            tab2.Visible = false;
        }

        intPageCount = ObjPDS.PageCount;

        ViewState[AdminConstantKeys.ProfileViewStPageCount] = intPageCount;
        if (intPageCount > 1)
        {
            int[] intPageNumbers = new int[intPageCount];
            for (int intIndex = 0; intIndex < intPageCount; intIndex++) intPageNumbers[intIndex] = intIndex + 1;
            lblPage.Text = AdminConstantKeys.ProfilePage +
                Convert.ToString(CurrentPage + 1) + AdminConstantKeys.ProfileOf
                + Convert.ToString(intPageCount);

            tab2.Visible = true;
            // checks if current page is zero
            if (CurrentPage == 0)
            {
                btnBottomNext.ImageUrl = AdminConstantKeys.PagerNextImage;
                btnBottomNext.Enabled = true;
                btnBottomNext.CssClass = AdminConstantKeys.Blank;
                btnBottomNext.Style.Add("cursor", "pointer");
                btnBottomPrev.ImageUrl = AdminConstantKeys.PagerFirstImage;
                btnBottomPrev.Enabled = false;
                btnBottomPrev.CssClass = AdminConstantKeys.Blank;
                btnBottomPrev.Style.Add("cursor", "default");
            }
            else
            {
                btnBottomNext.ImageUrl = AdminConstantKeys.PagerLastImage;
                btnBottomNext.Enabled = true;
                btnBottomNext.CssClass = AdminConstantKeys.Blank;
                btnBottomNext.Style.Add("cursor", "pointer");
                btnBottomPrev.ImageUrl = AdminConstantKeys.PagerPrevImage;
                btnBottomPrev.Enabled = true;
                btnBottomPrev.CssClass = AdminConstantKeys.Blank;
                btnBottomPrev.Style.Add("cursor", "pointer");
            }

        }
        else
        {
            lblPage.Text = AdminConstantKeys.ProfilePage +
                Convert.ToString(CurrentPage + 1) + AdminConstantKeys.ProfileOf
                + Convert.ToString(intPageCount);
            btnBottomNext.ImageUrl = AdminConstantKeys.PagerLastImage;
            btnBottomNext.Enabled = false;
            btnBottomNext.CssClass = AdminConstantKeys.Blank;
            btnBottomNext.Style.Add("cursor", "default");
            btnBottomPrev.ImageUrl = AdminConstantKeys.PagerFirstImage;
            btnBottomPrev.Enabled = false;
            btnBottomPrev.CssClass = AdminConstantKeys.Blank;
            btnBottomPrev.Style.Add("cursor", "default");


        }

    }

    /// <summary>
    /// Performing functionality to get the PageNumber
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void GetPageNumber()
    {
        int intPageCount1 = Convert.ToInt32(
            ViewState[AdminConstantKeys.ProfileViewStPageCount]);
        int[] intPageNumbers = new int[intPageCount1];

        // initialize the page number
        for (int intIndex = 0; intIndex < intPageCount; intIndex++)
        {
            intPageNumbers[intIndex] = intIndex + 1;
        }
    }

    /// <summary>
    /// Performing functionality on Next button click
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ImageNext_Click(object sender, ImageClickEventArgs e)
    {
        lblMsg.Text = "";
        // checks the current page value
        if (CurrentPage < Convert.ToInt32(
            ViewState[AdminConstantKeys.ProfileViewStPageCount]) - 1)
            CurrentPage += 1;

        BindUserPhotoGallery(strUserId);

        if (intPageCount == CurrentPage + 1)
        {
            btnBottomNext.ImageUrl = AdminConstantKeys.PagerLastImage;
            btnBottomNext.Enabled = false;
            btnBottomNext.CssClass = AdminConstantKeys.Blank;
            btnBottomNext.Style.Add("cursor", "default");
            btnBottomPrev.ImageUrl = AdminConstantKeys.PagerPrevImage;
            btnBottomPrev.Enabled = true;
            btnBottomPrev.CssClass = AdminConstantKeys.Blank;
            btnBottomPrev.Style.Add("cursor", "pointer");
        }
        else
        {
            btnBottomNext.ImageUrl = AdminConstantKeys.PagerNextImage;
            btnBottomNext.Enabled = true;
            btnBottomNext.CssClass = AdminConstantKeys.Blank;
            btnBottomNext.Style.Add("cursor", "pointer");
            btnBottomPrev.ImageUrl = AdminConstantKeys.PagerPrevImage;
            btnBottomPrev.Enabled = true;
            btnBottomPrev.CssClass = AdminConstantKeys.Blank;
            btnBottomPrev.Style.Add("cursor", "pointer");

        }
    }

    /// <summary>
    /// Performing functionality on previous button click
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ImagePrevious_Click(object sender, ImageClickEventArgs e)
    {
        lblMsg.Text = "";
        if (CurrentPage > 0) CurrentPage -= 1;

        BindUserPhotoGallery(strUserId);
        // enables buttons accordingly when page number is zero
        if (CurrentPage == 0)
        {
            btnBottomPrev.ImageUrl = AdminConstantKeys.PagerFirstImage;
            btnBottomPrev.Enabled = false;
            btnBottomPrev.CssClass = AdminConstantKeys.Blank;
            btnBottomPrev.Style.Add("cursor", "default");
            btnBottomNext.ImageUrl = AdminConstantKeys.PagerNextImage;
            btnBottomNext.Enabled = true;
            btnBottomNext.CssClass = AdminConstantKeys.Blank;
            btnBottomNext.Style.Add("cursor", "pointer");
        }
        else
        {
            btnBottomNext.ImageUrl = AdminConstantKeys.PagerNextImage;
            btnBottomNext.Enabled = true;
            btnBottomNext.CssClass = AdminConstantKeys.Blank;
            btnBottomNext.Style.Add("cursor", "pointer");
            btnBottomPrev.ImageUrl = AdminConstantKeys.PagerPrevImage;
            btnBottomPrev.Enabled = true;
            btnBottomPrev.CssClass = AdminConstantKeys.Blank;
            btnBottomPrev.Style.Add("cursor", "pointer");
        }
    }

    /// <summary>
    /// Wraps the text content
    /// </summary>
    /// <param name="objDescription">object</param>
    /// <param name="intNum">int</param>
    /// <returns></returns>
    protected string WrapDescription(object objDescription, int intNum)
    {
        return Server.HtmlEncode(CommonFunction.WrapCharacters(objDescription, intNum));
    }

    /// <summary>
    /// Action performed on Back Button
    /// </summary>
    /// <param name="sender">object</param>
    /// <param name="e"></param>
    protected void lnkBack_Click(object sender, EventArgs e)
    {
        if(strBack.Equals(AdminConstantKeys.ProfileTrue))
        {
            Response.Redirect("../ProfileApproval/UserPhotoGalleryListing.aspx?Type=B");
        }
        else
        {
        Response.Redirect("../ProfileApproval/UserPhotoGalleryListing.aspx?Type=" + strUserType);
        }
    } 

} Posted on Wednesday, April 2, 2008 10:18 PM .Net | Back to top


Comments on this post: Paging in Datalist + custom Paging + .Net

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Gaurav Taneja | Powered by: GeeksWithBlogs.net