C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Databinding »

How to bind a dropdown list using Sql query


Posted Date: 31 Jul 2009    Resource Type: Code Snippets    Category: Databinding
Author: RadhuMember Level: Gold    
Rating: 1 out of 5Points: 4



Description :


How to bind a dropdown list using Sql query


public void GetCenterName2()
{
dt = new DataTable();
con = new SqlConnection(constr);
da = new SqlDataAdapter("Select center_name from centermaster where deletion_status = 'U'",con);
da.Fill(dt);
if(dt.Rows.Count > 0)
{
ddlCentername.DataSource = dt;
ddlCentername.DataTextField = center_name";
ddlCentername.DataValueField = "center_name";
ddlCentername.DataBind();
ddlCentername.Items.Insert(0, new listItem"Please Select"));
ddlCentername.Items.Insert(1, new ListItem("Others"));
}
}



Responses

Author: Deepika Haridas    31 Jul 2009Member Level: Diamond   Points : 2
Hi,

Use proper formatting for your post. I have done it for this one but hope from next time onwards you will take care of these things.

---
Thanks & Regards,
Deepika
Editor



Author: Radhu    07 Aug 2009Member Level: Gold   Points : 0
Ok


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Bind a dropdown list using Sql query  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Acessing data from SQL server using Dataset
Previous Resource: Data binding using DataAdapter and Datareader
Return to Discussion Resource Index
Post New Resource
Category: Databinding


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use