1

I have created a database with table Category with categoryId,CategoryName, parentId and CategoryImage.

I am using Linqconnect(LinqtoMySql).

How could I display the categories and names using the Repeater or should I use datalist using linq datasource in this way:

enter image description here

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
Vishal Torne
  • 366
  • 5
  • 24

1 Answers1

2

The DataList was designed for this purpose.

You will run into significant difficulties using a GridView or Repeater.

Use the Repeat Direction property and the Repeat Columns property.

 <asp:DataList id="MyDataList" RepeatDirection="Horizontal" RepeatColumns="4" runat="server">

Of course, you'll need to set your DatasourceID and configure your datasource.

You can set the datasource from the codebehind if you wish.

 MyDataList.DataSource = MyDataTable

or

 MyDataList.DataSource = MyLinqQueryResults

References

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
  • repeater must be the first choice for this purpose, we can use CSS for repeating items Horizontally or Vertically – Siz S Mar 12 '13 at 18:07
  • @SizS I strongly disagree. You are going to end up with very hackish CSS in order to execute a 4-column tabular layout, given a dynamic list of records to bind. The code will be very painful to maintain. – Brian Webster Mar 12 '13 at 18:08
  • @GeorgeWBush you've a point, but we can give any layout to repeater and Repeater is fast as per compare to datalist, we can just use unordered list to that Horizontal View – Siz S Mar 12 '13 at 18:14
  • @George W Bush:Which control i should use to display hierarchical data. please see my question here : http://stackoverflow.com/questions/15363986/create-functions-for-html-hyperlinks-to-query-database/15364417#comment21710589_15364417 – Vishal Torne Mar 12 '13 at 18:50
  • @VishalTorne For that, i would actually build a string in the Code-Behind using a StringBuilder, and then I would write it to a Literal control. The string would use nested Unordered Lists (HTML tag UL). – Brian Webster Mar 12 '13 at 19:33
  • @GeorgeWBush Could give me an idea how i could do this.. not an entire solution.. please.. – Vishal Torne Mar 13 '13 at 09:15