Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi! I have a textbox, a dropdown list and a button. The code from the dorpdown list is:
{
        var com = con.CreateCommand();
        com.CommandText = String.Format("SELECT * FROM People");

        con.Open();
        SqlDataReader reader = com.ExecuteReader();
        string name;
        Guid PersonID;
        while (reader.Read())
        {
            ListItem list = new ListItem();
            PersonID= reader.GetGuid(0); //id
            name = reader[1].ToString(); //name
            list.Text = name ;
            list.Value = PersonID.ToString();
            List.Items.Add(list);
        }
        reader.Close();
        con.Close();
}

I would like that when you press the button, the selected name appear in the dropdown list to apear into the textbox and remove it form the dropdown list. After that, I need to sent a message or do something like that using the pople ids from that textbox. I am thinking of an array: when I press the button, the ID from selected person to be added to an array like the name into the textbox. I coulde not do that.
If you know how to do this or if you have a better ideea, please help me!
Posted
Updated 10-Jan-12 8:01am
v2

You have couple of ways to do acheive this task.

One way -
remove text from list and add to textbox - you can do this using javascript.

You said dropdownlist, so user selects one item each time to process. I do not think you need an array for this, unless you change ddl to multiselect listbox for multiple items to be selected for processing.

Sending message - you can either use javascript or serverside processing depending on the messaging system you are using. For example if you are using email message you may not have to use serer side processing. But if you are using messaging systems like MSMQ then you may to do server side processing.

If you want process serverside have a button like this pass the ID as form parameter.

ASP.NET
<asp:Button ID="Button1" runat="server" PostBackUrl="~/MsgProcPage.aspx" 
            Text="Send Message" />
 
Share this answer
 
v2
Here is what I want to do.
Here are a fictiv items from a DropDownList:
<item value="0">Item 1</item>
<item value="1">Item 2</item>
<item value="2">Item 3</item>
<item value="3">Item 4</item>
<item value="4">Item 5</item>
<item value="5">Item 6</item>


With item 1, 3 and 6 I want to do something: to change a value from database, to delete them from database, to send a massage. Doesn`t metter what. But to do this, I need those values, because the displayed text is not unique so i can't use the delete statement.

I am using a button to add those items to another text box so the user can see what he selected, and another button to process the data.
Thank you for your time. It`s a good sugestion to use multiple items to be selected for processing though.
 
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