Make Categories / Subcategories With Mvc?

Feb 6, 2011

I have a class

public class CountryListViewModel
{
public IEnumerable
Countries { get; set; }
}
public class CountryViewModel
{
public string CountryName { get; set; }
public string State { get; set; }
public IEnumerable<CityViewModel> Cities {
get; set; }
}
public class CityViewModel
{
public string CityName { get; set; }
public string CityLink { get; set; }
}

using linq to entity grouping by country and it works as designed. but I also have to group by state.

var query = from c in _db.MyTable
where c.IsActive && c.Country == country
group c by c.Country
into loc
select new CountryViewModel()
{
CountryName = loc.Key,
Cities = loc.Select(s => new CityViewModel() { CityName = s.City, CityLink = s.City }).Distinct()
};

View 2 Replies


Similar Messages:

Forms Data Controls :: Display Categories And Subcategories In Gridviews?

Dec 8, 2010

i have one requirement like i want to show all the categories with the subcategories ..

i mean if i have the Sale category it will be heading of the gridview and all sub categories of the Sale category foreign key related subcategories display in that gridview like urls .same way it will show all the categories ..

View 7 Replies

DataSource Controls :: Add Unlimited Categories And Sub Categories?

Jan 9, 2010

I want to add unlimited categories and sub categories facility, But I couldn't solve it for last two days.

1. DB

CategID,CategName,parentid

Data:

CategID CategName Parent ID
1 Electronics 0 (where 0 means it is main category)
2 TV 1 (Self Join whith the categ id Electronics)
3 Panasonic 2
4 LG 2
5 Toys 0
6 Girls Toys 5
7 Boys Toys 5
8 Criket Related 7
9 Dolls 6

Here I want to display this data in Combo Box like

Electronic
>>TV
>>Panasonic
>>LG
Toys
>>GirlsToys
>>Dolls
>>Boys Toys
>>Criket Realted

View 6 Replies

C# - Order The Subcategories Alphabetically?

Mar 24, 2010

I have a table:Category with some sort of categorie

[code]...

Well, the strange question is: how can i order the subcategories alphabetically?
If i'd have binded the children repeater to a linq it would be easy.
But in this case?

View 1 Replies

Forms Data Controls :: Setup Page To Display Gridviews Based On Subcategories?

Apr 18, 2010

I have a page for a client that currently is setup to display a gridview for each subcategory. They recently added a new subcategory and they were wondering why it wasnt showing up on the page. Well the way i have it setup, i have to create the gridview adn datasource for the new subcategory.

Is there a way to setup the page to display a gridview view for each subcategory so if they decide to add another, i dont have to update the page with a new gridview adn configure it? I would like to be able to update what i have and provide a more flexible setup for them.

keeping i mind that each gridview would contain different result sets, is this possible? if so, what controls would i use?

View 3 Replies

ADO.NET :: Using Categories To Get Products?

Nov 7, 2010

I am having problems in getting product data when using different levels of categories. My knowledge of SQL is also very limited.

Here is what i have so far

TABLES
Categories
CategoryID (PK) int
CategoryName nvchar(max) allow null
ParentID int allow null
Data for this table
1,Soaps,null
2,Original Range,1
3,Premium Range,1
4,Speciality Range,1
5,Seasonal Collection,4
6,Selection,4
Products
ProductID (PK) int
ProductName nvarchar(max)
ProductDescription nvarchar(max) allow null
ProductPrice money
CategoryID int

Data for this table

1,Prod1,some text,0.25,6
2,Prod2,some text,0.25,6

I have some linq to sql in the page load event that populates a list view,

[Code]....

Now when the category passed in from the query string is 6 then the products with a category of are shown correctly but category 6 is a child category of 4 and 4 is a child of 1 so when i pass in 4 as the category i should still be retrieving the data for products 1 and 2.

View 4 Replies

Url Rewriting / Routing - Categories In Database

Oct 8, 2010

I have my categories in database, and want something url rewriting/routing to make my url nicer and more SEO friendly. I have divided my categories into the following:

Cars > Select car > Car model >

how do I create url rewriting / routing in my categories? I use framework 4.0

View 1 Replies

ADO.NET :: LINQ Multiple Categories For Product?

Jan 27, 2011

I'm using Entity Framework.

I have 3 tables:

- Products (Primary key productId)
- Categories (Primary key categoryId)
- Product_to_categories (Table with two fields, CategoryId and ProductId)

One product can be assigned to multiple categories.

How should I download the products from specific category?

Now I retrieve them in that way:

int PageNum = 1;
int PageSize = 10;
int categoryId = 5;
var categoryModel = db.Categories.FirstOrDefault(c => c.CategoryId == categoryId);
var results = (from p in categoryModel.Products select p).Skip((PageNum - 1) * PageSize).Take(PageSize).ToList();

But when there is a lot of products in category my server crushed. I want only 10 products per page.

View 2 Replies

C# - Linking Listbox Child Categories?

May 12, 2010

I have few monhts working with aspx, and now I'm developing a shopping cart website. For the employee to upload the products on the DB, every product needs to be linked to a category and sub category, and sub-sub category, and so on. Sometimes the sub-sub categories are up to 5. For example Electronics-TV-LCD-Samsung-40 inches.

First, What I would like to identify is if the SQL table has the apporpiate structure. I have 3 columns Id, Description, Parent_Id. Categories with Parent Id=0 is used for the top ones. Is this the best way to do it?

Then I want to use the ListBox control to select main Categories, and once it is selected, filled a second listbox with its childs and so on. Do I need to query SQL DB everytime the change event happens? I heard about linq but have not used yet.

View 1 Replies

Show Sales In Various Categories In A Chart?

May 14, 2010

The problem is that we have 5 different categories and we have to calculate the percentage of products sold in each category. Then we have to show that in sort of a chart. The interface of chart is shown here

http://img64.imageshack.us/img64/5397/52805880.gif although this chart has 14 boxes but I will be using 20 boxes in the final chart, the reason for that is that I want each box to represent 5% of sales. Now the question is suppose that the percentage for sales in each category is 34.4%, 12.6%, 23.2%, 22.6% and 7.2%. How do I convert these values to nearest 5 and then fill each box with that color. For example 34.4% means that almost 35% or 7 boxes will be colored with that color. The problem is that the sum of all of these must always be 20. I understand that this will not be very precise representation but this is the demand from the user.

View 4 Replies

Web Forms :: Split The Treeview Into Sub-Categories?

Feb 22, 2010

This may be a fairly complex question but I'll try to make it as simple as possible.

I have 2 treeviews, the 1 has a single hierarchial structure like this:

Parent

-->LevelOne
---->LevelTwo
-------->LevelThree
------------->LevelFour

But the second treeview must populate defining sub-categories from the database onto the tree like this:

Parent

-->Sub-LevelOne
---->LevelOne
------->LevelTwo
------------LevelThree
-->Sub-LevelTwo
---->LevelOne
------->LevelTwo
------------LevelThree

My problem is after I've defined the second sub-level structures, I get duplicated sub-levels of data within the sub-level nodes as opposed to having the data distributed between the 2 sub-nodes with the appropriate corresponding data assigned to each level.

In my database, the 2 top sub-levels are identified by integer values of 1 and 2. So the first 2 sub-level nodes are created using a case statement which creates 2 separate sub-level nodes on the tree as I need. But I am having a problem for how I can get the next levels of data to distribute between the 2 separate sub-levels accordingly???

Its almost like I need a 2 more treeviews within a treeview to accomplish what I'm after but I don't know if this is even possible.

View 4 Replies

How To Separate Search Results Into Categories Like Ebay

Dec 16, 2010

I am trying to create a search filter much like the one used on eBay that dynamically comes up with appropriate search categories based on the search results left. For example: [URL]

As you can see the search filters on the left are based upon the details displayed on the product results.

I need to try and implement something similar for an ASP.NET site, whereby I need to filter articles based on fields such as sales, companies, employee numbers etc. My database is quite normalised so I am able to separate all the data into their own tables.

View 1 Replies

C# - Populate A List Box With Many Categories Using Recursive Programming?

Mar 18, 2011

I have a categories table which is set up to allow an infinite number of sub category levels. I would like to mimic the following:It should be clarified that sub categories can have sub categories. E.g. Parent cat -> level 1 -> level 2 -> level 3 etc.My categories table has two columns, CategoryName and ParentID.This list box will be used when assigning the correct category to a product.How can I write this?EditIn response to thedugas I had to modify your answer to work with my situation. I found some errors that needed to be fixed, but below is a final, working solution.

protected void Page_Load(object sender, EventArgs e)
{
using (DataClasses1DataContext db = new DataClasses1DataContext())

[code]...

View 3 Replies

Security :: Create / Add Categories Dynamically From The Webpage?

Feb 24, 2010

I would like to create a category page in the admin section where the admin can create/add category from the webpage , he/she don't have to go to database to create it how to make this possible by sourcecode in webpage and in database?

View 12 Replies

MVC :: Put A List Of Categories On Shared Master Page?

Mar 12, 2010

I am trying to put a list of categories on my shared master page, I have it working by passing my list of categories to the shared master page in a viewdata[] object - Problem I have is I now want to loop through and out put the links to my categories (Which I am doing this)

[Code]....

View 3 Replies

MVC :: Programmatically Creating List From Multi-Level Categories?

Mar 16, 2010

I have a multilevel Category Table, like so

CategoryID, CategoryName, ParentCategoryID, IsMainCategory

I want to be able to loop through all the categories starting with the Main Categories and then go all the way down for example I could have

[code]...

I wanted to be able to loop through ALL categories in order like above programatically - This is how far I got

[Code]....

But I hit a stumbling block.. I just wanted to check I am tackling this the right way? Or is there something simple I'm missing?

View 2 Replies

DataSource Controls :: Retrieving List Of Categories For A Post?

Jun 4, 2010

I have a ListView inside my UserControl which is showing a list of posts from the table named posts. I've also got a category table which is full of the categories. I then have another table which contains the PostID and the CategoryID so that posts can have multiple categories. I was wondering, in my ListView at the moment I only have a list of the posts but I would like to add, for every post in the listview, the cateogires it is in.

View 12 Replies

Multilevel Nested Product Categories Display With C# And Sql Server?

Jun 9, 2010

I have a product category table with the following fields:

cat_id (PK)
Cat_name
Cat_desc
Parent_Cat_Id

Now when a user wants to add a product he should be able to select multiple categories from a listbox(multiselection enabaled). But to let the user know the hierarchy of the categories, I need to display them in the following style:

parent category 1
parent category 1->sub category 1
parent category 1->sub category 1->sub-sub category 1
parent category 1->sub category 1->sub-sub category 2
parent category 1->sub category 2
Parent category 2.........

I know that to achieve this I need to use recursive programming. But how can we do it via stored procedures?

View 2 Replies

MVC :: Entities Data Models With Multiple Categories Using A Membership Table?

Sep 18, 2010

(Using SQL Server 2008 and ASP.NET MVC2)I have a simple business table and a category table. I have a 3rd table to map business to category, a many-to-many relationship. the Map table contains a BusinessID and CategoryID. I'm lost as to how I can load the categories into my Business View Model using the entities model.Without incorporating categories, my code looks like this:

[Code]....

with Business View Model defined as:

[Code]....

but if i want to populate the Categories with the mapped categories, how would one do that?

View 1 Replies

MVC :: Listboxfor And MultiSelectLists / How To Get The providers's Categories To Be Selected On The Load Of The Page

Nov 19, 2010

I am a student at Millsaps College in Jackson, Mississippi and im working on my Senior Project. For my project i have chosen to use ASP.net MVC 2. Most things seem to be going well, but im having a real issue with the ListBoxFor() method. I have read a ton of posts on this website, StackOverflow as well as others. Here is a description of my problem.

One of the major points of my project is to create a directory of healthcare service providers in Mississippi. These providers can be sorted into multple categories, which creates a many-to-many relationship. Im using a ListBoxFor() to display those categories
when the user would like to edit or create a provider. In the case of creation things work well. However in the case of editing an existing provider, i am unable to figure out how to get the providers's categories to be selected on the load of the page. Below is a look at some of the code. I would be so thankful to anyone who could help me tackle this issue

1. I am using the Entity Framework as my model.

2. Here is the controller i have created

[Code]....

Below is the view portion [Code]....

View 7 Replies

Forms Data Controls :: Gridview Custom Paging By Categories?

Jul 28, 2010

Is there any way to have the gridview page by categories instead of pages. In other words instead of at the bottom having some sort of page numbering scheme there would be categories from a specific column (kind of like a group by in sql) arranged along the bottom and when I would click one it would page to the start of all those matching rows (preferably return all of them rather than just say 10 or 20).

View 1 Replies

DataSource Controls :: Repeating A Nested (or Sub) Query For Multiple Categories?

Jul 10, 2010

I'm trying to design a page that displays all suppliers by their location. I'd quite like this to work from a query that will automatically include new locations added in the future.

At the moment my design has a table that holds 'locations' with locationID and locationName fields. In my 'suppliers' table I also have a locationID to join them.

I'm not sure how to query the database to return all the suppliers in location 1, then all in location 2. (Or even sure of the terms I need to Google to get some examples!) For example:

Location 1
Supplier 1
Supplier 2
Location 2
Supplier 3
Supplier 4

View 3 Replies

Web Forms :: Data List Control To Display The Categories And Forum?

Mar 30, 2012

sample code for datalist to display the categories and forum like used in a  aspsnippet forum

View 1 Replies

ADO.NET :: Not Duplicate / Query A Products Table Based On Categories Selected By The User?

Feb 22, 2011

i posted a question yesterday but it got taken off by moderator mbanavige with the reason indicating it was a duplicate post. i know for sure it was the first time i was asking that question. i will have to ask it again NOW because it was deleted. hope THIS one does not duplicate the one i made yesterday. so here goes:

I need to query a products table based on categories selected by the user. The selection of the categories is a checkbox list, and user can select any number of categories (including none at all). I only know how to compare one parameter at a time. Like this:

[Code]....

View 3 Replies

Forms Data Controls :: Add Categories To Repeater That Displays List Of Job Postings

Jun 8, 2010

I have a repeater that displays a list of job openings. I now need to modify the repeater and break out the job openings by category.

See below for the existing code for my repeater. I'm not sure how I need to modify my repeater to display the jobs under the appropriate categories.

I've added a new JobsCategory table to the database and added the foreign key relationship between my jobListing table and the jobcategory table.

I've created a new stored procedure to pull the jobs my category:

CREATE PROCEDURE [dbo].[GetJobsByCategory]
@categoryId int
AS
BEGIN
SET NOCOUNT ON
SELECT j.JobID, j.JobTitle, j.URL, j.City, j.State, j.Country, c.CategoryName
FROM ADPJobListing j
INNER JOIN ADPJobCategory c ON j.CategoryID = c.CategoryID
WHERE j.CategoryID = @categoryId
END

In my typed dataset (tableadapter), I'll add a new query to the above stored procedure and finally in my business logic layer, I'll add a new method to call down into my data access layer:

[DataObjectMethod(DataObjectMethodType.Select, false)]
public ADP.JobsDataTable GetJobsByCategory(int categoryId)
{
return this.Adapter.GetJobsByCategory(categoryId);
}

How do I need to modify my repeater to display the jobs by category?

[Code]....

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved