Link to home
Start Free TrialLog in
Avatar of Jason Livengood
Jason LivengoodFlag for United States of America

asked on

Problem with 2 ListView Controls on .aspx

OK this is driving me nuts. I have a .aspx page with 2 ListView Controls (ListViewA and ListViewB) on it. Both Listview controls have a Checkbox in it. If the user decides some action need to be taken on a record, they will check the checkbox for that particular record and then click a button at the bottom of the page.

The button click event itterates through the records in both ListViews and checks to see if the checkbox is checked. If so,
it will execute some code on that record. So I have two FOREACH statements to do this. 1 for each ListView

Problem: The test to see if the checkbox is checked on ListViewB always evaluates as FALSE. So no processing occurrs.

I stepped through the code and I can see that this is what is happening. Checkbox is checked...I swear. I have done all kinds of things to try to remedy this or figure out what the deal is. I tried switching the order of them in the .aspx markup, I tried changing the order of the ForEach statements, renaming he checkbox controls, and removing an AJAX Update panel that is on the .aspx page. None of this seems to matter. If anybody has any suggestions as to why this maybe happening it would be greatly appreciated. Code is below.

Jason
protected void AddRowstoInvoiceList()
        {

           //Loop Through ListView A This Works Fine !!
            foreach (ListViewDataItem lvi in BillListView.Items)
            {
                // Find the checkbox in each row
                CheckBox chkSelect = (CheckBox)lvi.FindControl("Chbxbill");

                // If the checkbox is checked then add the corresponding ID to our private InvoiceList


                // Get the CheckedID from the datakeynames property
                Int64 ID = Convert.ToInt64(BillListView.DataKeys[lvi.DisplayIndex].Value);
                //purge the list of any checked studies that are currently in the list, don't want studies to show up twice
                this.InvoiceList.RemoveAll(x => x.Studyid == ID);

     //Here is the test ..this one works as expected...Yay !!!!
                if (chkSelect.Checked == true)
                {
                    InvoicingRecord record = new InvoicingRecord();
                    // Add the ID to our list
                    record.Studyid = ID;

                    //Add Upload date
                    LinkButton ScoreDate = (LinkButton)lvi.FindControl("ScoreDateLBtn");
                    DateTime scrdt;
                    scrdt = Convert.ToDateTime(ScoreDate.Text);
                    record.ScoreDate = scrdt;

                    // Add patient
                    TextBox patlnk = (TextBox)lvi.FindControl("txbxPatient");
                    record.patient = patlnk.Text;

                    //Add item price 
                    TextBox pricebx = (TextBox)lvi.FindControl("txbxItemPrice");
                    decimal price = Convert.ToDecimal(pricebx.Text);
                    record.ItemPrice = price;

                    // Add the Notes

                    TextBox txtnote = (TextBox)lvi.FindControl("txbxNote");
                    record.note = txtnote.Text;

                    //Add the companyID

                    TextBox txttechid = (TextBox)lvi.FindControl("txbxTechId");
                    Guid g = new Guid(txttechid.Text);
                    record.techid_i = g;


                    //Add the InvoiceRecord to the list
                    this.InvoiceList.Add(record);

                }

            }


            // Loop Through TechTouchedListView The test for theckbox always evaluates to False...WHY ??
            foreach (ListViewDataItem rec in TechTouchedListView.Items)
            {
                // Find the checkbox in each row, it does infact find it when I step through the code
                CheckBox chkXXXX = (CheckBox)rec.FindControl("TechTouchedChbxbill");

                // If the checkbox is checked then add the corresponding ID to our private InvoiceList


                // Get the CheckedID from the datakeynames property
                Int64 ID = Convert.ToInt64(TechTouchedListView.DataKeys[rec.DisplayIndex].Value);
                //purge the list of any checked studies that are currently in the list, don't want studies to show up twice
                this.InvoiceList.RemoveAll(x => x.Studyid == ID);
//Here is the test ..this one always comes back as FALSE..I HAVE NO IDEA WHY.. What could cause this ??
                if (chkXXXX.Checked == true)
                {
                    InvoicingRecord record = new InvoicingRecord();
                    // Add the ID to our list
                    record.Studyid = ID;

                    //Add Upload date
                    LinkButton ScoreDate = (LinkButton)rec.FindControl("TechTouchedScoreDateLBtn");
                    DateTime scrdt;
                    scrdt = Convert.ToDateTime(ScoreDate.Text);
                    record.ScoreDate = scrdt;

                    // Add patient
                    TextBox patlnk = (TextBox)rec.FindControl("TechTouchedtxbxPatient");
                    record.patient = patlnk.Text;

                    //Add item price 
                    TextBox pricebx = (TextBox)rec.FindControl("TechTouchedtxbxItemPrice");
                    decimal price = Convert.ToDecimal(pricebx.Text);
                    record.ItemPrice = price;

                    // Add the Notes

                    TextBox txtnote = (TextBox)rec.FindControl("TechTouchedtxbxNote");
                    record.note = txtnote.Text;

                    //Add the companyID

                    TextBox txttechid = (TextBox)rec.FindControl("TechTouchedtxbxTechId");
                    Guid g = new Guid(txttechid.Text);
                    record.techid_i = g;


                    //Add the InvoiceRecord to the list
                    this.InvoiceList.Add(record);

                }

            }

     }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of strickdd
strickdd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Make sure you have EnableViewState = "true" on the second ListView
Avatar of Jason Livengood

ASKER

I had another control on the page. When the control reloaded (on control load) due to a postback (like strickdd said) oat was causing the second list view was reloading. This is essentially what was causing it..