Solved

Problem with 2 ListView Controls on .aspx

Posted on 2011-02-25
3
460 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

710 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