[英]Getting value from Dropdownlist in Checkboxlist in C#
好。 我做了疯狂的事。 这实际上是正确的,但是您如何使用C#从服务器端的下拉列表中获取选定的值?
我尝试获取下拉列表代码
CheckBoxList.Items[0].Text.Substring(CheckBoxList.Items[0].Text.indexOf("<select>"));
但是现在有了下拉列表,如何从中获取所选值? EST 5/15/15 5:39 PM EST我想如果我编写有关如何创建此代码的代码,它将是:
CheckBoxList chkBoxLst = new CheckBoxList();
chkBoxLst.Items.Add("Grade");
chkBoxLst.Items.Add("2");
chkBoxLst.Items.Add("3");
chkBoxLst.Items[0].Text += "<select id='Letter' runat='server'>
<option>A</option>
<option>B</option>
<option>C</option>
</select>"
我正在使用服务器端代码动态创建此代码。
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem>Grade <select id="Letter" runat="server">
<option>A</option>
<option>B</option>
<option>C</option>
</select>
</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:CheckBoxList>
如果您看到我正在尝试做的事情并且知道更好的方法,欢迎提出建议。
如果您要获取的是所选值,请更改此值
<select id="Letter" runat="server">
<option>A</option>
<option>B</option>
<option>C</option>
</select>
为了这
<asp:DropDownList ID="Letter" runat="server" >
<asp:ListItem Text="A" Value="A"></asp:ListItem>
<asp:ListItem Text="B" Value="B"></asp:ListItem>
<asp:ListItem Text="C" Value="C"></asp:ListItem>
</asp:DropDownList>
并获取选定的值,执行此操作
string selectedValue = Letter.SelectedValue;
您还可以使用SELECT
元素的id从Form values集合中获取值。
var val = Request.Form["Letter"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.