Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET SQL-Server
How do I concatenate two dropdown list values into a single value for entry into a database field? Also i want to split them into the two dropdown list accordingly when displaying in update mode.
 
For example: I want to enter the height of the person as 5'3" in height field of my database table. But i collect them seperately as feet(5) and inches(3) in two dropdownlists. How do i concatenate and send them to my database table's height field? Also when I retrieve them in update mode it should split and display accordingly as 5 in feet dropdownlist box and 3 in inches dropdownlist. Any ideas on how do I do this? Please help....i've been trying this for a while, still no idea.
Posted 29-Apr-13 19:18pm
Comments
Usha Muhunthan at 30-Apr-13 0:37am
   
First store them in a string. Cosider 2 dropdownlist(5'3") names dropdownlist1(for 5) and dropdownlist2 (for 3)
 
string s = dropdownlist1.Text + " ' " + dropdownlist2.Text;
 
insert s into table
 
-------> In update mode just retrieve value from table split it where it find '
string[] height= str.Split(''');
dropdownlist1.Text=height[0].ToString();
dropdownlist2.Text=height[1].ToString();
 
----------> str is table value
 
Hope it helps to you, If not reply me
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can store these values in database concatenating with any separator (|)
Ex. store "5|3" in database
 
Now when you need to display it in edit mode then split these values by "|"
 
var data = heightValue.Split('|');
 
so you will get array of string
 
var heightInFeet = data[0];
var heightInInch = data[1];
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

<asp:DropDownList runat="server" ID="drop1">
        <asp:ListItem runat="server" Value="5">5</asp:ListItem>
        <asp:ListItem runat="server" Value="7">7</asp:ListItem>
    </asp:DropDownList>
    <asp:DropDownList runat="server" ID="drop2">
        <asp:ListItem runat="server" Value="10">10</asp:ListItem>
        <asp:ListItem runat="server" Value="12">12</asp:ListItem>
    </asp:DropDownList>
    <asp:Button runat="server" ID="save" Text="Save" onclick="save_Click"/>
    <asp:Button runat="server" ID="retrive" Text="Retrive" onclick="retrive_Click"/>
 

 

 
protected void save_Click(object sender, EventArgs e)
    {
        string ddlValue = drop1.SelectedValue + "-" + drop2.SelectedValue;
        //database.save(ddlValue)

    }
    protected void retrive_Click(object sender, EventArgs e)
    {
        //retriveValue=database.retriveValue;
        string retriveValue = "7-12";
        string[] arrRetrive = retriveValue.Split('-');
        drop1.SelectedValue = arrRetrive[0];
        drop2.SelectedValue = arrRetrive[1];
    }
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 480
1 Maciej Los 290
2 Richard MacCutchan 225
3 BillWoodruff 185
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,764
1 Sergey Alexandrovich Kryukov 7,437
2 DamithSL 5,639
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411028.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100