Frndz,

I want to display data in a horizontal pattern using Datagrid.
Tried to get that through the TemplateColumns but wasnt able to find out what exact values are to be modified to achieve that.

can someone plz tell me how can this be done ??


cheers
- Prasadd

Dani AI

Generated

Two practical ways to lay out items horizontally in ASP.NET WebForms were missed in the thread. noted TemplateColumns (TemplateColumn in a DataGrid) — that defines per-column templates in a tabular grid but does not change the control's flow. is correct that transposing the dataset (pivoting rows into columns) will work when you need a true rotated table. For most "show items left-to-right, then wrap" scenarios you do not need to modify the data: use a DataList or a Repeater and a layout property or CSS.

A simple DataList approach:

<asp:DataList ID="DataList1" runat="server" RepeatDirection="Horizontal" RepeatColumns="4">
  <ItemTemplate>
    <%# Eval("FieldName") %>
  </ItemTemplate>
</asp:DataList>

RepeatDirection="Horizontal" makes items flow across, and RepeatColumns controls how many items per row before wrapping.

If you want full control of markup and CSS, use a Repeater and style each item:

<asp:Repeater ID="rpt" runat="server">
  <ItemTemplate>
    <div class="box"><%# Eval("FieldName") %></div>
  </ItemTemplate>
</asp:Repeater>
.box { display:inline-block; width:150px; margin:6px; vertical-align:top; }

If the requirement is a true pivoted table (rows become columns with header labels), transform the DataTable in code-behind or pivot in SQL before binding. Use the control-based approach for layout concerns; use data transformation when the underlying data shape must change.

Recommended Answers

All 2 Replies

i think this would be something you would modify your dataset, then binding your mod dataset would give you that result

i think this would be something you would modify your dataset, then binding your mod dataset would give you that result

are you sure that this is the only way to achieve what i want ?
coz, i remember having come across some property using which u can display data horizontally

neways, thanx for ur help !
if i get the answer would let u know too
& if u find some solution plz do let me know


cheers
- Prasadd

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.