Click here to Skip to main content
15,913,773 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a DropDownlist that contains values
C - Corporates
FT - Fasttrack
Nt - NoramlTrack

Based on the Selection i need to Save the Short Forms in Database

I need to save only C, FT,Nt..... in the Database.

Can we handle this in Database level or in the CodeBehind..?
Posted
Comments
Thanks7872 5-May-14 5:46am    
If you specify these values[C,FT,NT] as value in listitem as suggested in solution-1,then Dropdownlist.SelectedValue will directly give you the desired results. Whats the actual problem here?

use Substring in Codebehind

C#
var s = "FT-Fasttrack";
         var firstWord = s.Substring(0, s.IndexOf("-"));


Better you Can Store the Value
 
Share this answer
 
v2
you can handle it at c# side

Create drop down like this

XML
<asp:DropDownList ID="DropDownList1" runat="server">
               <asp:ListItem Text="C - Corporates" Value="C"></asp:ListItem>
               <asp:ListItem Text="FT - Fasttrack" Value="FT"></asp:ListItem>
               <asp:ListItem Text="Nt - NoramlTrack" Value="Nt"></asp:ListItem>
           </asp:DropDownList>



Whichever fields are selected, make it comma seprated in c# with for loop or with any logic.

C#
string s = "";
        for (int i = 0; i < DropDownList1.Items.Count; i++)
        {
            if (DropDownList1.Items[i].Selected)
                s = s + DropDownList1.Items[i].Value + ",";
        }



Pass that comma seprated string to database and store it.
 
Share this answer
 
v2
string val=ddlhour.SelectedItem.Text; //
string firstval= val.Split('-')[0]
 
Share this answer
 

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