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

Dynamic Grid Templates With a RadToolBar

4 Answers 70 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Craig
Top achievements
Rank 1
Craig asked on 17 Jan 2009, 11:37 PM
http://demos.telerik.com/aspnet-ajax/Grid/Examples/Programming/ListView/DefaultCS.aspx
I was looking over this demo (link above) and wondering how I might flip the grid from a "List/Data" view as displayed in the demo to a different custom templateboundcolumn as described in this demo.
http://demos.telerik.com/aspnet-ajax/Grid/Examples/Hierarchy/DefiningStructure/DefaultCS.aspx

I would like to have a radtoolbar with 2 buttons that show's the two different custom templated layouts. The problem I see, is if the grid has be be created @ Page_Init or OnInit (Second Demo), how would I flag the grid to use the correct templates when the toolbar OnButtonClick server event is going to fire later in the page life cycle.

Got a demo?? :)

Just looking for some advice on how to proceed.
Thanks

4 Answers, 1 is accepted

Sort by
0
Craig
Top achievements
Rank 1
answered on 20 Jan 2009, 03:45 AM
Well it was a good day! I got it working by creating a session state, complex template 1, or complex template 2. The only problem I see is I would like to add more sort columns to the grid header. Since I'm only adding one templated column I can't seem to sort on anything other then one column. (Product Description). I'd like to add Product Number, and Product price to the header.

Thoughts group? :)
0
Sebastian
Telerik team
answered on 20 Jan 2009, 09:40 AM
Hi Craig,

You can implement multi-headers for template columns along with sorting for each individual sub-columns as illustrated in the following examples:

http://demos.telerik.com/aspnet-ajax/Grid/Examples/GeneralFeatures/ColumnTypes/DefaultCS.aspx (see the last column in the grid)
http://www.telerik.com/help/aspnet-ajax/grdcustomizewithgridtemplatecolumn.html

Best regards,
Sebastian
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Craig
Top achievements
Rank 1
answered on 21 Jan 2009, 10:53 PM
I'm trying some more complicated templates now and I'm having some problems with my data/listview

I'm trying to implement as described in this link, but my template is a class not on the aspx page.
http://demos.telerik.com/aspnet-ajax/Grid/Examples/Programming/ListView/DefaultCS.aspx

ITemplate

 

public class DetailTemplate : ITemplate

 

{

 

public void InstantiateIn(Control container)

 

{

 

var index = (GridDataItem)container.NamingContainer;

 

 

 

if (index.ItemIndex !=0)

 

container.Controls.Add(

new LiteralControl("</td></tr></table>"));

 


//Create panel with formatted table and data....add panel to container (Is the Table causing a problem in the foreach in the code behind loop possibly?)

}
}

CODE BEHIND PAGE - PER example. The only change I made was using my  column's UniqueName = "Detail"

 

 

 

protected void RadGrid1_DataBound(object sender, EventArgs e)
        {
            int itemCount = (sender as RadGrid).MasterTableView.GetItems(GridItemType.Item).Length + (sender as RadGrid).MasterTableView.GetItems(GridItemType.AlternatingItem).Length;
            foreach (GridItem item in (sender as RadGrid).Items)
            {
                if (item is GridDataItem && item.ItemIndex < itemCount - 1)
                {
                    ((item as GridDataItem)["Detail"] as TableCell).Controls.Add(new LiteralControl("<table style='display:none;'><tr><td>"));
                }
            }
        }

The resulting HTML has one small problem and I can't seem to find where to fix it. (Doubled Table entry.) This occures on every item but the first and last.

  <table style='display:none;'>
        <tr>
          <td><table style='display:none;'>
              <tr>
                <td></td>
              </tr>
              <tr class="GridAltRow_Sunset" id="MyRadGrid_ctl00__1">
                <td></td>
              </tr>
            </table>

Anyone have an idea.
Thanks in advance

0
Craig
Top achievements
Rank 1
answered on 21 Jan 2009, 11:32 PM
found it...I didn't need the foreach at all.
Tags
Grid
Asked by
Craig
Top achievements
Rank 1
Answers by
Craig
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or