Click here to Skip to main content
15,906,329 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have a menu which contain an unordered list. i have to get data into this unordered list from database. Please any one help me.

In my controller:

C#
DataTable dtc = registerDAL.CategoryRetrieve();ArrayL
ist category = new ArrayList();
          foreach (DataRow dr in dtc.Rows)
          {
              category.Add(dr);
          }


In my view:
i need to get these categories an display as a list.
What can i do?
Posted
Updated 2-Jul-16 1:34am

Herei am demonstrate a simple example for loading list.Please follow the steps

Create a Model

C#
public class YourList
{
public ArrayList Category{get;set;}
}


Create a Controller and ActionResult

C#
public ListController:Controller
{
public ActionResult Index()
{
DataTable dtc = registerDAL.CategoryRetrieve();ArrayL
ist category = new ArrayList();
          foreach (DataRow dr in dtc.Rows)
          {
              category.Add(dr);
          }
var list=new YourList();
list.Category=category;
return View(list)
}
}


Create a view by right clicking the index view and loop through the category

C#
@model YourList
{
<ul>
  @foreach (var item in Model.Category)
            {
                <li>@item</li>          
            }
</ul>
}

Hope this helps
 
Share this answer
 
v2
Comments
Minnu Sanju 18-Jul-13 6:32am    
Thank u let me try it
Minnu Sanju 18-Jul-13 7:53am    
when i tried this
i am getting the list as: System.DataRow

what to do please guide me
Jameel VM 18-Jul-13 8:48am    
you must specify the column name or index.for example dr[0] or dr["columnname"]
Jameel VM 18-Jul-13 8:49am    
not in the view. inside the loop .foreach (DataRow dr in dtc.Rows)
{
category.Add(dr["Columnname"]);
}
how to bind my entity data to dropdown bootstarp dropdown in MVC app
Playlist is my data table from entity database and
connection name playlist entity
below is my code

HTML
<div class="row">
    <div class="container">
        <div class="col-md-2 col-md-offset-10">
            <div style="float:right;">
                <ul class="nav-dp navdpbar-nav">
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">My Playlists <span class="caret"></span></a>

                        <ul class="dropdown-menu">
                           

                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>


share what i have to do changes in my code
 
Share this answer
 
Comments
CHill60 3-Jul-16 17:29pm    
If you have a question of your own then use the "Ask a question" link. Don't post questions or comments as solutions to old posts

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900