Click here to Skip to main content
15,881,898 members
Home / Discussions / C#
   

C#

 
GeneralRe: linq in c# Pin
Simon_Whale20-Aug-14 5:17
Simon_Whale20-Aug-14 5:17 
GeneralRe: linq in c# Pin
saharmirzaei20-Aug-14 5:37
saharmirzaei20-Aug-14 5:37 
GeneralRe: linq in c# Pin
Simon_Whale20-Aug-14 5:45
Simon_Whale20-Aug-14 5:45 
GeneralRe: linq in c# Pin
saharmirzaei20-Aug-14 5:52
saharmirzaei20-Aug-14 5:52 
GeneralRe: linq in c# Pin
Jameel VM20-Aug-14 19:31
Jameel VM20-Aug-14 19:31 
AnswerRe: linq in c# Pin
Ravi Bhavnani19-Aug-14 6:22
professionalRavi Bhavnani19-Aug-14 6:22 
QuestionFind value that is not filled by AutoCompleteExtender Pin
gurusarma18-Aug-14 17:15
gurusarma18-Aug-14 17:15 
QuestionPaging Problem using c# PagedDataSource, Stored Procedure, asp.net repeater Pin
TeresaScott18-Aug-14 9:12
TeresaScott18-Aug-14 9:12 
I am trying to page my results. However, my Next Link and my Last Link always bring up my first page. I cannot get to the second page of results.
Might anyone have any idea as to what I am doing wrong?

namespace ClassesnWorkshops
{
    public partial class _Default : System.Web.UI.Page
    {
        #region Web Form Designer generated code
        
        protected System.Web.UI.WebControls.RadioButton rdoProduct;
        protected System.Web.UI.WebControls.Image Image1;

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.cmdSearch.Click += new System.EventHandler(this.cmdSearch_Click);
            this.Load += new System.EventHandler(this.Page_Load);
        }

        #endregion


        #region "Local Variables and Declarations"

        private const bool blnAllowPaging = true;
        private const int iPageSize = 5;

        //private static 
        PagedDataSource pgdProducts = new PagedDataSource();

        #endregion

                

        #region Page_Load
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {                
                //Hide results controls
                rptClasses.Visible = false;
                lblMessage.Text = "";
                //set previous link, next link and page# labels to invisible.
                lblCurrentPage.Visible = true;
                lnkNext.Visible = true;
                lnkPrevious.Visible = true;

                //Populate within values (real app would pull from DB)
                cboWithin.Items.Add("Only this zip");
                cboWithin.Items[cboWithin.Items.Count - 1].Value = "0";
                cboWithin.Items.Add("5 miles");
                cboWithin.Items[cboWithin.Items.Count - 1].Value = "5";
                cboWithin.Items.Add("10 miles");
                cboWithin.Items[cboWithin.Items.Count - 1].Value = "10";
                cboWithin.Items.Add("25 miles");
                cboWithin.Items[cboWithin.Items.Count - 1].Value = "25";
                cboWithin.Items.Add("50 miles");
                cboWithin.Items[cboWithin.Items.Count - 1].Value = "50";
                cboWithin.Items.Add("100 miles");
                cboWithin.Items[cboWithin.Items.Count - 1].Value = "100";
                cboWithin.Items.Add("200 miles");
                cboWithin.Items[cboWithin.Items.Count - 1].Value = "200";
                cboWithin.Items.Add("No limit");
                cboWithin.Items[cboWithin.Items.Count - 1].Value = "999";
            }                
        }
        #endregion



        #region "Footer LinkButtons"

        protected void lnkFirst_Click(object sender, EventArgs e)
        {
            //Set viewstatevariable to the next page.
            NowViewing = 0;

            //Reload Control
            BindRepeater();
        }

        protected void lnkPrev_Click(object sender, EventArgs e)
        {
            //Set viewstatevariable to the next page.
            //CurrentPage -= 1;
            NowViewing--;

            //Reload Control
            BindRepeater();
        }

        protected void lnkNext_Click(object sender, EventArgs e)
        {            
            //Set viewstatevariable to the next page
            //CurrentPage += 1;
            NowViewing++;
            //Reload control
            BindRepeater();
        }

        protected void lnkLast_Click(object sender, EventArgs e)
        {
            //Set viewstatevariable to the previous page
            NowViewing = pgdProducts.PageCount - 1;

            //Reload control
            BindRepeater();
        }

        #endregion


        #region "Footer DropDownList"

        protected void ddlpageNumbers_SelectedIndexChanged(object sender, EventArgs e)
        {
            //pgdProducts.PageSize = int.Parse(ddlpageNumbers.SelectedValue);
            NowViewing = ddlpageNumbers.SelectedIndex;
            BindRepeater();
        }

        #endregion


        #region "Custom Functions"

        private void BindRepeater()
        {
            pgdProducts.AllowPaging = blnAllowPaging;
            pgdProducts.PageSize = iPageSize;
            pgdProducts.DataSource = GetProductsDataView();

            pgdProducts.CurrentPageIndex = NowViewing;
            //lblTotalPages.Text = pgdProducts.PageCount.ToString();
            FillPagesDropDownList(pgdProducts.PageCount);
            //tell what page number the user is on and how many pages of results there are total.
            //lblCurrentPageBottom.Text = "Showing Page " + CurPage.ToString() + " of " + pagesCount + " ";
            lblCurrentPage.Text = "Now Showing Page " + (NowViewing + 1).ToString() + " of " + pgdProducts.PageCount.ToString();
            lblItemsPerPage.Text = (pgdProducts.Count).ToString() + " items per page.";
            //lblTotalItemCount.Text = (objPds.Count * objPds.PageCount).ToString() + " total number of items that your search returned.";
            lblTotalItemCount.Text = (pgdProducts.DataSourceCount).ToString() + " total number of items that your search returned.";

            lnkFirst.Enabled = !pgdProducts.IsFirstPage;
            lnkPrevious.Enabled = !pgdProducts.IsFirstPage;
            lnkNext.Enabled = !pgdProducts.IsLastPage;
            lnkLast.Enabled = !pgdProducts.IsLastPage;
            ddlpageNumbers.SelectedIndex = pgdProducts.CurrentPageIndex;

            rptClasses.DataSource = pgdProducts;
            rptClasses.DataBind();
        }

        private DataView GetProductsDataView()
        {
            DataTable dtProductsTemp = new DataTable();
            using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnStr"]))
            {                
                using (SqlDataAdapter adapProducts = new SqlDataAdapter("cmd", conn))
                {
                    SqlParameter[] arParms = new SqlParameter[3];
                    arParms[0] = new SqlParameter("@Zipcode", SqlDbType.Char);
                    arParms[0].Value = txtZipCode.Text;
                    arParms[1] = new SqlParameter("@Miles", SqlDbType.Decimal);
                    arParms[1].Value = Int16.Parse(cboWithin.SelectedItem.Value);
                    arParms[2] = new SqlParameter("@Subject", SqlDbType.Char);
                    arParms[2].Value = txtSearchWords.Text;

                    DataSet ds = new DataSet();

                    ds = SqlHelper.ExecuteDataset(ConfigurationManager.ConnectionStrings["ClassesnWorkshops.Properties.Settings.ConnectionString"].ConnectionString,
                        CommandType.StoredProcedure, "spHouses_GetNearZipcode", arParms);

                    dtProductsTemp = ds.Tables[0];
                }
            }
            return dtProductsTemp.DefaultView;            
        }


        private void FillPagesDropDownList(int iTotalPages)
        {
            ddlpageNumbers.Items.Clear();
            for (int i = 1; i <= iTotalPages; i++)
            {
                ddlpageNumbers.Items.Add(new ListItem(i.ToString(), i.ToString()));
            }
        }

        #endregion


        #region "Properties"
        
        //int thisPageNumber;
        private int NowViewing
        {
            get
            {
                object obj = ViewState["_NowViewing"];
                if (obj == null)
                    return 0;
                else
                    return (int)obj;
                //return this.thisPageNumber;
            }
            set
            {
                this.ViewState["_NowViewing"] = value;
                //this.thisPageNumber = value;
            }
        }

        #endregion


        #region cmdSearch_Click
        protected void cmdSearch_Click(object sender, EventArgs e)
        {
            DataTable objDT = null;
			try
			{
				//Query the database for classes
                objDT = GetProductsDataView().ToTable();                
                BindRepeater();

				//Any classes found?
				if (objDT.Rows.Count == 0)
				{
					//None found - hide repeater, show message
					rptClasses.Visible = false;
					lblMessage.Text = "No results found";
				}
				else
				{
					// //Houses found - show repeater, hide message					
					rptClasses.Visible = true;
					lblMessage.Text = "";                    
                }
			}
			catch (Exception ex)
			{
				//Add your own error handling here
				lblMessage.Text = "Error: " + ex.ToString();
			}
			finally
            {			
				//Release memory
				objDT = null;
            }           
        }
        #endregion
                       
  } 
}

TRS

AnswerRe: Paging Problem using c# PagedDataSource, Stored Procedure, asp.net repeater Pin
TeresaScott19-Aug-14 9:23
TeresaScott19-Aug-14 9:23 
Questionartificial immune system implemintation Pin
Member 1067159618-Aug-14 6:14
Member 1067159618-Aug-14 6:14 
AnswerRe: artificial immune system implemintation Pin
Eddy Vluggen18-Aug-14 7:06
professionalEddy Vluggen18-Aug-14 7:06 
GeneralRe: artificial immune system implemintation Pin
Member 1067159618-Aug-14 9:31
Member 1067159618-Aug-14 9:31 
GeneralRe: artificial immune system implemintation Pin
Bernhard Hiller18-Aug-14 21:02
Bernhard Hiller18-Aug-14 21:02 
GeneralRe: artificial immune system implemintation Pin
Eddy Vluggen18-Aug-14 22:27
professionalEddy Vluggen18-Aug-14 22:27 
AnswerRe: artificial immune system implemintation Pin
Ravi Bhavnani18-Aug-14 8:02
professionalRavi Bhavnani18-Aug-14 8:02 
GeneralRe: artificial immune system implemintation Pin
Member 1067159618-Aug-14 9:26
Member 1067159618-Aug-14 9:26 
GeneralRe: artificial immune system implemintation Pin
Ravi Bhavnani18-Aug-14 9:52
professionalRavi Bhavnani18-Aug-14 9:52 
AnswerRe: artificial immune system implemintation Pin
Pete O'Hanlon19-Aug-14 2:10
mvePete O'Hanlon19-Aug-14 2:10 
Questionthe most universal barcode symbology Pin
Jassim Rahma18-Aug-14 4:05
Jassim Rahma18-Aug-14 4:05 
AnswerRe: the most universal barcode symbology Pin
Richard MacCutchan18-Aug-14 4:15
mveRichard MacCutchan18-Aug-14 4:15 
AnswerRe: the most universal barcode symbology Pin
Eddy Vluggen18-Aug-14 4:52
professionalEddy Vluggen18-Aug-14 4:52 
AnswerRe: the most universal barcode symbology Pin
OriginalGriff18-Aug-14 5:04
mveOriginalGriff18-Aug-14 5:04 
GeneralRe: the most universal barcode symbology Pin
Jassim Rahma18-Aug-14 5:08
Jassim Rahma18-Aug-14 5:08 
AnswerRe: the most universal barcode symbology Pin
jschell18-Aug-14 11:45
jschell18-Aug-14 11:45 
AnswerRe: the most universal barcode symbology Pin
Gerry Schmitz18-Aug-14 13:08
mveGerry Schmitz18-Aug-14 13:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.