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

DataList to Grid question

2 Answers 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 25 Mar 2010, 07:51 AM
Hi!

I want to transfer our DataList with template to the Grid control and don't know how to go about it, please help! This datalist has custom paging too:

<asp:datalist id="dlProducts" runat="server" EnableViewState="False">  
                        <HeaderTemplate> 
                </td> 
                <td colspan="9" /> 
            </tr> 
            <tr class="gridHeader">  
                <td width="5%">SC</td> 
                <td width="15%">Man Code</td> 
                <td width="30%">Description</td> 
                <td width="10%" align="right">Cost 1</td> 
                <td width="10%" align="right">Cost 2</td> 
                <td width="10%" align="right">Cost 3</td> 
                <td width="10%" align="right">Cost 4</td> 
                <td width="10%" align="right">Status</td> 
            </tr> 
            </HeaderTemplate> 
            <ItemTemplate> 
            </td> 
            <td colspan="9" /> 
        </tr> 
        <tr class="gridItem">  
                    <td width="5%" align="left"><asp:HyperLink id="hlnkSC" runat="server" NavigateUrl='<%# String.Format("~/Purchasing/ProductDealerDetail.aspx?siid={0}", DataBinder.Eval(Container.DataItem, "SupplierItemId")) %>' Text='<%# DataBinder.Eval(Container.DataItem, "SourceCode") %>'/></td> 
                    <td width="15%" align="left"><asp:HyperLink id="hlnkManCode" runat="server" NavigateUrl='<%# String.Format("~/Purchasing/ProductDealerDetail.aspx?siid={0}", DataBinder.Eval(Container.DataItem, "SupplierItemId")) %>' Text='<%# DataBinder.Eval(Container.DataItem, "SupplierItemCode") %>'/></td> 
                    <td width="30%" align="left"><asp:HyperLink id="hlnkItem" runat="server" NavigateUrl='<%# String.Format("~/Purchasing/ProductDealerDetail.aspx?siid={0}", DataBinder.Eval(Container.DataItem, "SupplierItemId")) %>' Text='<%# DataBinder.Eval(Container.DataItem, "SupplierProduct") + " " + DataBinder.Eval(Container.DataItem, "Description2") %>'/></td> 
                    <td width="10%" align="right"><%# FormatCurrencyString(DataBinder.Eval(Container.DataItem, "OCCost")) %></td>  
                    <td width="10%" align="right"><%# FormatCurrencyString(DataBinder.Eval(Container.DataItem, "OCCost1")) %></td>  
                    <td width="10%" align="right"><%# FormatCurrencyString(DataBinder.Eval(Container.DataItem, "OCCost2")) %></td>  
                    <td width="10%" align="right"><%# FormatCurrencyString(DataBinder.Eval(Container.DataItem, "OCCost3")) %></td>  
                    <td width="10%" align="right"><it:TextImage id="Textimage1" Text='<%# DataBinder.Eval(Container.DataItem, "ItemStatusImage" )%>' ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ItemStatusImage" )%>' ImageDirectory="/ItemStatus" Runat="Server" /></td>  
                </tr> 
          
</ItemTemplate> 
            </asp:datalist> 

2 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 30 Mar 2010, 07:34 AM
Hi Joe,

In order to achieve the desired functionality with RadGrid you could try the following code snippet:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowCustomPaging="true">
    <MasterTableView HeaderStyle-CssClass="gridHeader">
        <Columns>
            <telerik:GridTemplateColumn HeaderStyle-Width="5%" UniqueName="TemplateColumnSC" DataField="SupplierItemId" ItemStyle-HorizontalAlign="Left" HeaderText="SC">
                <ItemTemplate>
                    <asp:HyperLink ID="hlnkSC" runat="server" NavigateUrl='<%# String.Format("~/Purchasing/ProductDealerDetail.aspx?siid={0}", DataBinder.Eval(Container.DataItem, "SupplierItemId")) %>' Text='<%# DataBinder.Eval(Container.DataItem, "SourceCode") %>' />
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-Width="15%" UniqueName="TemplateColumnManCode" DataField="SupplierItemId" HeaderText="Man Code">
                <ItemTemplate>
                    <asp:HyperLink ID="hlnkManCode" runat="server" NavigateUrl='<%# String.Format("~/Purchasing/ProductDealerDetail.aspx?siid={0}", DataBinder.Eval(Container.DataItem, "SupplierItemId")) %>' Text='<%# DataBinder.Eval(Container.DataItem, "SupplierItemCode") %>' />
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-Width="30%" UniqueName="TemplateColumnItem" DataField="SupplierItemId" HeaderText="Description">
                <ItemTemplate>
                    <asp:HyperLink ID="hlnkItem" runat="server" NavigateUrl='<%# String.Format("~/Purchasing/ProductDealerDetail.aspx?siid={0}", DataBinder.Eval(Container.DataItem, "SupplierItemId")) %>' Text='<%# DataBinder.Eval(Container.DataItem, "SupplierProduct") + " " + DataBinder.Eval(Container.DataItem, "Description2") %>' />
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderStyle-Width="10%" ItemStyle-HorizontalAlign="Right" UniqueName="TemplateColumnOCCost" DataField="OCCost" HeaderText="Cost 1">
                <ItemTemplate>
            <%# FormatCurrencyString(DataBinder.Eval(Container.DataItem, "OCCost")) %>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderStyle-Width="10%" ItemStyle-HorizontalAlign="Right" UniqueName="TemplateColumnOCCost1" DataField="OCCost1" HeaderText="Cost 2">
                <ItemTemplate>
             <%# FormatCurrencyString(DataBinder.Eval(Container.DataItem, "OCCost1")) %>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderStyle-Width="10%" ItemStyle-HorizontalAlign="Right" UniqueName="TemplateColumnOCCost2" DataField="OCCost2" HeaderText="Cost 3">
                <ItemTemplate>
            <%# FormatCurrencyString(DataBinder.Eval(Container.DataItem, "OCCost2")) %>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderStyle-Width="10%" ItemStyle-HorizontalAlign="Right" UniqueName="TemplateColumnOCCost3" DataField="OCCost3" HeaderText="Cost 4">
                <ItemTemplate>
             <%# FormatCurrencyString(DataBinder.Eval(Container.DataItem, "OCCost3")) %>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderStyle-Width="10%" ItemStyle-HorizontalAlign="Right" UniqueName="TemplateColumnItemStatusImage" DataField="ItemStatusImage" HeaderText="Status">
                <ItemTemplate>
                    <it:textimage id="Textimage1" text='<%# DataBinder.Eval(Container.DataItem, "ItemStatusImage" )%>' imageurl='<%# DataBinder.Eval(Container.DataItem, "ItemStatusImage" )%>' imagedirectory="/ItemStatus" runat="Server" />
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>


Additionally I suggest you to set your ViewState to true. If you disable it because you want to optimize your application you may go through the following help articles to get more details about Optimizing ViewState usage:
http://www.telerik.com/help/aspnet-ajax/grdviewstateoptimization.html
http://www.telerik.com/help/aspnet-ajax/grdsavinggridviewstateinsession.html

I hope this helps.

Regards,
Radoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Joe
Top achievements
Rank 1
answered on 31 Mar 2010, 01:39 AM
Radoslav, thanks a lot!!
Tags
Grid
Asked by
Joe
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Joe
Top achievements
Rank 1
Share this question
or