How to check if CheckBox is check in C#

Hi all,

Please help.
I have  a gridview and inside the <HeaderTemplate> I declare a checkBox as follow:

<HeaderTemplate >

<asp:Label ID="Label6" runat="server" Text='Code' CssClass="dirStyle1"></asp:Label>&nbsp;

<asp:CheckBox ID="CheckBox1" runat="server"/>

</HeaderTemplate>

so let say i have a button for PostBack/Submit
so how do I check if the checkbox is check?


I tried

------------------------------------------------------------

CheckBox chbx = GridView1.FindControl("CheckBox1") as CheckBox;

if (chbx != null && chbx.Checked)

      Response.Write("Checkbox 1 is checked ");

else

    Response.Write("not check");

-------------------------------

and the answer is always "Not Check"

 

 

Thanks for your help

0
BrigideW
11/21/2007 9:40:53 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
1442 Views

Similar Articles

[PageSpeed] 34

Your if statement will always be false.

If (chbx is null) AND (chbx is checked) will always be false since they can't be both. Try removing the first condition (checking for null) or place an OR operator instead of AND. Hope that helps.


Please mark as "answer" if this helped you in anyway.
0
onSlaught
11/21/2007 9:52:54 PM

Button1 is outside of the GridView:

<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

 protected void Button1_Click(object sender, EventArgs e)
    {
        CheckBox chbx = GridView1.HeaderRow.FindControl("CheckBox1") as CheckBox;

        if (chbx != null && chbx.Checked)
            Response.Write("Checkbox 1 is checked ");

        else

            Response.Write("Checkbox 1 is not checked!"); 


    }
 

Limno

0
limno
11/22/2007 12:01:16 AM

It is a dynamic checkBox so on page load it has not created it yet
if I dont check if it is not null I will a error message beside if it is not null then therefore the value of the checkbox could be check or not checked
so the condition is correct

 

0
BrigideW
11/23/2007 12:14:36 AM
Reply:

Similar Artilces:

checking checkbox is checked or not using checkbox.checked
Hi,my checkbox is<asp:CheckBox ID="Chkcity" runat="server" Text="My own city"  OnCheckedChanged="EventHandler"/>code behind: Private Sub Chkcity_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Chkcity.CheckedChangedif (Chkcity ...............)end if End SubERROR    'EventHandler' is not a member of 'ASP.bpoaddjob_aspx'.    Please Mark the post as "ANSWER" if it helps you I think it should be like this:<asp:CheckBox ID="Chkcity"...

Check All Check Box While Check Header CheckBox
 hello...I have two grid on same page...both grid contains header checkbox and item checkbox i want that if use check header checkbox then all item check box checked,i have javascript for this functinality but problem is that when i click on header check box of first grid then checkbox of second grid also checked that i dnt want i want to perform this operation on one grid at one time.i have attache my script also...plz help me....thanks<script type="text/javascript">        function SelectAll(ID)      &nbs...

Check One CheckBox To Check All CheckBoxes
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked. I set the AutoPostBack property of the CheckBox in the Header to True & am invoking a sub named CheckAllRows on the CheckedChanged event of this CheckBox. The CheckBox in the Header exists within the HeaderTemplate of a TemplateColumn in the DataGrid & the rest of the CheckBoxes reside within the ItemTemplate of the same TemplateColumn. This is the code (the ID of the CheckBox in the Header...

Check out/check in
Hello How can i use the process check out/check in in PowerBuilder 8.0.3 ? We work in network. The Source Control is PB Native. I don't understand what is the parameters of Source Control ? Thank you Better to ask this in the source control group. Lots of posts on PBNative -- Evita Chapa Senior Systems Analyst II Command Technologies Inc. <Herv� Bareth> wrote in message news:3f69678e.7b3a.846930886@sybase.com... > Hello > > How can i use the process check out/check in in PowerBuilder > 8.0.3 ? We work in network. The Source Control is PB Native. ...

Check in
Hi all. I am migrating from PB 7.0 to PB 10.5, After migrating my first application i am trying to work on my first window but i'am not able to find out the way to CHECK it OUT. Wher do i can find "check out/check in" functions ?? TIA Mario Parietti What source control are you using? Have you configured it? Right click on your Workspace and check the source control tab to see if you've got it set up. "Mario Parietti" <mparietti@intercad.ch> wrote in message news:451283e0$1@forums-1-dub... > Hi all. > I am migrating from PB...

Check out/check in
Hello How can i use the process check out/check in in PowerBuilder 8.0.3 ? We work in network. The Source Control is PB Native. I don't understand what is the parameters of Source Control ? Thank you Have you looked the PB8 User's guide? Chapter 3 talks about source control. -- Evita Chapa Senior Systems Analyst II Command Technologies Inc. <Herv� Bareth> wrote in message news:3f69ba0a.592b.846930886@sybase.com... > Hello > > How can i use the process check out/check in in PowerBuilder > 8.0.3 ? We work in network. The Source Control is PB Na...

Check-in/Check-out
I'm having some difficulty with powerbuilder's check-in/check-out operation. When I check an object back in, the .pbl the object is being moved from is destroyed. Has anyone else experienced this and is there a fix? Cheers, Tom Thomas F. (Tom) Massey wrote: > > I'm having some difficulty with powerbuilder's check-in/check-out > operation. When I check an object back in, the .pbl the object is > being moved from is destroyed. > > Has anyone else experienced this and is there a fix? > > Cheers, > > Tom The prob...

Checked=Checked
 I am dynamically writing out checkboxes on a page.  I have 2 link buttons on the page that sets a boolean variable to True or False. This boolen is set in Page_PreInit and is used to Select or Deselect all the Checkboxes as they are written out. A Select ALL, Deselect ALL type of thing. At least that is the plan. As the page is being written out I do this for each checkbox and then add it to a table cell control that it added to a table row and on. tc is the table cell.  Dim chkItem As CheckBox = New CheckBox chkItem.ID = "chkRecommend" + drMember("ID")...

Check In/Check out
I am using PowerBuilder 9. The undo check out is right next to the check in. This is a big problem! I so easy to select Undo check out and lose all of your changes. I lost 8 hours of work yesterday because of it. I know I should be more careful. However, there should be a "Are you sure" some where also. PLEASE FIX!!!!!!!!!!!!! -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ This isn't the tech support line, it's an end-user forum. If you want to report a bug, use CaseXpress and either open a case or report a bug ...

Check In Check Out
I have some source code that I need to modify and it was sent to me in a Registered status. Therfore, when I open any object it says " 'object name' is registered but not checked out and therefore can not be overwritten. Open anyway?" Then when I try to check it out, I get "PBNative checkout not allowed for registered objects." How can I get around this? When I look under the "Source" menu, all the items concerning registered are grayed out. TIA Option1:Copy the object(Only) to someother pbl and try . Option2:If You have any SCC Expo...

Not able to un-check or check my checkbox control using Java Script with .aspx
Hello, I am trying to programatticaly un-check a checkbox on my web form using Java script. This is in an asp.net web form. Can someone spot what is wrong here? Below is the web form that can easily be cut and pasted into visual studio in order for you to see what is going on.   <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Sampler._Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script...

if checkbox is checked , then all the checkboxlist should be checked
i have a checkbox list and a checkbox , i want f the checkbox is checked then all the checkboxes in the checkboxlist should be checked as well.   Please suggest , if there is any way out   Thanksneelu gupta Do u want this to be done on the client side or server side? And are these check boxes server controls or html controls??Shravan Addaypally MCP maybe this thread can help.> penny for a thought...

How to check checkbox is checked or not dynamically....
Hai friends.... I am creating checkbox dynamically............ dim check(100) as checkbox dim cell as new tablecell check(i)=new checkbox() is there any short method to check whether non of the checkbox is checked........... Ambrose... Help me......Winners Never QuitQuitters Never Win You could do this to check if check boxes are checked If CheckBox1.Checked Then    Message.Text &= "CheckBox 1 was checked<br/>"  End If  If CheckBox2.Checked Then    Message.Text &= "CheckBox 2 was checked<br/>"  End ...

How to Check if Checkboxes are Checked? ^_~
Hullo,What I'm basically trying to do is see if a checkbox is checked, and if it is, then change the value of a hiddenfield to update a database.  Here's my code:  protected void Rankbox_CheckedChanged(object sender, EventArgs e) { if (Rankbox = checked) { Rank.Value = 1; } else if (Rankbox = unchecked) { Rank.Value = 0; } } My checkbox is named "Rankbox", and the hidden field with information that needs changing is "Rank".  The error Visual Studio is giving me basically says that it hates the if sta...

Web resources about - How to check if CheckBox is check in C# - asp.net.presentation-controls

Checkbox - Wikipedia, the free encyclopedia
In computing , a checkbox ( check box , tickbox , or tick box ) is a graphical user interface element ( widget ) that permits the user to make ...


XYplorer adds flat select tool, timestamping, sticky checkbox selection and improves portable device ...
... them a date previously copied to the clipboard. sc_* - *.doc matches both files beginning sc_ and those with a .doc extension. Sticky checkbox ...

Beware of checkbox marketing!
... able to sell the product at all and the company will go out of business. (sometimes in those exact words) These are the two edges of the checkbox ...

Disable Lion’s Resume Checkbox When Shutting Down [Video How-To]
One of the most annoying features in OS X Lion for me has been the little checkbox on the shutdown dialog box that states, "Reopen windows when ...

A Checkbox On Your Tax Return Helped Kill Public Campaign Funding
You already hate tax season, and as you move wearily through the cold calculations of the 1040 form, you come across a familiar checkbox. It’s ...

Google's Clever Plan to Replace CAPTCHA With a Checkbox
CAPTCHAs are an unfortunate side effect of the internet. They're those irritating collection of numbers and letters morphed into some Surrealist ...

Great news: New EEOC checkbox category emerges
"Bow-tie'n white boys"? Hey, I tried to anticipate the next expansion in ethnic categorization yesterday with my proposal for recognition of ...

Checkbox Syndrome: Why We Spend Money on Things We Don't Need
Ever been overwhelmed by the temptation to buy the latest shiny thing because it's got another checkbox in the features column? We call this ...

Magid: Google ditching CAPTCHA for 'I'm not a robot' checkbox
We need better security, but we need to find systems that are hard for bad guys to break but easy for good folks to use. Google is one of the ...

Resources last updated: 1/6/2016 7:35:04 AM