This is a migrated thread and some comments may be shown as answers.

DataList with Ajax

1 Answer 34 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mani
Top achievements
Rank 1
mani asked on 26 Jul 2009, 05:52 PM
Hi
 I used the DataList. herewith i used the pageindex using panel container... It is working fine.. Herewith i used the dynamic controls (link button) for paging. I dont know how can i bind the Ajax for this dynamic control. Herewith i have attached the sample paging coding here...



        private void bindDataWithPaging(DataList bindControl, DataTable propertyDataTable) //you can pass either DatList or Repeater to this function
        {
            if (propertyDataTable.Rows.Count > 0) // if the datset contains data
            {
                DataView dv = propertyDataTable.DefaultView;

                PagedDataSource dsP = new PagedDataSource();
                dsP.AllowPaging = true;
                dsP.DataSource = dv;
                dsP.CurrentPageIndex = CurrentPageIndex;
                dsP.PageSize = PageSize;

                //Binding data to the controls
                if (bindControl is DataList)
                {
                    ((DataList)bindControl).DataSource = dsP;
                    ((DataList)bindControl).DataBind();
                }

                //saving the total page count in Viewstate for later use
                PageCount = dsP.PageCount;

                //create the linkbuttons for pagination
                BuildPagination();
            }
        }

        private int CurrentPageIndex //to store the current page index
        {
            get { return ViewState["CurrentPageIndex"] == null ? 0 : int.Parse(ViewState["CurrentPageIndex"].ToString()); }
            set { ViewState["CurrentPageIndex"] = value; }
        }
        private int PageCount  //total number of pages needed to display the data
        {
            get { return ViewState["PageCount"] == null ? 0 : int.Parse(ViewState["PageCount"].ToString()); }
            set { ViewState["PageCount"] = value; }
        }

        private LinkButton createButton(string title, int index)
        {
            LinkButton lnk = new LinkButton();
            lnk.ID = index.ToString();
            lnk.Text = title;
            lnk.CommandArgument = index.ToString();
            lnk.Click += new EventHandler(lnkPager_Click);
            return lnk;
        }

        //Top Create Button
        private LinkButton topcreateButton(string title, int index)
        {
            LinkButton toplnk = new LinkButton();
            toplnk.ID = "toplink"+index.ToString();
            toplnk.Text = title;
            toplnk.CommandArgument = index.ToString();
            toplnk.Click += new EventHandler(toplnkPager_Click);
            return toplnk;
        }


        //create the linkbuttons for pagination
        protected void BuildPagination()
        {
            pnlPager.Controls.Clear(); //
            pnlTopPager.Controls.Clear();

            if (PageCount <= 1) return; // at least two pages should be there to show the pagination

            //finding the first linkbutton to be shown in the current display
            int start = CurrentPageIndex - (CurrentPageIndex % ButtonsCount);

            //finding the last linkbutton to be shown in the current display
            int end = CurrentPageIndex + (ButtonsCount - (CurrentPageIndex % ButtonsCount));

            //if the start button is more than the number of buttons. If the start button is 11 we have to show the <<First link
            if (start > ButtonsCount - 1)
            {
                pnlPager.Controls.Add(createButton(propertyDetailData.FirstPageText, 0));
                pnlPager.Controls.Add(createButton("..", start - 1));

                //Top View
                pnlTopPager.Controls.Add(topcreateButton(propertyDetailData.FirstPageText, 0));
                pnlTopPager.Controls.Add(topcreateButton("..", start - 1));
            }

            int i = 0, j = 0;

            for (i = start; i < end; i++)
            {
                LinkButton lnk;
                if (i < PageCount)
                {
                    if (i == CurrentPageIndex) //if its the current page
                    {
                        Label lbl = new Label();
                        Label lbltop = new Label();
                        //  lbl.Text = (i + 1).ToString();

                        if (i == 0)
                        {
                            lbl.Text = (i + 1).ToString() + "-" + (((i + 1) * PageSize));
                            lbltop.Text = (i + 1).ToString() + "-" + (((i + 1) * PageSize));
                        }
                        else
                        {
                            lbl.Text = (((i) * (PageSize)) + 1 + "-" + (((i + 1) * PageSize)));                            
                            lbltop.Text = (((i) * (PageSize)) + 1 + "-" + (((i + 1) * PageSize)));
                        }

                        pnlPager.Controls.Add(lbl);
                        pnlTopPager.Controls.Add(lbltop);
                    }
                    else
                    {
                        if (i == 0)
                        {
                            pnlPager.Controls.Add(createButton((i + 1).ToString() + "-" + (((i + 1) * PageSize)), i));                            
                            pnlTopPager.Controls.Add(topcreateButton((i + 1).ToString() + "-" + (((i + 1) * PageSize)), i));
                        }
                        else
                        {
                            pnlPager.Controls.Add(createButton((i) * (PageSize) + 1 + "-" + (((i + 1) * PageSize)), i));
                            pnlTopPager.Controls.Add(topcreateButton((i) * (PageSize) + 1 + "-" + (((i + 1) * PageSize)), i));
                        }
                    }
                }
                j++;
            }

            //If the total number of pages are greaer than the end page we have to show Last>> link
            if (PageCount > end)
            {
                pnlPager.Controls.Add(createButton("..", i));
                pnlPager.Controls.Add(createButton("&gt;&gt;", PageCount - 1));

                pnlTopPager.Controls.Add(topcreateButton("..", i));
                pnlTopPager.Controls.Add(topcreateButton("&gt;&gt;", PageCount - 1));
            }


        }


        // DataList Page Size Changed

        protected void cmbDataListPageSizeChange_OnSelectedIndexChanged(object sender, EventArgs e)
        {
            
            PageSize = Convert.ToInt32(cmbDataListPageSizeChange.SelectedValue);
            DataTable propertyDataTable = (DataTable)JSSessionHandler.GetSessionValue("propertyData");
            bindDataWithPaging(imageAreaLanding, propertyDataTable);
            cmbTopDataListPageSizeChange.SelectedValue = cmbDataListPageSizeChange.SelectedValue;
        }

        protected void cmbTopDataListPageSizeChange_OnSelectedIndexChanged(object sender, EventArgs e)
        {

            PageSize = Convert.ToInt32(cmbTopDataListPageSizeChange.SelectedValue);
            DataTable propertyDataTable = (DataTable)JSSessionHandler.GetSessionValue("propertyData");
            cmbDataListPageSizeChange.SelectedValue = cmbTopDataListPageSizeChange.SelectedValue;
            bindDataWithPaging(imageAreaLanding, propertyDataTable);
        }
 

<JetSoft:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
            <JetSoft:AjaxSetting AjaxControlID="cmbPropertySearchDestination">
                <UpdatedControls>
                    <JetSoft:AjaxUpdatedControl ControlID="cmbPropertySearchArea" LoadingPanelID="loadingPanelDetails" />
                </UpdatedControls>
            </JetSoft:AjaxSetting>
        </AjaxSettings>
        
         <AjaxSettings>
            <JetSoft:AjaxSetting AjaxControlID="cmbPropertySearchArea">
                <UpdatedControls>
                    <JetSoft:AjaxUpdatedControl ControlID="cmbPropertySearchLocation" LoadingPanelID="loadingPanelDetails" />
                </UpdatedControls>
            </JetSoft:AjaxSetting>
        </AjaxSettings>
        
          <AjaxSettings>
            <JetSoft:AjaxSetting AjaxControlID="cmbDataListPageSizeChange">
                <UpdatedControls>
                    <JetSoft:AjaxUpdatedControl ControlID="imageAreaLanding" LoadingPanelID="loadingPanelDetails" />
                </UpdatedControls>
            </JetSoft:AjaxSetting>
            
             <JetSoft:AjaxSetting AjaxControlID="cmbDataListPageSizeChange">
                <UpdatedControls>
                    <JetSoft:AjaxUpdatedControl ControlID="cmbTopDataListPageSizeChange" LoadingPanelID="loadingPanelDetails" />
                </UpdatedControls>
            </JetSoft:AjaxSetting>
        </AjaxSettings>
        
          <AjaxSettings>
            <JetSoft:AjaxSetting AjaxControlID="cmbTopDataListPageSizeChange">
                <UpdatedControls>
                    <JetSoft:AjaxUpdatedControl ControlID="imageAreaLanding" LoadingPanelID="loadingPanelDetails" />
                </UpdatedControls>
            </JetSoft:AjaxSetting>
             <JetSoft:AjaxSetting AjaxControlID="cmbTopDataListPageSizeChange">
                <UpdatedControls>
                    <JetSoft:AjaxUpdatedControl ControlID="cmbDataListPageSizeChange" LoadingPanelID="loadingPanelDetails" />
                </UpdatedControls>
            </JetSoft:AjaxSetting>            
        </AjaxSettings>
        
         <AjaxSettings>
            <JetSoft:AjaxSetting AjaxControlID="cmbPropertySearchArea">
                <UpdatedControls>
                    <JetSoft:AjaxUpdatedControl ControlID="cmbPropertySearchLocation" LoadingPanelID="loadingPanelDetails" />
                </UpdatedControls>
            </JetSoft:AjaxSetting>
        </AjaxSettings>
        
          <AjaxSettings>
            <JetSoft:AjaxSetting AjaxControlID="pnlTopPager">
                <UpdatedControls>
                    <JetSoft:AjaxUpdatedControl ControlID="imageAreaLanding" LoadingPanelID="loadingPanelDetails" />
                </UpdatedControls>
            </JetSoft:AjaxSetting>
        </AjaxSettings>
        
        <AjaxSettings>
            <JetSoft:AjaxSetting AjaxControlID="pnlPager">
                <UpdatedControls>
                    <JetSoft:AjaxUpdatedControl ControlID="imageAreaLanding" LoadingPanelID="loadingPanelDetails" />
                </UpdatedControls>
            </JetSoft:AjaxSetting>
        </AjaxSettings>
        
</JetSoft:RadAjaxManager>


Let me know how can i solved this problem

Regards
G. Manikandan




1 Answer, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 27 Jul 2009, 10:08 AM
Hello,

In some cases you need to add AJAX pair dynamically (at runtime).
For more information about how to achieve it, please refer to the following help article:
Add AjaxSettings programmatically

Sincerely yours,
Pavlina
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
mani
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Share this question
or