DropDownList Which Binds Values from DB

Hi All, 

I want to develop a custom asp.net server control. A drop down list which contains values from Database table. 

LIke EmpDropDownList contains Employees Names into Text and ID into Value field. 

How to Develop it?


Thanks in Advance. 

4/28/2009 11:24:51 AM
asp.net.custom-server-controls 3498 articles. 0 followers. Follow

4 Replies

Similar Articles

[PageSpeed] 18

Create one Custom Control which contains properties like ConnectionString, DataValueFiled, DataTextFiled, and TableName.

Bind them in CustomControlLoad event, that will do...

make sure that you are taking care of SelectedValues in post back..

thank you,

-nm reddy

***Hope this helps you***
thank you,
-nm reddy
4/28/2009 11:32:35 AM
cmd = new SqlCommand(commandText, conn);


        dr = cmd.ExecuteReader();
        //Bind Priority
        DropDownList.DataSource = dr;
        DropDownList.DataTextField = "Name";
        DropDownList.DataValueField = "id";

Try This it will work
4/28/2009 11:32:46 AM

 u just need to bind data to dropdown list...

cmd= new sqlcommand("select * from mydatabse",cn)





4/28/2009 11:51:27 AM
4/28/2009 12:47:20 PM

Similar Artilces:

URGENT: DropDownList in custom server control not holding value on postback
Hello All,I have a problem where a DropDownList contained within one of my custom server controls is not holding its value on postback.  I've tried several different things but can't seem to find why it's dropping its value.  ViewState is enabled on the page and I've not specifically disabled ViewState on any of the controls.Below is the code specific to the dropdownlist in the custom control. public class DatePicker : WebControl  {    // CREATE CONTROLS    public DropDownList Month = new DropDownList();     &n...

Usercontrol vs Custom Server Controls, Any need for Custom Server Controls
Hello I'm new to ASP.Net so this is probably a stupid question but, is there any need to create customer server controls now that you can pre-compile usercontrols into a dll and thus easily share between applications? This blog post from David Ebb describes how to do it and the restrictions he note don't seem that bad (other than being able to embed resources such as images in the dll). http://blogs.msdn.com/davidebb/archive/2005/10/30/487160.aspx His article desribes the techniques for ASP.Net 2.0 and he suggests that there will be further improvements in .Net 3.5 in this ar...

problems listenening to events on a custom server control from another custom server control
 Hi all,I am having problems listening to events on one of custom server controls(AddBookmark) from another custom server control(BookmarkList). The listener or the BookmarkList control has a property that can be set to the AddBookmark control (string at design but the reference is obtained at run-time). I am able to get a reference to the AddBookmark control and add a listener to it on the BookmarkList control on the OnPrender of BookmarkList. But the problem is that when the events on AddBookmark gets fired, the listener added from the BookmarkList is no longer present and the listene...

Custom Server Control Vs Web Parts, Any need for Custom Server Control
Hello I've just posted a similar question on why you need server controls when you can pre-compile usercontrols and redistribute them. http://forums.asp.net/p/1397433/3010100.aspx#3010100 I've seen lots of (usercontrol vs web part) but not much on web part vs custom server control. According to the MSDN site you can put web parts onto a normal asp.net page outside of a web part zone and they behave just like custom server controls. So, if you are creating a bunch of controls for redistribution to customer asp.net sites and/or SharePoint sites why don't you just create Web Par...

Creating .Net custom server controls and .Net pages programatically
Thanks a lot for reading this and greatly appreciate your inputs I am writing a webinterface that lets users configure options that'll create an interface for them and generete the webpage. So I am having to programattically create custom server controls and .Net page with code behind to support the functionality. Are there APIs in the .NET SDK that let you do this. Any pointers would be greatly helpful Thanks a lot Sathya Controls on the fly? Or Create code on the fly? I think it is the latter so here we go - look at the following namespaces: * System.Reflection.Emit - gen...

Custom Server Control Made of Custom Controls?
I'm giving myself a crash course in custom server controls, and I have a quick general question. Can I have a custom server control that is composed of other server controls I created. I'm pretty sure the answer is yes, but I want to be positive. Yes http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondevelopingcompositecontrols.asp Shows how to combine existing controls into a new control using class composition. -ron Thanks! ASP.NET so rocks! Making page components extensible objects is such a great idea! I love it....

new to .net, need help setting db values from checkbox's then retrieving value to a label control
Hi, Being new to asp.net i know this possible i just can't quite get it right!  I need a page with 5 checkbox's that when submitted sets the bit values in DB fields to checked. Then i need another page that retrieves the records of the checkboxes, but instead of having the db pre-set checkboxes on the second page i want it to turn on label web controls depending on if the check box is set.. I hope that makes sense?!! Can anyone point me in the right direction or to a suitable tutorial? Thanks in advance Ben Excellent article here.http://www.heliosfx.com...

Bind value from db to Checkboxlist control
Does anybody knows how to bind the checkboxlist value from db? I have a  field name called "OtherFeatures" from my db  that collects all values from the checkboxlist control everytime user is adding new record. Example value inserted into my db are: value1, value2, value3, value4 When user wants to edit the record I have to display the records from db using a FormView control  inside the EditTemplate. I tried to add the attribute SelectedValue='<%# Bind("OtherFeautres") %>'  in my checkboxlist control and it works OK. IF I only one value in...

Dropdownlist Server Control losing values
I've created a dropdownlist server control (code below), if I try and toggle the visibility of the control using a button for instance, the control loses it's items, any idea why this is? [DefaultProperty("Text"), ToolboxData("<{0}:ActiveEmployeeDropDownList runat=server></{0}:ActiveEmployeeDropDownList>")] public class ActiveEmployeeDropDownList : System.Web.UI.WebControls.DropDownList { #region Fields private string _text = "Please Select"; #endregion #region Properties [Bindable(true), Category("Appearance"), DefaultValue("Please Select")] public string Text ...

Error binding value to custom DropDownList
I have a custom control that inherits from DropDownList.  Inside OnInit I bind the control to data pulled from the database.  If I put the control on a page by itself it works fine and all events fire properly.  If I try to use it inside of a GridView and bind a value to it, like I would with an ordinary DropDownList, I get the following error: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. Description: An unhandled exception occurred during the execution of the current web req...

how to have both server controls and html controls rendered in a custom control?
I have a custom control in which there is an html text box.when you click on it , a div containing a table is appeared and according to what you select in that table a text is set to the text box. It works fine but the problem is: as the text box is an html element it doesn't have viewstate and when a post back occures in the page its value disappeares.I tried a hidden field to keep its value.again there is another problem : I put this custom control in a usercontrol and put the usercontrol in a multiview and by clicking on a button this view is selected and by clicking another bu...

Binding list of values to DropDownList control through a template
Hi there.I'm using a template in order to create a custom column in a GridView control, like that:TemplateField tc = new TemplateField();tc.ItemTemplate = Page.LoadTemplate("someUserControl.ascx");grid.DataSource = vView;grid.Columns.Add(tc);grid.DataBind();   In order to bind a value of a column into the template, I use the following code for labels, textboxes, etc.:Text='<%# Eval("ColumnName") %>'Now to the problem. One of the columns ("tQuantity") contains DataTable objects, which contain the text ("packageQ") and Va...

How to Build a custom DropdownList Web Server control
Hello 1-I want to make a Dropdown list 2-To whom i just porvide the table name and column for data 3-In the control i want to make the customized data base code . 4-It will populate it self with providing the dataset to it 5-I will be very thank full to you if you can guide me to how to build this Like control control should handle the event and viewstate.. Thanks Waiting for your kind reply Malik Asif JoyiaRegards, Malik Asif Joyia. 1. Create a new class and inherit the DropDownList control 2. Add properties for TableName and ColumnName(s) Heres where yo...

Custom server control
I am trying to create a simple generic pager control. I want to get the current page index from the querystring of the parent page that contains this pager control. I built the control and try to drop it on an aspx page, it shows an error. It's because of this line in the render method (no error if I comment this line out), where I retrieve the current page index from the page querystring. Like this: HttpContext.Current.Request.QueryString["page"] The error is 'object reference not set to an instance of an object'. There is no request object or parent page or querystring at design...

Web resources about - DropDownList Which Binds Values from DB - asp.net.custom-server-controls

Tag Synonyms - Stack Overflow
Q&A for professional and enthusiast programmers

Accidental entities - what about the UI?
This post is a follow-up to my previous blog post " Accidental entities - you don't need that identity ". In that post, we followed a consultant ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Air Astana - Join Now
Thank you for considering membership of Nomad Club – Kazakhstan’s first Frequent Flyer Program. You could soon be on your way to earning free ...

Languages -> C# Articles, Tutorials, Examples: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Blog - Avisra
Avisra Web Development Home Blog Services Contact The Blog Latest Module Builder: How can we make it better? Sitefinity by Chris on July 2, 2013 ...

Online Booking Tool Support
This Online Booking Tool Support page might help you as you navigate through the process of booking travel through your OBT provided by CWT. ...

@Html and beyond
... ); } return string .Format( “{0}{1}” , me.Member.Name, id); } The Html building methods are quite simple. Building a dropdownlist for a ...

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

Unit Testing DateTime.Now Without Isolation
public virtual void SeedWithYearsSince(DropDownList list, int year){ for (int index = year; index

Resources last updated: 11/25/2015 3:15:49 AM