We have two table named food_category and food. The Structure of the tables :
food table
No. | Table Name | Data Type | Desc. |
---|---|---|---|
1 | food_id | AutoNumber | PK, Autoincrement |
2 | food_name | Short Text(255) | - |
3 | description | Short Text(255) | - |
4 | food_status | Yes/No | - |
5 | category_id | Number | FK |
food_category table
No. | Table Name | Data Type | Desc. |
---|---|---|---|
1 | category_id | AutoNumber | PK, Autoincrement |
2 | category_name | Short Text(100) | - |
3 | description | Short Text(255) | - |
4 | category_status | Yes/No | - |
Here is the relationship between food and food_category table :
Now... Let's Cook !
1. Run your Visual Studio. I’m using Visual Studio 2010 and Microsoft Access as DataSource for this food
2. Create a New Web Site > ASP.NET Empty Web Site > Give the name of Food : menu01_allcategory
3. Add New Item > Web Form > Default.aspx
4. Add ASP.NET Folder > App_Data
5. Add Exisitng Access Database on App_Data folder
6. Create a simple page like this :
7. Assign food_category DataSource to a DropDownList and food DataSource to a GridView
8. Change the properties of DropDownList : “AppendDataBoudItems” to True, “AutoPostBack” to True
9. Edit Item on a DropDownList, Add a ListItem, Text = All Category, Value = 0
10. Edit the Query of food DataSource :
SELECT [food_id], [food_name], [description], [food_status], [category_id]
FROM [food] WHERE ([food_status] = ?)
AND (([category_id] = ?) OR (’0′ = ?))
11. Define Parameters :
No. | Parameters | Parameter Source | ControlID | DefaultValue |
---|---|---|---|---|
1 | food_status | None | - | True |
2 | category_id | Control | DropDownList1 | 0 |
3 | category_id | Control | DropDownList1 | 0 |
Okey… It’s time to EAT :-)
Download Source : menu01_allcategory.zip
No comments:
Post a Comment