Search code examples
asp.nethtmlrepeaterlinqdatasource

create a separated columns in asp.net c# using repeater or datalist using linqdatasource


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


Solution

  • 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