Wednesday, February 1, 2012

Use Ajax Slider as Paging in Grid View

for using Slider as paging in grid view first of all we have to use textbox/label control and ajax slider control in grid view .

<PagerTemplate>
    <asp:TextBox ID="txtSlide" runat="server" Text='<%# gvDispatch.PageIndex + 1 %>' OnTextChanged="txtSlide_Changed" AutoPostBack="true" />
         
    <ajaxToolkit:SliderExtender ID="ajaxSlider" runat="server" TargetControlID="txtSlide" Orientation="Horizontal"/>
     </PagerTemplate>


code behind code---c#

protected void txtSlide_Changed(object sender, EventArgs e)
{
    TextBox txtCurrentPage = sender as TextBox;
    GridViewRow rowPager = gvDispatch.BottomPagerRow;
    TextBox txtSliderExt = (TextBox)rowPager.Cells(0).FindControl("txtSlide");
    gvDispatch.PageIndex = Int32.Parse(txtSliderExt.Text) - 1;
    BindDispatchData();
}

protected void  gvDispatch_RowDataBound(object sender,System.Web.UI.WebControls.GridViewRowEventArgs e)
{
    GridViewRow rowPager = gvDispatch.BottomPagerRow;
    if ((rowPager != null)) {
        AjaxControlToolkit.SliderExtender slide = (AjaxControlToolkit.SliderExtender)rowPager.Cells(0).FindControl("ajaxSlider");
        slide.Minimum = 1;
        slide.Maximum = gvDispatch.PageCount;
        slide.Decimals = true;
        slide.Length = gvDispatch.PageCount;
        slide.Steps = gvDispatch.PageCount;
    }
}

after rendering page slider take over Textbox/label control

No comments:

Post a Comment