Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 27th, 2011, 04:58 PM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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

Code:
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;
               CatList.DataBind();
               ListItem myItem =
               CatList.Items.FindByValue(review.CategoryId.ToString());
               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
                    colListItemCollection.Add(objListItem);

                    AddChildren(colListItemCollection, objCat);
                }

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

}
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
Reply With Quote
  #2 (permalink)  
Old December 27th, 2011, 05:10 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
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!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:05 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.