Add ListBox values toTextBox on Button click in ASP.Net did not work correctly -


i have 1 list box , 1 text box, want add list box value text box on button click , not working correctly, can please me ,i can add item text box cant add more item text box (multiselect)thanks in advance

textbox

<div class="col-sm-3">     <asp:textbox id="txtdesignname" runat="server" cssclass="form-control" width="250px" ></asp:textbox>  </div>      

listbox

<div class="col-sm-3">     <asp:listbox id="lstvalue" runat="server" cssclass="content" rows="5" validationgroup="save"                width="250" onselectedindexchanged="lstvalues_selectedindexchanged"></asp:listbox> </div> 

add button

<asp:button id="btnadd" runat="server" cssclass="button" text="add" validationgroup="add"          width="70" onclick="btnadd_click" /> 

codebehind

protected void btnadd_click(object sender, eventargs e) {     //if(txtdesignname.text.equals(string.empty))     //{     //    return;      //}     //else     //{         lstvalue.items.add(txtdesignname.text);     //} } 

lstvalues_selectedindexchanged

protected void lstvalues_selectedindexchanged(object sender, eventargs e)         {             txtqlt.text = lstvalue.selecteditem.tostring();           } 

the question, have asked , code have shown both representing different purposes. so, provided 2 options; choose whatever want.

to display selected list box-items text-box

protected void btndisplay_click(object sender, eventargs e) //create display button process {   string selecteditems = string.empty;   string separator = ",";   foreach (int in lstvalue.getselectedindices())   {    selecteditems += lstvalue.items[i] + separator;   }   txtdesignname.text = selecteditems.trim(','); } 

to add text-box value list-box items

protected void btnadd_click(object sender, eventargs e) {   if (txtdesignname.text.trim() != string.empty)   {     lstvalue.items.add(new listitem(txtdesignname.text));     txtdesignname.text = string.empty; //reset text-box value   } } 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -