Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,

I have Selected and Combined 2 columns into 1 column in DropDownList in the following DataSource:

ASP.NET
<asp:SqlDataSource ID="SqlDataSource12" runat="server" ConnectionString="Data Source=MEHDI-PC\SQLEXPRESS;Initial Catalog=PIMS;Integrated Security=True" ProviderName="System.Data.SqlClient" SelectCommand="SELECT (convert(varchar,CostID) +'   ,   '+ Item_Description) Cost_ID FROM Cost_ID"></asp:SqlDataSource>


I want to display both the columns (CostID, Item_Description) to help users to read Item Description while choosing the CostID. But when User chooses an item from the combined columns, I only want CostID as the field value. For example suppose CostID is 01, and Item Description is "General Requirments", currently my query results in showing 01,General Requiements in the DropDownList value. When users selects this value, it is entered as 01,General Requirements in the SQL Database while I need only the CostID (01) to be stored in the SQL Database
Posted
Updated 28-Jul-13 9:55am
v2
Comments
[no name] 28-Jul-13 20:32pm    
So split the value and only insert the part you want in your database.
BulletVictim 30-Jul-13 6:04am    
Pass the Dropdownlist value.Remove(n(until the comma)) to the database
So in your case it would be Ddl.SelectedValue.Tostring().Remove(2); this code is not 100% but should give you an idea of how to do it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900