Furqan Khan
Furqan Khan

Reputation: 39

show data in columns using gridview

Hi I am trying to show data in 2 column.. e.g

col       col            

A          E       
B          F       
C          G       
D          H  

I am able to show single column but I am unable to show 2 columns, when I add the new field in gridview to show the columns it displays the same column. like

col       col            

A          A       
B          B       
C          C       
D          D

I wanted to show data in continuity. Please suggest me a solution. Thanks

 <asp:GridView 
       ] ID="GridViewProducts" 
        DataKeyNames="pkProductId,RetailPrice"
        runat="server" 
        OnSelectedIndexChanged="getSelectedRowToCard"            
        AutoGenerateColumns="false"
        AllowPaging="True"  
        PageSize="4"
        OnPageIndexChanging="OnNewPage"
        BorderWidth="0px"
        BorderColor="White" Width="341px">
            <Columns>
                <asp:CommandField ShowSelectButton="True" SelectText="ADD To Card"/>                    
                <asp:TemplateField>
                    <ItemTemplate>
                        <br />                            
                        Description:
                        <asp:HyperLink ID="SelectProduct" NavigateUrl="~/Home.aspx"                                                    
                        runat="server"><%#Eval("Description").ToString()%> 
                        </asp:HyperLink>
                        <br />
                        TypeDescription: <%#Eval("TypeDescription").ToString()%>
                        <br />
                        <span style="color: #FF3300">RetailPrice:$</span>
                        <%#Eval("RetailPrice").ToString()%>
                        <br />
                        Weight: <%#Eval("Weight").ToString()%>
                        <%--<asp:Button ID=btn runat="server" Text="Add to Cart"
                        OnCommand="getSelectedRowToCard"/>--%>
                        <br />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:HyperLinkField />
                <asp:CommandField SelectText="ADD To Card" ShowSelectButton="True" />
                <asp:TemplateField>
                    <ItemTemplate>
                        <br />
                        Description:
                        <asp:HyperLink ID="SelectProduct" runat="server"                
                        NavigateUrl="~/Home.aspx"><%#Eval("Description").ToString()%>
                        </asp:HyperLink>
                        <br />
                        TypeDescription: <%#Eval("TypeDescription").ToString()%>
                        <br />
                        <span style="color: #FF3300">RetailPrice:$</span>
                        <%#Eval("RetailPrice").ToString()%>
                        <br />
                        Weight: <%#Eval("Weight").ToString()%>
                        </ItemTemplate>
                </asp:TemplateField>
                <asp:HyperLinkField />
            </Columns>
        </asp:GridView>

Upvotes: 0

Views: 117

Answers (1)

qqbenq
qqbenq

Reputation: 10460

I think you should consider using a DataList control instead of the GridView.

Here is a quite nice tutorial about how to use it, and here you can find information about it's RepeatDirection, RepeatLayout and RepeatColumns properties.

For example, by setting RepeatColumns to 2, RepeatLayout to "Table" and RepeatDirection to "Vertical" you can achieve the layout you are after:

A   E
B   F
C   G 
D   H

If you are curious about the performance of the control you can find a nice comparison here.

Upvotes: 1

Related Questions