Get the value from the CheckBox Control

35,600

Solution 1

You must get Value attribute.

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

Solution 2

myCheckbox.Checked

returns true or false based on the state of the checkbox.

Solution 3

try this : ((CheckBox)(c)).Checked.ToString()

Share:
35,600
Asier Pomposo
Author by

Asier Pomposo

Updated on April 05, 2020

Comments

  • Asier Pomposo
    Asier Pomposo about 4 years

    How can I get the value from the CheckBox Control before is selected?? It doesn´t have a .Value method.

    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?
    
  • Asier Pomposo
    Asier Pomposo almost 9 years
    it returns False value
  • Jamil
    Jamil almost 9 years
    Well this is what "value" means in checkbox.
  • Kram
    Kram almost 9 years
    Try AutoPostBack="true" on your check box in the aspx
  • keypcb
    keypcb about 5 years
    Your checkbox control