Reputation: 872
I am using below drop-down list that allows user to select multiple values.
How can i save the selected values from drop-down list to hidden field.
Drop Down List
<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>
HiddenField
<asp:HiddenField ID="hdnSearchParam" runat="server" />
Upvotes: 0
Views: 672
Reputation: 29026
You can use like this:
string selectedTexts="";
foreach (ListItem item in DropDownList1.Items)
{
if (item.Selected)
{
selectedTexts += item.Text + " : " + item.Value + "\\n";
}
}
hdnSearchParam.Value= selectedTexts;
Upvotes: 1