0

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>
6
  • Please post your code. Commented Jun 16, 2014 at 4:31
  • Show us your code pls. Commented Jun 16, 2014 at 4:31
  • Downvote : Without seeing your code how can one tell you what's the problem? Commented Jun 16, 2014 at 4:47
  • I would suggest you to use Datalist rather than Grid view, you can set your columns easily in datalist. Commented Jun 16, 2014 at 4:52
  • I have added the aspx code ... Commented Jun 16, 2014 at 5:02

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.