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.
Andrew FensterPosted Feb 13, 2012, 4:06 PM
khaleel shaikPosted Feb 13, 2012, 4:41 AM
dropdownlist.datasource=ds;
dropdownlist.datatextfield="columnname";
dropdownlist.datavaluefield="colunid";
dropdownlist.databind();
use this code
Satyapriya NayakPosted Feb 8, 2012, 7:29 AM
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
Pramod Kumar NandagiriPosted Feb 8, 2012, 7:02 AM
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.