我想在asp.net代码后面获取jquery select2插件的选择值。
这是我的来源
客户端:
<select id="ddlcountry" runat="server" class="select" style="width: 100%;">
</select>
隐藏代码:
var query1 = from pcountry in CTX.Countries
orderby pcountry.Country1 ascending
select new
{
pcountry.CountryId,
pcountry.CountryName
};
if (query1 != null)
{
ddlcountry.DataSource = query1.ToList();
ddlcountry.DataValueField = "CountryId";
ddlcountry.DataTextField = "CountryName";
ddlcountry.DataBind();
ddlcountry.Multiple = true;
}
protected void btnSave_Click(object sender, EventArgs e)
{
Now i want to get all the selected country values here ?
}
请帮助我,我将非常感激。
最佳答案
如果您没有创建 <select>
元素为<ASP:DropDownList>
控件,那么我不相信您将有权访问“Datasource”等属性和方法。但是,您可以访问具有 runat="server"
的 HTML 元素。添加属性。
我相信<option>
标签是通用 HTML 控件类型。我坚持使用 VB.Net,所以我必须为你编写一些伪代码...
For each o as HtmlGenericControl in ddlcountry.Children.ofType(of HtmlGenericControl)
If o.Attributes("selected") then
' Here you can access your option value using the "value" attribute (and InnerHtml works too, I think)
End if
Next o
<小时/>
这是一个答案的链接,我在其中展示了如何使用工作示例循环遍历通用控件:
关于javascript - 如何使用asp.net获取jquery select2标签列表的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29083290/