Adding tabs and pageviews in codebehind

5 posts, 1 answers
  1. Jason
    Jason avatar
    4 posts
    Member since:
    Jun 2008

    Posted 14 Jun 2008 Link to this post

    I'm stumbling once again. This time, I'm trying to dynamically add tabs and an associated pageview to when an item from a RadGrid is selected.

    The tab is created and selected, however the text does not get set, nor does it appear that the pageview is created. I've verified with a radalert that the e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["queueid"].ToString() does return a valid string.

    What am I missing here?

    protected void QueueGrid_ItemCommand(object source, GridCommandEventArgs e) 
        if (e.CommandName == "RowClick" && e.Item is GridDataItem) 
        { 
            if (RadTabStrip1.FindTabByText(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["queueid"].ToString()) == null) 
            { 
                RadTab tab1 = new RadTab(); 
                RadTabStrip1.Tabs.Add(tab1); 
     
                RadPageView newpage = new RadPageView(); 
                RadMultiPage1.PageViews.Add(newpage); 
                newpage.ID = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["queueid"].ToString(); 
                tab1.Text = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["queueid"].ToString(); 
                tab1.Value = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["queueid"].ToString(); 
                tab1.PageViewID = newpage.ID; 
                RadTabStrip1.SelectedIndex = RadTabStrip1.SelectedIndex + 1; 
                RadMultiPage1.SelectedIndex = RadMultiPage1.SelectedIndex + 1; 
            } 
        } 


  2. Jason
    Jason avatar
    4 posts
    Member since:
    Jun 2008

    Posted 16 Jun 2008 Link to this post

    Turns out to be an issue with having a TabTemplate. If I remove the following, I can create tabs and pageviews dynamically. Once I add it back, it creates blank tabs.

    <TabTemplate> 
        <%# DataBinder.Eval(Container, "Text") %> 
        <img style="margin-left: 10px" src="/images/delete.gif" alt="Delete tab" onclick="deleteTab('<%# DataBinder.Eval(Container, "Text") %>')" /> 
    </TabTemplate> 

  3. Answer
    Erjan Gavalji
    Admin
    Erjan Gavalji avatar
    1455 posts

    Posted 17 Jun 2008 Link to this post

    Hi Jason,

    To have the text evaluated, you should call the DataBind() method of the RadTabStrip, e.g. RadTabStrip1.DataBind();

    Kind regards,
    Erjan Gavalji
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  4. Peter
    Peter avatar
    2 posts
    Member since:
    Jul 2008

    Posted 22 Jul 2008 Link to this post

    Hey, I have a question on this, how do I create the pageviews on runtime?  I am trying to do the same thing but I can't seem to find a way to generate a new pageview on runtime.
  5. Paul
    Admin
    Paul avatar
    4281 posts

    Posted 28 Jul 2008 Link to this post

    Hello Peter,

    Please take a look at our Dynamic RadPageView online example for details on the matter.

    All the best,
    Paul
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top