我使用下面的下拉列表,允许用户选择多个值。
如何将选定的值从下拉列表保存到隐藏字段。
下拉列表
import java.util.Scanner;
public class PF {
public PF() {
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter a line to be checked for profanity: ");
String sentence = keyboard.nextLine();
System.out.println("\nYour input line: " + sentence);
String [] prof = new String []{"cat", "dog", "llama"};
for (String s : prof)
{
if (sentence.toLowerCase().contains(s))
System.out.println("The sentence contains " + s);
else
System.out.println("The sentence does not contain " + s);
}
}
public static void main(String...banana) { new PF();}
}
HiddenField
<asp:DropDownList ID="DropDownList1" CssClass="form-control chosen-select" multiple data-placeholder="Multiple Select" runat="server" DataSourceID="SqlDataSource1" DataTextField="Product_Name" DataValueField="Pro_ID"></asp:DropDownList>
答案 0 :(得分:1)
您可以这样使用:
string selectedTexts="";
foreach (ListItem item in DropDownList1.Items)
{
if (item.Selected)
{
selectedTexts += item.Text + " : " + item.Value + "\\n";
}
}
hdnSearchParam.Value= selectedTexts;