Hi,
In my web application, I am binding a Dropdownlist with database and displaying USER_ID into it. I want, when I run the application the dropdownlist should show text "Select" and then a user can select a ID from it. But in my application it is showing starting ID. How can I solve this problem?
Thanks in advance.

Pramod Kumar NandagiriRank #6,963 · 252 reputationPosted Feb 8, 2012, 2:02 AM EST
DropDownList1.DataSource=dset;
DropDownList1.DataBind();
DropDownList1.Items.Insert(0,"Select");
Then first index will display "Select" text and reamining values will be u r database values.
Satyapriya NayakRank #47 · 31.5K reputationPosted Feb 8, 2012, 2:29 AM EST
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
if (!IsPostBack)
{
DropDownList_country.Items.Add("Select");
con.Open();
str = "select country from area group by country";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
DropDownList_country.Items.Add(reader["country"].ToString());
}
reader.Close();
con.Close();
}
}
}
Thanks
khaleel shaik11 reputationPosted Feb 12, 2012, 11:41 PM EST
dropdownlist.datasource=ds;
dropdownlist.datatextfield="columnname";
dropdownlist.datavaluefield="colunid";
dropdownlist.databind();
use this code
Andrew FensterRank #983 · 2K reputationPosted Feb 13, 2012, 11:06 AM EST