|
-
Sep 23rd, 2010, 05:06 PM
#1
Thread Starter
Hyperactive Member
[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
-
Sep 24th, 2010, 02:13 AM
#2
Frenzied Member
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 
-
Sep 24th, 2010, 04:52 AM
#3
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
-
Sep 24th, 2010, 08:57 AM
#4
Thread Starter
Hyperactive Member
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
-
Sep 24th, 2010, 09:07 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|