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

RadGrid & RenderSelectedPageOnly

4 Answers 260 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
Zoinky
Top achievements
Rank 1
Zoinky asked on 08 Dec 2008, 04:23 AM
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;

 

}

4 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 08 Dec 2008, 01:09 PM
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.
0
Ahmed Soliman
Top achievements
Rank 1
answered on 16 Dec 2008, 08:31 AM
so why we use RenderSelectedPageOnly if we have to rebind the grid when any tab is selected?!!!
0
Atanas Korchev
Telerik team
answered on 16 Dec 2008, 08:43 AM
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.
0
Louis
Top achievements
Rank 1
answered on 19 Aug 2009, 05:04 AM
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.
Tags
TabStrip
Asked by
Zoinky
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Ahmed Soliman
Top achievements
Rank 1
Louis
Top achievements
Rank 1
Share this question
or