Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8926671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:01:40+00:00 2026-06-15T08:01:40+00:00

I am new to this c# coding. I am trying to write a code

  • 0

I am new to this c# coding.
I am trying to write a code using checkboxes. Below is code in design flow

<table>
    <tr>
        <td align="right">
            <asp:Label ID="lblOwn" runat="server" Text="Owned by You :"></asp:Label>
        </td>
        <td align="left">
            <asp:CheckBoxList ID="chbxOwn" runat="server"
                OnSelectedIndexChanged="onAckTypeChanged3" AutoPostBack="true">
                <asp:ListItem>2 wheeler</asp:ListItem>
                <asp:ListItem>4 wheeler</asp:ListItem>
            </asp:CheckBoxList>
        </td>
    </tr>
    <tr>
        <td align="right">
            <asp:Label ID="Label1" runat="server" Text="2 w"></asp:Label>
        </td>
    </tr>
    <tr>
        <td align="right">
            <asp:Label ID="Label2" runat="server" Text="4 w"></asp:Label>
        </td>
    </tr>
</table>

And following is codebehind

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Hid1();
        Hid2();
    }
    protected void onAckTypeChanged3(object sender, EventArgs e)
    {
        if (chbxOwn.SelectedItem.Text == "2 wheeler")
        {
            Vis1();
        }
        if (chbxOwn.SelectedItem.Text == "4 wheeler")
        {
           Vis2();
        }
    }
    private void Hid1()
    {
        Label1.Visible = false;
    }
    private void Hid2()
    {
        Label2.Visible = false;
    }
    private void  Vis1()
    {
        Label1.Visible = true;
    }
    private void Vis2()
    {
        Label2.Visible = true;
    }
}

When “2 wheeler” checkbox is checked “2 w” label is visible. But when i check “4 wheeler” it doesnot shows both the labels. i want to know where i am making a mistake. Also when i de-select both the checkboxes there is an Null reference exception generated.

can you please help me out with these problems
1. Checking both the checkbox should display both the labels.
2. De-selecting should not produce null reference exception.

Thanks in advance
Regards,
Abhishek

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:01:42+00:00Added an answer on June 15, 2026 at 8:01 am

    This is what you want:

    protected void onAckTypeChanged3(object sender, EventArgs e)
    {
        foreach (ListItem item in chbxOwn.Items)
        {
            if (item.Text == "2 wheeler" && item.Selected)
            {
                Vis1();
            }
            if (item.Text == "4 wheeler" && item.Selected)
            {
                Vis2();
            }
        }
    }
    

    It works like a charm..!!

    Here is the working demo: DEMO

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to coding python. I am hoping to modify this code to
Am relatively new to C# and coding in general. I am trying to write
I am new to Javascript coding and have looked for this information in many
Im very new to all coding including jquery. I though this would have been
So, I'm still new with the php coding, still learning, etc. So, if this
New to this library (no more familiar with BeautifulSoup either, sadly), trying to do
Im new on this project and am going to write, what i thought was
I am trying to write a program that reads in binary files using C++.
I am currently trying to write some code which is going to send a
I often want to write something like this: new Form { Text = Caption,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.