RadGrid & RenderSelectedPageOnly

5 posts, 0 answers
  1. Zoinky
    Zoinky avatar
    45 posts
    Member since:
    Sep 2007

    Posted 07 Dec 2008 Link to this post

    I am trying to do a simple example like the online wizard, but with a datagrid
    the problem is that the datagrid_needdatasource is not firing at the right time
    it only fires if i go to the 3rd tab (grid is on the second tab),

    here is the code i am using, simple example.

    <

     

    telerik:RadTabStrip ID="tsRes" runat="server" SelectedIndex="0" AutoPostBack="true"

     

     

    MultiPageID="mpRes">

     

     

    <Tabs>

     

     

    <telerik:RadTab Text="Step 1" Value="1">

     

     

    </telerik:RadTab>

     

     

    <telerik:RadTab Text="Step 2" Value="2" Enabled="false">

     

     

    </telerik:RadTab>

     

     

    <telerik:RadTab Text="Step 3" Value="3" Enabled="false">

     

     

    </telerik:RadTab>

     

     

    <telerik:RadTab Text="Step 4" Value="4" Enabled="false">

     

     

    </telerik:RadTab>

     

     

    </Tabs>

     

     

    </telerik:RadTabStrip>

     

     

    <telerik:RadMultiPage runat="server" ID="mpRes" RenderSelectedPageOnly="true" SelectedIndex="0">

     

     

    <telerik:RadPageView ID="pvStep1" runat="server">

     

    Step 1

     

    </telerik:RadPageView>

     

     

    <telerik:RadPageView ID="pvStep2" runat="server">

     

     

    <telerik:RadGrid ID="dgCustomers" runat="server" AutoGenerateColumns="false" OnNeedDataSource="dgCustomers_NeedDataSource">

     

     

    <MasterTableView>

     

     

    <Columns>

     

     

    <telerik:GridTemplateColumn>

     

     

    <ItemTemplate>

     

    <%

    #Eval("Text") %>

     

     

    </ItemTemplate>

     

     

    </telerik:GridTemplateColumn>

     

     

    </Columns>

     

     

    </MasterTableView>

     

     

    </telerik:RadGrid>

     

     

    </telerik:RadPageView>

     

     

    <telerik:RadPageView ID="pvStep3" runat="server">

     

    Step 3

     

    </telerik:RadPageView>

     

     

    <telerik:RadPageView ID="pvStep4" runat="server">

     

    Step 4

     

    </telerik:RadPageView>

     

     

    </telerik:RadMultiPage>

     

     

    <asp:Button ID="btnNext" runat="server" Text="Next" OnClick="btnNext_Click" /></telerik:RadAjaxPanel>

     

    {

     

    if (Page.IsValid)

     

    {

     

    RadTab selected = tsRes.SelectedTab;

     

     

    int val = Convert.ToInt32(selected.Value);

     

     

    //change the caption

     

     

     

     

     

    if (val + 1 == tsRes.Tabs.Count)

     

    {

    btnNext.Text =

    "Finish";

     

    }

     

    if (val < tsRes.Tabs.Count)

     

    {

     

    //get the next tab

     

     

     

     

     

    RadTab nextTab = tsRes.FindTabByValue((val + 1).ToString());

     

    nextTab.Enabled = nextTab.Selected =

    true;

     

    mpRes.SelectedIndex = nextTab.Index;

    }

     

    else

     

     

     

     

    {

     

    int save = 0;

     

    }

    }

    }

     

    protected void dgCustomers_NeedDataSource(object source, GridNeedDataSourceEventArgs e)

     

    {

     

    dgCustomers.DataSource = GetCustomers();

    }

     

    private ListItemCollection GetCustomers()

     

    {

     

    ListItemCollection custs = new ListItemCollection();

     

     

    for(int i =1;i<10;i++)

     

    {

     

    ListItem li = new ListItem("Customer " + i.ToString());

     

    custs.Add(li);

    }

     

    return custs;

     

    }

  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 08 Dec 2008 Link to this post

    Hi Zoinky,

    Inavtive pageviews are not visible (Visible=False) when using RenderSelectedPageOnly. The NeedDataSource event is fired during the Load event of the RadGrid control. However since you make the grid (and containing pageview) visible during a postback event (the click of the button) the NeedDataSource event will not fire.

    As a workaround you may manually databind your grid:

                if (val < tsRes.Tabs.Count)
                {
                    //get the next tab
                    RadTab nextTab = tsRes.FindTabByValue((val + 1).ToString());
                    nextTab.Enabled = nextTab.Selected = true;
                    mpRes.SelectedIndex = nextTab.Index;
                    dgCustomers.DataSource = GetCustomers();
                    dgCustomers.DataBind();

                }

    I hope this helps,
    Albert
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ahmed Soliman
    Ahmed Soliman avatar
    3 posts
    Member since:
    Mar 2008

    Posted 16 Dec 2008 Link to this post

    so why we use RenderSelectedPageOnly if we have to rebind the grid when any tab is selected?!!!
  5. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 16 Dec 2008 Link to this post

    Hello Ahmed Soliman,

    I have explained that in my previous reply. The pageview which contains the grid is made visible after the load event of the grid which fires NeedDataSource.

    Regards,
    Albert
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Louis
    Louis avatar
    1 posts
    Member since:
    Jan 2008

    Posted 19 Aug 2009 Link to this post

    Why does the RadGrid call NeedDataSource when clicking on the RadTabStrip but not when changing the SelectedIndex from  a CodeBehind click event? What is so special that the RadTabStrip  can perform that a developer cannot do the same? Are "Next" and "Previous" buttons are not supported when using NeedDataSource? This is the recommended way to get data and provides all the automated features.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017