Check Box List Selected Value Issue

i am trying to get the selected value of a check box list and insert that into a sql statement. no big deal right? lol wrong....i'm dong this in the selectedindexchanged event of the check box list. the first part of the code is just there a tester so i can check and see if the count is being added correctly and if the anythign is getting passed. however the items.count shows correctly but the cklstManagers.Items[i].Selected shows false and i can't get it to show anything but null

here is code:

for (int i = 0; i < CklstManagers.Items.Count; i++)
        {
            if (CklstManagers.Items[i].Selected)
            {
                listbox1.Items.Add(CklstManagers.Items[i].Value);
            }
        }  
       
        string MyConString2 = "SERVER=xxxx;" + "DATABASE=xxxx;" + "UID=xxxx;" + "PASSWORD=xxxx;";
        MySqlConnection connection2 = new MySqlConnection(MyConString2);
        string strQuery = "update mgrenrollment set AdminAccess = '1' where lastname = '" + CklstManagers.SelectedValue.ToString() + "'";
        MySqlCommand command2 = new MySqlCommand(strQuery);                 
     connection2.Open();
        command2.Connection = connection2; 
     command2.ExecuteNonQuery();
     command2.Dispose();
     connection2.Close();

any ideas and/or reply's are greatly appreicated!!!

0
baytes
6/9/2008 7:58:08 PM
asp.net.web-forms 93655 articles. 2 followers. Follow

9 Replies
183 Views

Similar Articles

[PageSpeed] 42

for (int i = 0; i < CklstManagers.Items.Count-1; i++) should be used in place of for (int i = 0; i < CklstManagers.Items.Count; i++)

because i starts from zero, but the count starts from 1.

 for (int i = 0; i < CklstManagers.Items.Count-1; i++)

{
            if (CklstManagers.Items[i].Selected)
            {
             
        
        string MyConString2 = "SERVER=xxxx;" + "DATABASE=xxxx;" + "UID=xxxx;" + "PASSWORD=xxxx;";
        MySqlConnection connection2 = new MySqlConnection(MyConString2);
        string strQuery = "update mgrenrollment set AdminAccess = '1' where lastname = '" + CklstManagers.SelectedValue.ToString() + "'";
        MySqlCommand command2 = new MySqlCommand(strQuery);                 
     connection2.Open();
        command2.Connection = connection2; 
     command2.ExecuteNonQuery();
     command2.Dispose();

}

}

0
sreenathp143
6/9/2008 8:22:11 PM

thanks for your reply......but it does the same thing as the example i posted. it sets the count to 2 (like its suppost to) but skips the mysql stuff and cklstManagers.SelectedValue.ToString() still is null. any other suggesttions??

0
baytes
6/9/2008 10:34:18 PM

for (int i = 0; i < CklstManagers.Items.Count-1; i++)

{
            if (CklstManagers.Items[i].Selected)
            {string item=CklstManagers.items[i].value;
             
        
        string MyConString2 = "SERVER=xxxx;" + "DATABASE=xxxx;" + "UID=xxxx;" + "PASSWORD=xxxx;";
        MySqlConnection connection2 = new MySqlConnection(MyConString2);
        string strQuery = "update mgrenrollment set AdminAccess = '1' where lastname = '" + item + "'";
        MySqlCommand command2 = new MySqlCommand(strQuery);                 
     connection2.Open();
        command2.Connection = connection2; 
     command2.ExecuteNonQuery();
     command2.Dispose();

}

}

this is working for me. try this

0
sreenathp143
6/10/2008 1:12:26 AM
Thanks! yes this works however when i put a breakpoint on line 

if (CklstManagers.Items[i].Selected) and hover over .Selected it's still set to false and the checked box isn't being passed it always has the first check box listed in the output even if i check the second or third and it still skips the mysql stuff and never executes it.

0
baytes
6/10/2008 11:29:17 AM

if it had worked , plz mark as answer

0
sreenathp143
6/10/2008 1:20:09 PM

i mean it works in the sense that it lists the first item in the collection but it doesnt work becuase its still showing the nothing is selected

 

breakpoint-

if (CklstManagers.Items[i].Selected) and hover over .Selected it's still set to false and the checked box isn't being passed it always has the first check box listed in the output even if i check the second or third and it still skips the mysql stuff and never executes it.

 

so its not the answer

0
baytes
6/10/2008 1:23:15 PM
for (int i = 0; i < CheckBoxList1.Items.Count; i++) 

{

if (CheckBoxList1.Items[i].Selected)

{

string aa = CheckBoxList1.Items[i].Value ;

  string MyConString2 = "SERVER=xxxx;" + "DATABASE=xxxx;" + "UID=xxxx;" + "PASSWORD=xxxx;";
        MySqlConnection connection2 = new MySqlConnection(MyConString2);
        string strQuery = "update mgrenrollment set AdminAccess = '1' where lastname = '" + aa+ "'";
        MySqlCommand command2 = new MySqlCommand(strQuery);                 
     connection2.Open();
        command2.Connection = connection2; 
     command2.ExecuteNonQuery();
     command2.Dispose();

connection2.Close();

}

}

 

this is working for me. i dont know why its not working for u.....

 

0
sreenathp143
6/10/2008 1:34:11 PM

me either this should work. but for some reason it wont get the "selected" value of the check box list. every time it gets ran it shows that there is nothing selected. it prints the first item collection in the debug window but doesn't show the names of the other items and also says that .selected is = to false. gotta be a bug or something. thanks for all your help though. i'll as answer. as this technically should be it. thanks agian!

0
baytes
6/10/2008 1:42:15 PM

mark as answer if it is

0
sreenathp143
6/10/2008 2:02:51 PM
Reply:

Similar Artilces:

Load Text box of one web form with selected list item of list box of another web form
one help please Problem is i have two web forms  1.  ForiegnkeyTest.aspx  2. foroginkeytable.aspx   step 1 1 ForiegnkeyTest.aspx one web form <head runat="server"><script language="javascript" type="text/javascript">   function popWin()   {         var confirmWin = null;      confirmWin = window.open('foroginkeytable.aspx','anycontent',   'width=455,height=435,status');   }  </script> &...

problem with selected text field and selected value field in check box list
Hi! i have a  problem with check box list:here is the code for binding the check box list with sqldatasource  SqlDataSource1.SelectCommand = "select vcentrolno,inttpaperno from tabmarksdetails where vcbunchno='" & strBunchNo & "'"  chkEnrolNos.DataBind()say now my chkEnrolNos consist of data in this way:vcentrolno        inttpaperno selected text   selected valueA11439            1A11439            2AR439    ...

Problem in selecting text in List box Web Form
hi In List box load the data from database. If i am select any Item from list box i am geting selected Indexvalue ="-1" at the same time i am not get the text value. how can i get the selected index text value. Regards, Sabarish. Hi, it sounds to me that you're rebinding your data upon every postback. If you're doing it in code behind place it between if(!Page.IsPostBack) to avoid this. Then you should be able to get a value different than -1 (which means nothing's selected). Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Workaround for...

Populate 2nd drop-down list box based on selected values in 1st drop-down list box
Hi Group,I have two DDL boxes on my page.  DDL one has a list of values and a code.e.g code  ValueABC   123ABC   345FGH   123 DDL 2 should only show values for the code selected in  DDL1 e.g  if user selects record 1 with code ABCthen DDL2 should show ALL records with the linked field value of ABC.The tables are normalized.  For your info, the name of the field of the value I would like to check is called sublistcode.Using vb.net  TIA         Try this code: Note: Set appenddataboun...

Web-Forms: Check-Box List Doesn't Work?
When my page is posted back all the items in my check-box list are incorrectly set to true, but some should be false because they display with and without the checkmark in the browser, just as the user wants. Programmatically the checkboxes initialize correctly but everything always comes back true. I'm using VB and ASP.net (see below). Am I doing something wrong, or is there really a bug in something so fundmental?Three functions, INVERT, CLEAR, and PROCESS depend on this check-box list working correctly. They all work incorrectly in the same wrong manner. I've included only INVERT bel...

selecting multiple values in a list box using vb.net code
Hi, I have a list box with certain values. The SelectionMode property of List box is set to Multiple. I want to select multiple items based on the values of the items in the Listbox using the vb.net code. Can any one please help.Thanks eg: for i = 0 to listbox.items.count - 1 if listbox.items(i).selected then Response.Write("Selected") else Response.Write("Selection Needed") end if next refer links: http://www.411asp.net/func/content?tree=411asp/tutorial/specific/web/userinte/webcontr...

how to make one list box(this list box should have selected products) gets filled from another list box (for example this list box has the whole products) by using navigation control
Hello Mate!, I have two list boxes. one should get populated with whole products. and i have another list box in which i have to move some of the products which i like .   The design should be the one below: List Box1   List Box 2 all products   Selected products BMW    >> BMW BENZ     > LEXUS AUDI     <   LEXUS    <<     Could you please suggest me whether i have to use buttons(by which i move items from one list box to another)  ...

Text box check value from List box.
Hi, I have create asimple function but it is not working correctly. I have 1 textbox, 1 Button, 1 Label and 1 Listbox. I have entered the static name in the listbox. Now I want to check these names through entering names in textbox.protected void btnSubmit_Click(object sender, EventArgs e) {for (int a = 0 ; a < ListBox1.Items.Count ; a++) {if (txtName.Text == ListBox1.Items[a].Text){ lblSubmit.Text = "Your Answer is Correct"; } else {lblSubmit.Text = "Please try again"; }   } } And all the time I found "Please Try again". I want when i e...

Check box list into List box
Hi I am using VB.NET, I have a check box list called chk_bx_1, every time something is selected in this list I want it to autmatically appear in a list_box or I would like to select all the items in the checkbox list first then by pressing a button get all the selected utems to appear in the list box. Can someone PLEASE help!!!...

How do you pre-select values in a multiple selection list box
Let's say I have a list box like so, this is already rendered: <select name="names" size="3" multiple="multiple" id="names1" > <option value="0">John</option> <option value="1">Mike</option> <option selected="2">Bill</option> </select> how could I pre-selecte two names on load, if I say names1.selectedvalue = "1" it pre-selects Mike cool but if I say names1.selectedvalue = "1,2" then I get an exception. Is there a way ...

Dropdownlist selected value passes first value in list no matter what value is selected. why ?
 HI . I have a dropdownlist. Databinds ok but when I must pass a value as a Selected value it always passes the first value in the list even if I select another value. I tried to set the ddl to enableviewstate false but it doesn't change anything. Any ideas ? Code below, thanksLoading the ddl:       productCategories = CatalogAdmin.Admin_Product_Categories_NotIn(productId);        for (int i = 0; i < productCategories.Rows.Count; i++)        {       &...

Default "Checked" Values in a Check Box List after Databind
I am new to using a DataConnection to bind data to controls - I'm from the old days of doing everything in code.  So, to do this my way is, I would consider, very simple.  But since I am unfamiliar with the new methods using DAL and whatnot, I don't know how to do something very easy.I have a checkbox list.  I am using a SqlDataSource and autopopulating this list within a Wizard(A WizardStep).  The checkboxlist is populating very easily and I am so far pleased with this method of doing things.  But I want all boxes checked by default, and I don't see a way to do that...

Validation when moving values from list box to list box.
 I have two list boxes on a page, one of which is populated based off a drop down. I can move values from the left listbox to the right, and from the right to the left. The issue I'm having is that it's possible to get the same value into the list boxes twice. For example, if I populate the left listbox from the drop down list, move all the values to the right listbox, and then change the drop down list to another value, then change it back to the original value, the left listbox populates with the same values that are already in the right listbox. I can then move values from th...

Check Box selection form
I  retrieve Work-Breakdown-Structure data from a database table, there are over 600 items, at four different levels, the user needs to select items from the third or the fourth (if fourth is available) levels.  I need to add a check box next to each item to include or not include in a results page.  How do you add a selection box next to retrieved items and it would recognize that item, and inturn display it in a conformation or results page?   Thank you...

Web resources about - Check Box List Selected Value Issue - asp.net.web-forms

Portal:Bollywood/Selected biography - Wikipedia, the free encyclopedia
Write three or four paragraphs in the text field using information from the selected notable article, you may find it useful to examine the existing ...

F8: Facebook’s FbStart Initiative Will Give Selected Developers A $30K Kick-Start
... successful applications is likely a whole lot easier with $30,000 in free tools and services to start off with, and that’s exactly what selected ...

LEGO Shop - The LEGO Technic team has selected the winner... - Facebook
The LEGO Technic team has selected the winner of the Co-Creation Challenge! LEGO will be producing a limited run of 20,000 of this stunning set.... ...

Grand Doctor Ma Selected Students-baby365 on the App Store on iTunes
Get Grand Doctor Ma Selected Students-baby365 on the App Store. See screenshots and ratings, and read customer reviews.

Selected Cheney Vice Presidential Photographs
... for photos found within these albums are Paul Morse, Karen Ballard, Kimberlee Hewitt, Shealah Craighead, and Chris Greenberg. These selected ...

[iOS Advice] How To Clarify Your Email Replies By Quoting Selected Text - YouTube
Follow me on Twitter: http://www.twitter.com/macmixing Like my Facebook page: http://www.facebook.com/macmixing RATE, COMMENT, SUBSCRIBE! :-) ...

UAE Under-19 cricketers for ACC Premier League tour of Malaysia selected - The National
Coach Aaqib Javed seeking fresh blood for senior team after missing out on World Twenty20

Animal of the Day: Lucius Has Been Selected as the U.K.’s ‘Happiest Cat’
He’s got one blue eye, one green eye and a heart of gold. British mobile phone company O2 recently held some “cat auditions” to find “the UK’s ...

Boyd Cordner selected for Kangaroos squad
Sydney Roosters stars Michael Jennings and Boyd Cordner have capped a grand-final win with selection in the Australian squad for the World Cup ...

Redlands LNP branch blood-letting after Matt McEachan pre-selected
There was more blood-letting in the seat of Redlands on the weekend when a motorcycle instructor was named LNP candidate for the embattled electorate ...

Resources last updated: 12/1/2015 9:37:15 AM