Solved

Problem with 2 ListView Controls on .aspx

Posted on 2011-02-25
3
459 Views
Last Modified: 2012-06-27
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

0
Comment
Question by:jazzcatone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 28

Accepted Solution

by:
strickdd earned 500 total points
ID: 34982248
More often than not, this is caused by setting the .Checked property of the checkboxes in the code-behind during a postback. What you want to do is make sure you check:

if(!Page.IsPostBack)
{
    PopulateMyControls();
}
0
 
LVL 6

Expert Comment

by:ksrsrinivasan
ID: 34985762
Make sure you have EnableViewState = "true" on the second ListView
0
 

Author Comment

by:jazzcatone
ID: 34991677
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..
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question