0

this is my code:

sdsNamaSales.SelectCommand = "SELECT ID, NAMA FROM REF_SALES_OFFICER WHERE" +
                                     " SOF_TYPE = '" + ddlJenisSales.SelectedValue + "' AND KOT_ID = '" + ddlKota.SelectedValue + "'";
        // insert nama sales manual
        ddlNamaSales.Items.Clear();
        ddlNamaSales.DataSource = sdsNamaSales;
        ddlNamaSales.DataTextField = "NAMA";
        ddlNamaSales.DataValueField = "ID";
        ddlNamaSales.DataBind();
        ddlNamaSales.Items.Insert(0, new ListItem("--PILIH--", "--PILIH--"));

i want to set value ID in ddlNamaSales.DataTextField = "NAMA", now ddlNamaSales.DataTextField = "ID - NAMA"

3
Contributors
2
Replies
5
Views
7 Years
Discussion Span
Last Post by __avd
0

You could add an extra field to your query to create the display value:
"SELECT ID, NAMA, CAST(ID AS nvarchar) + ' - ' + CAST(NAMA AS nvarchar) AS DisplayValue FROM REF_SALES_OFFICER WHERE..."
Then assign DisplayValue to your control.

0

>how to get two value in dropdownlist in asp.net c#

Have a look at sample,

void page_load() {
   if(!IsPostBack) {
         DataTable dt=new DataTable();
         dt.Columns.Add("ProdID",typeof(int));  
         dt.Columns.Add("ProdName");

         dt.Rows.Add(1,"Pen");
         dt.Rows.Add(2,"Pencil");

         DropDownList1.DataSource=dt;
         DropDownList1.DataTextField="ProdName";
         DropDownList1.DataValueField="ProdID";

         DropDownList1.DataBind(); 
   }
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.