开发者

Populate mega-dropdown with data

I found plenty of very nice drop downs to use in my website. (like that one Here)

I can't seem to find how I fill the links from a database. I don't want to go to each line and assign it a link manually..

Currently I have some kind of bar that is linked to a data adapter, I tried to change it over to the new design, but I can't bind it to a开发者_StackOverflow社区ny of this mega menu samples.

I'm using MsSQL server database.


Probably the easiest way would be to use LINQ to sql then load those results into a datatable. That datatable could then be used as the datasource for your data-adaptor/repeater (or whatever it is you use)

http://www.c-sharpcorner.com/UploadFile/VIMAL.LAKHERA/LINQResultsetToDatatable06242008042629AM/LINQResultsetToDatatable.aspx

Here is the best (IMO) example from that tutorial

var vrCountry = from country in objEmpDataContext.CountryMaster
                        select new {country.CountryID,country.CountryName};

DataTable dt = LINQToDataTable(objEmpDataContext,vrCountry);

public DataTable ToDataTable(System.Data.Linq.DataContext ctx, object query)
{
     if (query == null)
     {
          throw new ArgumentNullException("query");
     }

     IDbCommand cmd = ctx.GetCommand(query as IQueryable);
     SqlDataAdapter adapter = new SqlDataAdapter();
     adapter.SelectCommand = (SqlCommand)cmd;
     DataTable dt = new DataTable("sd");

     try
     {
          cmd.Connection.Open();
          adapter.FillSchema(dt, SchemaType.Source); 
          adapter.Fill(dt);
     }
     finally
     {
          cmd.Connection.Close();
     }
     return dt;
}

You would then bind the dt object as the datasource to your control

Hope that helps!


Its very easy... I just didn't understood the sample I got :).

I would of delete this question as it won't help anyone searching around but the system wont allow me to do so.

I flagged the question last week but yet got any response.

So I guess I leave it as is and that's all.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜