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

I have a textbox and two buttons (Add and Show).
I want that when I click on add button after entering a value in the textbox then that value should be added in list which would appear on Show button click.

Please guide me how I can handle this.
Thanks in Advance
Posted
Updated 9-Jan-11 22:13pm
v2
Comments
Dalek Dave 10-Jan-11 4:13am    
Edited for Grammar, Spelling and Readability.

add textbox
add eventhandler for Add button, retrieve text from textbox, store in db
add eventhandler for Show button, select list from db, render list

Update:
If you wnat the same button to act as both an Add and a show button:
add eventhandler for Add/Show button - retrieve text from button if text is "Add" execute add functionality, if text is "Show" execute show functionality. For the rest do as above.

Regards
Espen Harlinn
 
Share this answer
 
v2
Comments
Dalek Dave 10-Jan-11 4:13am    
Quick and Simple.
Espen Harlinn 10-Jan-11 4:47am    
Thanks Dalek!
Try this code:
C#
private ICollection<string> lst = new List<string>();
        private void btnAdd_Click(object sender, EventArgs e)
        {
            lst.Add(txtValue.Text);
        }
        private void btnShow_Click(object sender, EventArgs e)
        {
            listBox1.DataSource = lst;
            listBox1.DataBind();
        }
 
Share this answer
 
v3
Hi,
There is little change here the second button is Show/Hide. It should not only show the list but when i click it again the list should disappear. Can i achieve this functionality through ajax?
 
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