dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online Membersprofit22
Pawan Awasthi
nagendra varma
Padma
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Forums » .NET » ASP.NET »

Bingdropdown with the database dynamically


Posted Date: 18 Jun 2012      Posted By:: ramya     Member Level: Bronze    Member Rank: 7477     Points: 3   Responses: 2



I want to display the categories and subcategories in single dropdownlist

eg:

Main Category 1-->The main categories should be in disabled state(ie.it shouldnt be selected by the user)
- Sub Category 1.1
- Sub Category 1.2
- Sub Category 1.3
Main Category 2
-Sub Category 2.1
-Sub Category 2.2
etc...




Responses

#675939    Author: Anil Kumar Pandey      Member Level: Platinum      Member Rank: 1     Date: 18/Jun/2012   Rating: 2 out of 52 out of 5     Points: 3

Here is a sample code to bind the drop down list dynamically


SqlConnection con = new SqlConnection(ConnStr);
string strQuery = "select EmpName,ID from emp where Id>100";

SqlDataAdapter ada = new SqlDataAdapter(strQuery, con);
DataSet lds = new DataSet();
ada.Fill(lds);

ddlname.DataSource = lds;
ddlname.DataTextField = "Empname"
ddlname.DataValueField = "Id"
ddlname.DataBind();
ddlName.Items.Insert(0, "-Select-");



Thanks & Regards
Anil Kumar Pandey
Microsoft MVP, DNS MVM



 
#676450    Author: Ultimaterengan        Member Level: Gold      Member Rank: 9     Date: 20/Jun/2012   Rating: 2 out of 52 out of 5     Points: 3

Dear friend,

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Give your connection string here");
string SQLQuery= "select categoryID,ID from categorymaster";
SqlDataAdapter ads = new SqlDataAdapter(SQLQuery, con);
DataSet ds = new DataSet();
ads.Fill(ds);
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "categoryID";
DropDownList1.DataValueField = "Id";
DropDownList1.DataBind();
}
}








Thanks & Regards
G.Renganathan
Nothing is mine ,Everything is yours!!!


http://renganathan1984.blogspot.com/



 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : Make a Web Page Set to all Screen Sizes
Previous : How to get Selected Values In Excel Sheet ?
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.