【问题标题】:show data in columns using gridview使用gridview在列中显示数据
【发布时间】:2014-06-16 23:45:15
【问题描述】:

您好,我正在尝试在 2 列中显示数据..例如

col       col            

A          E       
B          F       
C          G       
D          H  

我可以显示单列,但无法显示 2 列,当我在 gridview 中添加新字段以显示列时,它会显示同一列。喜欢

col       col            

A          A       
B          B       
C          C       
D          D

我想连续显示数据。请建议我一个解决方案。 谢谢

 <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>

【问题讨论】:

  • 请发布您的代码。
  • 请向我们展示您的代码。
  • 投反对票:没有看到你的代码怎么能告诉你有什么问题?
  • 我建议你使用 Datalist 而不是 Grid 视图,你可以在 datalist 中轻松设置列。
  • 我已经添加了aspx代码...

标签: c# asp.net gridview


【解决方案1】:

我认为您应该考虑使用 DataList 控件而不是 GridView。

Here 是一个很好的关于如何使用它的教程,here 你可以找到关于它的RepeatDirectionRepeatLayoutRepeatColumns 属性的信息。

例如,通过将RepeatColumns 设置为2,将RepeatLayout 设置为"Table"RepeatDirection 设置为"Vertical",您可以实现您所追求的布局:

A   E
B   F
C   G 
D   H

如果您对控件的性能感到好奇,可以找到一个很好的比较here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-29
    • 2017-12-06
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    相关资源
    最近更新 更多