从CheckBox控件获取值

问题描述 投票:3回答:4

如何在选中之前从CheckBox控件中获取值?它没有.Value方法。

else if (c.GetType() == typeof(CheckBox)) // c is control
{
      string textValue= ((CheckBox)(c)).Text; // here I take the text
     string value= ((CheckBox)(c)).????; //how should I take the value?
c# asp.net checkbox webforms
4个回答
2
投票

你必须得到Value属性。

string Value = checkbox1.Attributes["Value"];

1
投票

试试这个:((CheckBox)(c))。Checked.ToString()


1
投票
myCheckbox.Checked

根据复选框的状态返回true或false。


0
投票

你可以尝试这个:

<input id="chkBox1" name="chkbo" type="checkbox" value="myvalue" runat="server" />

然后你可以从后面获取值字段:

chkBox1.value;
© www.soinside.com 2019 - 2024. All rights reserved.