How do you bind a Datalist that has paging with dropdown list?
<p>I'm new to asp.net and have some clue but not sure how to do this so any help would be great thank you.</p>

<p>I have a Datalist with paging how do the update the datalist from user input via Dropdown list which will bind my datalist and paging?</p>

<p>My private properties</p>

<pre><code>private int CurrentPage
    {
        get
        {
            object objPage = ViewState["_CurrentPage"];
            int _CurrentPage = 0;
            if (objPage == null)
            {
                _CurrentPage = 0;
            }
            else
            {
                _CurrentPage = (int)objPage;
            }
            return _CurrentPage;
        }
        set { ViewState["_CurrentPage"] = value; }
    }
    private int fistIndex
    {
        get
        {

            int _FirstIndex = 0;
            if (ViewState["_FirstIndex"] == null)
            {
                _FirstIndex = 0;
            }
            else
            {
                _FirstIndex = Convert.ToInt32(ViewState["_FirstIndex"]);
            }
            return _FirstIndex;
        }
        set { ViewState["_FirstIndex"] = value; }
    }
    private int lastIndex
    {
        get
        {

            int _LastIndex = 0;
            if (ViewState["_LastIndex"] == null)
            {
                _LastIndex = 0;
            }
            else
            {
                _LastIndex = Convert.ToInt32(ViewState["_LastIndex"]);
            }
            return _LastIndex;
        }
        set { ViewState["_LastIndex"] = value; }
    }
</code></pre>

<p>Private methods</p>

<pre><code>private void BindItemsList()
    {

        DataTable dataTable = dm.GetDataTable().Tables["product"];// middle tier which pulls data from a database
        _PageDataSource.DataSource = dataTable.DefaultView;
        _PageDataSource.AllowPaging = true;
        _PageDataSource.PageSize = 1;
        _PageDataSource.CurrentPageIndex = CurrentPage;
        ViewState["TotalPages"] = _PageDataSource.PageCount;

        this.lblPageInfo.Text = "Page " + (CurrentPage + 1) + " of " + _PageDataSource.PageCount;
        this.lbtnPrevious.Enabled = !_PageDataSource.IsFirstPage;
        this.lbtnNext.Enabled = !_PageDataSource.IsLastPage;
        this.lbtnFirst.Enabled = !_PageDataSource.IsFirstPage;
        this.lbtnLast.Enabled = !_PageDataSource.IsLastPage;

        this.dlPhones.DataSource = _PageDataSource;
        this.dlPhones.DataBind();
        this.doPaging();
    }

    /// &lt;summary&gt;
    /// Binding Paging List
    /// &lt;/summary&gt;
    private void doPaging()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("PageIndex");
        dt.Columns.Add("PageText");

        fistIndex = CurrentPage - 5;


        if (CurrentPage &gt; 5)
        {
            lastIndex = CurrentPage + 5;
        }
        else
        {
            lastIndex = 10;
        }
        if (lastIndex &gt; Convert.ToInt32(ViewState["TotalPages"]))
        {
            lastIndex = Convert.ToInt32(ViewState["TotalPages"]);
            fistIndex = lastIndex - 10;
        }

        if (fistIndex &lt; 0)
        {
            fistIndex = 0;
        }

        for (int i = fistIndex; i &lt; lastIndex; i++)
        {
            DataRow dr = dt.NewRow();
            dr[0] = i;
            dr[1] = i + 1;
            dt.Rows.Add(dr);
        }

        this.dlPaging.DataSource = dt;
        this.dlPaging.DataBind();
    }
</code></pre>

<p>Code behind page code</p>

<pre><code>protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.BindItemsList();
        }
    }//end of page load
    protected void lbtnNext_Click(object sender, EventArgs e)
    {

        CurrentPage += 1;
        this.BindItemsList();

    }
    protected void lbtnPrevious_Click(object sender, EventArgs e)
    {
        CurrentPage -= 1;
        this.BindItemsList();

    }
    protected void dlPaging_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName.Equals("Paging"))
        {
            CurrentPage = Convert.ToInt16(e.CommandArgument.ToString());
            this.BindItemsList();
        }
    }
    protected void dlPaging_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        LinkButton lnkbtnPage = (LinkButton)e.Item.FindControl("lnkbtnPaging");
        if (lnkbtnPage.CommandArgument.ToString() == CurrentPage.ToString())
        {
            lnkbtnPage.Enabled = false;
            lnkbtnPage.Style.Add("fone-size", "14px");
            lnkbtnPage.Font.Bold = true;

        }
    }
    protected void lbtnLast_Click(object sender, EventArgs e)
    {

        CurrentPage = (Convert.ToInt32(ViewState["TotalPages"]) - 1);
        this.BindItemsList();

    }
    protected void lbtnFirst_Click(object sender, EventArgs e)
    {

        CurrentPage = 0;
        this.BindItemsList();


    }
</code></pre>

<p>asp.net front page</p>

<pre><code>&lt;asp:Label ID="lblSearch" runat="server" Text="Search By Phone"&gt;&lt;/asp:Label&gt;
                &lt;asp:DropDownList ID="ddlCat" runat="server"&gt;
                    &lt;asp:ListItem&gt;Nokia&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Samsung&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Motorola&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Sony&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Ericsson&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Sony&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;LG&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Apple&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;HTC&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;BlackBerry&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;HP&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Huawei&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Acer&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Asus&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Dell&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Alcatel&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Vodafone&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;T-Mobile&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Toshiba&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Gigabyte&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Pantech&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;ZTE&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Micromax&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;BLU&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Spice&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Icemobile&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;verykool&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Vertu&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Celkon&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;NIU&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Yezz&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Parla&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Plum&lt;/asp:ListItem&gt;
                    &lt;asp:ListItem&gt;Sim Card&lt;/asp:ListItem&gt;
                &lt;/asp:DropDownList&gt;
                &lt;asp:DataList ID="dlPhones" runat="server" DataKeyField="PID" RepeatDirection="Horizontal" RepeatColumns="1" CellPadding="10" CellSpacing="10" &gt;
                    &lt;ItemTemplate&gt;           
                        &lt;asp:Label ID="ProductNameLabel" runat="server" Text='&lt;%# Eval("ProductName") %&gt;' /&gt;   
                        &lt;br /&gt;Price:
                        &lt;asp:Label ID="PriceLabel" runat="server" Text='&lt;%# "$" + Eval("Price") %&gt;'  /&gt;
                        &lt;br /&gt;

                        &lt;asp:Image ID="Image1" runat="server" CssClass="ImageStyles" ImageUrl='&lt;%# "GetImage.ashx?Id=" + Eval("PID") %&gt;' BackColor="White" BorderStyle="Ridge" BorderColor="WhiteSmoke" /&gt;
                        &lt;br /&gt;           
                    &lt;/ItemTemplate&gt;
                &lt;/asp:DataList&gt;                
               &lt;table cellpadding="0" border="0"&gt;
                    &lt;tr&gt;
                        &lt;td align="right"&gt;
                            &lt;asp:LinkButton ID="lbtnFirst" runat="server" CausesValidation="false" OnClick="lbtnFirst_Click"&gt;&lt;img src="images/First.png" height="50px" width="100px" onmouseover="this.src='images/FirstMouseOver.png';" onmouseout="this.src='images/First.png';" /&gt;&lt;/asp:LinkButton&gt;
                            &amp;nbsp;&lt;/td&gt;
                        &lt;td align="right"&gt;
                            &lt;asp:LinkButton ID="lbtnPrevious" runat="server" CausesValidation="false" OnClick="lbtnPrevious_Click"&gt;&lt;img src="images/Previouse.png" onmouseover="this.src='images/PreviouseMouseOver.png';" onmouseout="this.src='images/Previouse.png';" /&gt;&lt;/asp:LinkButton&gt;&amp;nbsp;&amp;nbsp;&lt;/td&gt;
                        &lt;td align="center" valign="middle"&gt;
                            &lt;asp:DataList ID="dlPaging" runat="server" RepeatDirection="Horizontal" OnItemCommand="dlPaging_ItemCommand"
                                OnItemDataBound="dlPaging_ItemDataBound"&gt;
                                &lt;ItemTemplate&gt;
                                    &lt;asp:LinkButton ID="lnkbtnPaging" Font-Size="X-Large" runat="server" CommandArgument='&lt;%# Eval("PageIndex") %&gt;'
                                        CommandName="Paging" Text='&lt;%# Eval("PageText") %&gt;'&gt;&lt;/asp:LinkButton&gt;&amp;nbsp;
                                &lt;/ItemTemplate&gt;
                            &lt;/asp:DataList&gt;
                        &lt;/td&gt;
                        &lt;td align="left"&gt;
                            &amp;nbsp;&amp;nbsp;&lt;asp:LinkButton ID="lbtnNext" runat="server" CausesValidation="false"
                                OnClick="lbtnNext_Click"&gt;&lt;img src="images/Next.png" onmouseover="this.src='images/NextMouseOver.png';" onmouseout="this.src='images/Next.png';" /&gt;&lt;/asp:LinkButton&gt;&lt;/td&gt;
                        &lt;td align="left"&gt;
                            &amp;nbsp;
                            &lt;asp:LinkButton ID="lbtnLast" runat="server" CausesValidation="false" OnClick="lbtnLast_Click"&gt;&lt;img src="images/Last.png" onmouseover="this.src='images/LastMouseOver.png';" onmouseout="this.src='images/Last.png';" /&gt;&lt;/asp:LinkButton&gt;&lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;tr&gt;
                        &lt;td colspan="5" align="center" style="height: 30px" valign="middle"&gt;
                            &lt;asp:Label ID="lblPageInfo" runat="server"&gt;&lt;/asp:Label&gt;&lt;/td&gt;
                    &lt;/tr&gt;
                &lt;/table&gt;
</code></pre>
