Results 1 to 5 of 5

Thread: [RESOLVED] Problem With CheckBoxList in uncheck

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2010
    Posts
    313

    Resolved [RESOLVED] Problem With CheckBoxList in uncheck

    Hi, I have a problem I do not find resolve the matter simply, when the user chooses the item from the list add value to the textbox
    When I want to cancel the selection subtract the value of the textbox,
    When the selection was canceled I want to know the item that was nullified CheckBoxList.SelectedValue use but do not work


    Code:
           if (CheckBoxList.SelectedIndex > -1)   
          {   
             Response.Write("Checked");
             cnn.Open();
             string cmdString = "select * from [merit] where [System_Name] = '" + DropDownList5.SelectedValue + "' and [Merit] = '" + CheckBoxList.SelectedValue + "'";
             SqlCommand cmd = new SqlCommand(cmdString, cnn);
             SqlDataReader dr1 = cmd.ExecuteReader();
             while (dr1.Read())
             {
                 int A;
                 int B;
                 int Z;
                 A = Convert.ToInt32(TextBox1.Text);
                 B = dr1.GetInt32(3);
                 Z = A + B;
                 TextBox1.Text = Z.ToString();
             }
             cnn.Close();
          }   
    
          else  
    
          {   
                       cnn.Open();
             string cmdString = "select * from [merit] where [System_Name] = '" + DropDownList5.SelectedValue + "' and [Merit] = '" + CheckBoxList.SelectedValue + "'";
             SqlCommand cmd = new SqlCommand(cmdString, cnn);
             SqlDataReader dr1 = cmd.ExecuteReader();
             while (dr1.Read())
             {
                 int A;
                 int B;
                 int Z;
                 A = Convert.ToInt32(TextBox1.Text);
                 B = dr1.GetInt32(3);
                 Z = A - B;
                 TextBox1.Text = Z.ToString();
             }
             cnn.Close();
               
           }

    thanks in advane
    with my regards

  2. #2
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: Problem With CheckBoxList in uncheck

    hay,

    you need to loop through the selected items into the checkboxlist object


    Code:
            foreach (ListItem item in CheckBoxList1.Items)
            {
                if (item.Selected == true)
                {
                    string str = item.Value;
                    // and here do the things you want to do
                }
            }
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Problem With CheckBoxList in uncheck

    waleed_89,

    You really shouldn't use Response.Write directly. There are a couple places where using this is applicable, but in your case it really isn't. Instead, in your case, add a label to the page, and set the Text property of the label to the string that you are trying to write out.

    Also, you really should be using Parameterized Queries, not concatenating your SQL String like you are. Take a look at the link in my signature regarding always use parameters.

    Also, you seem to be executing the exact same query within both the if and the else, so why do it twice. Only do it once, and then take the appropriate action.

    Gary

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2010
    Posts
    313

    Re: Problem With CheckBoxList in uncheck

    thanks for attention, i try more then solution but not found solution work good without problems, used listbox and button.

    thanks again

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] Problem With CheckBoxList in uncheck

    Ah, ok, that works I guess.

    If you want to continue down that route, you might want to post the code that you tried, and we might be able to help you out.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width