Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old December 27th, 2011, 04:58 PM
Friend of Wrox
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile Binding dropdown list in code behind with hand coding

Hi Imar,

In the hand coding for Category and Review scenario I am binding the Dropdownlist with code behind code. Actually I want to show some arbitrary no. of extra spaces with each Category for showing nesting effect. I am even getting those spaces but when I go for the edit section of Review then the associated category is not getting assigned for that review.

And if I Bind it to EntityDataSource in mark up view and comment those binding code in code behind then I see associated category is assigned but no space is shown.

my code while binding the DDL in code behind is

public partial class Management_AddEditReviewHandCoded : System.Web.UI.Page
  int _id = -1;
protected void Page_Load(object sender, EventArgs e)
   if (!string.IsNullOrEmpty(Request.QueryString.Get(“Id”)))
      _id = Convert.ToInt32(Request.QueryString.Get(“Id”)); 
   if (!Page.IsPostBack && _id > -1)
      using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
         var review = (from r in myEntities.Reviews
                            where r.Id == _id
                            select r).SingleOrDefault();
          if (review != null)
               TitleText.Text = review.Title;
               SummaryText.Text = review.Summary; 
               BodyText.Text = review.Body;
               ListItem myItem =
               if (myItem != null)
                    myItem.Selected = true;
               Authorized.Checked = review.Authorized;

// I am showing spaces here in both cases Edit and Insert, so I kept it separate

if (!Page.IsPostBack)
            using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
                var EntireTable = from cats in myEntities.Categories
                                  select cats;

                ListItemCollection colListItemCollection = new ListItemCollection();

                var results = from cat in EntireTable
                              orderby cat.Name
                              where cat.ParentId == 0
                              select cat;

                foreach (Category objCat in results)
                    ListItem objListItem = new ListItem();
                    objListItem.Text = objCat.Name;
                    objListItem.Value = objCat.Id.ToString();
                    // Add a top level item to the final collection

                    AddChildren(colListItemCollection, objCat);

                // Bind the final collection to the drop downs
                CatList.DataSource = colListItemCollection;
                CatList.DataTextField = "Text";
                CatList.DataValueField = "Value";

further many functions go after that but those are not important here.

So how I can show spaces along with assigning associated Category to Review...

Many Thanks
Old December 27th, 2011, 05:10 PM
Imar's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

Hi there,

Since this is not related to the book, please post this in a more general ASP.NET category. When you do, be sure to provide more relevant information and code. There's too much missing to understand your problem in the first place.


Imar Spaanjaars
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!

Similar Threads
Thread Thread Starter Forum Replies Last Post
hand code for datasets greenbriar BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 1 May 1st, 2008 05:42 AM
how to integrate a hand-held bar code scanner suneet.pant Pro VB.NET 2002/2003 4 March 4th, 2008 06:06 AM
Hand Coding VS Data Wizards Bulldog BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 3 May 22nd, 2007 04:21 AM
Datagrid binding two dropdown inkrajesh ASP.NET 1.0 and 1.1 Basics 0 July 18th, 2006 10:46 PM
fill dropdown list with items when parent list isaac_cm Pro PHP 1 July 10th, 2006 05:41 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.