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 9126385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:01:47+00:00 2026-06-17T07:01:47+00:00

i am adding multiple checkboxes in my asp.net page by doing this: public static

  • 0

i am adding multiple checkboxes in my asp.net page by doing this:

 public static CheckBox[] chck;

on pageload:

 protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
      con.Open();
        SqlCommand cmd = new SqlCommand("select count(CompanyName) from Stock_Company");
        cmd.Connection = con;
        comno = Convert.ToInt32(cmd.ExecuteScalar());
         con.Close();

        chck = new CheckBox[comno];
    }
 }

now i have a function which is generating the checkboxes :

   public void generatecheckbox1()
{

    con.Open();
    SqlCommand cmd = new SqlCommand("select CompanyName from Stock_Company");
    cmd.Connection = con;
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds);
    DataTable dt = ds.Tables[0];
    con.Close();
    for (int i = 0; i < dt.Rows.Count; i++)
    {
        chck[i] = new CheckBox();
        chck[i].ID = "chck" + Convert.ToString(i);
        chck[i].Text = dt.Rows[i]["CompanyName"].ToString();
        pnlcom1.Controls.Add(chck[i]);
        pnlcom1.Controls.Add(new LiteralControl("<br />"));
    }
  }

and i am calling this on a combobox event:

 protected void ddluserwebser_SelectedIndexChanged(object sender, EventArgs e)
{
    if (ddluserwebser.SelectedItem.Text == "Custom")
    {
        generatecheckbox1();
    }
 }

as far as this all are working fine … but in a button click i want to get the select checkbox’s text which i am not getting

i made a function :

   public string getbsecompany()
{
    string companyname = "";
    string bsetricker = "";
    con.Open();
    SqlCommand cmd = new SqlCommand("select CompanyName from Stock_Company");
    cmd.Connection = con;
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds);
    DataTable dt = ds.Tables[0];
    con.Close();
    for (int i = 0; i < dt.Rows.Count; i++)
    {
        if (chck[i].Checked == true)     **THE PROBLEM IS HERE**
        {
            companyname = chck[i].Text;
            con.Open();
            SqlCommand cmdd = new SqlCommand("select BSETickerCode from Stock_Company where CompanyName='" + companyname + "'");
            cmdd.Connection = con;
            bsetricker += bsetricker + "+" + cmdd.ExecuteScalar();
            con.Close();
        }
    }

    return bsetricker;
}

and i am calling it here:

  protected void btnusersave_Click(object sender, EventArgs e)
{
    string bsetricker = "";
    bsetricker = getbsecompany();
}

the problem is i am not getting the checked box’s text. when i am checking if (chck[i].Checked == true) i am gettin false and all checkboxes are checked.
What should i do now?
any help

  • 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-17T07:01:49+00:00Added an answer on June 17, 2026 at 7:01 am

    The dynamic controls should added to page in On_Init() for each time if you want it display in page.
    Else there’s nothing you can get.
    Plus, better not use a static value to contains checkBox List, it will cause problem when multi user access same page. You can save them in session or try this.Form.FindControls()

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

Sidebar

Related Questions

I am reading this tutorial : http://sleekd.com/general/adding-multiple-images-to-a-rails-model-with-paperclip/ because i need Save the product images
I am working on a multi-purpose page and rather than adding multiple grids to
I have a html form for adding multiple addresses: http://i48.tinypic.com/jg2ruo.png This way If I
Let's say customer is adding multiple products to cart. Add car, apartment, tour, some
I have written a code for adding multiple keys for a dictionary for that
I'm having a problem with the new google maps api when adding multiple markers
for an li tag i am adding a div with multiple div dynamically like
I want to get all the file upload controls on my page, Im adding
I have 5 checkboxes and I have to select multiple checkboxes. I made a
I have a form with multiple checkboxes, which I want to put into an

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.