I have a asp:dropdownlist I'm binding two values(columns from sql table) to it 1.EmpId and 2.EmpName 1 as DataText field and 2 as DataValueField its fine but my requirement is i want display both 1 and 2 in the dropdownlist
E-001 shashi
E-002 Abhijit
E-003 Laxmanan
when select EmpId should be selecteditem and EmpName should Selectedvalue
i have written the my code like this but i am getting problem with selecteditem due to concating..
public void BindEmp()
{
Ds = ObjTrip.BlOnLoadTrip();
DataTable Dt = new DataTable();
string Eid = string.Empty;
string EmpName = string.Empty;
string EIdEname = string.Empty;
Dt = Ds.Tables[2];
foreach (DataRow dtr in Dt.Rows)
{
Eid = dtr["EmpCode"].ToString();
EmpName = dtr["Driver"].ToString();
EIdEname = Eid + "------------" + EmpName;
ddlDriverName.Items.Add(new ListItem(EIdEname, Eid));
}
}
Result
selecteditem: E-002------------Abhijit
Selectedvalue:E-002
Loading
VulpesPosted Feb 28, 2014, 5:38 AM
using System.Text.RegularExpressions;
// ....
shashi kiran JillepallyPosted Feb 28, 2014, 6:51 AM
string str1=Dt.Rows[0]["RouteCode"].ToString();//Hyd-Delhi
string[]str2=str1.Split("-".ToCharArray());
string s1=str2[0];
string s2=str2[1];
lblRoutecode.Text = s2 + "-" + s1;//Delhi-Hyd
shashi kiran JillepallyPosted Feb 28, 2014, 4:45 AM
i have update question plz check it once
thanks..
shashi kiran JillepallyPosted Feb 28, 2014, 4:43 AM
i have update question plz check it once
thanks..
Lakshmanan Sethu SankaranarayanPosted Feb 28, 2014, 2:29 AM
Abhijit PatilPosted Feb 28, 2014, 2:26 AM
also check the below link
http://www.codeproject.com/Articles/8348/Multiple-Columns-DropDown-for-ASP-NET
hope it help for u