?
Solved

getting value of a label in a repeater

Posted on 2013-02-05
6
Medium Priority
?
665 Views
Last Modified: 2013-02-10
i have a datarepeater in a win form using C# and I am trying to get the value of a label in the repeater but it keeps comming up as label3 on messagebox.show why wont it give me the value?
        private void ButtonRepeater()
        {
            if (DesignMode == false)
            {
                string sqlStr = "";
                string sqlCon = ConfigurationManager.ConnectionStrings["conn1"].ToString();
                sqlStr += " SELECT  id, TaskUID, Factory, ItemNumber, ItemName, ExFactoryDate, Customer, ReportDate, InspectorName, BatchCode, OverallResultChina, OverallResultDallas, ";
                sqlStr += " IsDupro, IsFinalRandomInsp, IsTestSamplePull, Uploaded, Downloaded, PDS_CC, WorkmanShip, OnSiteTest, BarcodeVer, Packaging, Packing, Lbl_Print_Mrkg, ";
                sqlStr += " ShipRemarks, IsCOmplete "; 
                sqlStr += " FROM         Inspection ";
                sqlStr += " WHERE     (IsCOmplete IS NULL) ";
                using(SqlConnection conn = new SqlConnection(sqlCon))
                using(SqlCommand cmd = new SqlCommand(sqlStr,conn))
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.Connection.Open();
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    BindingSource bindingSource1 = new BindingSource();
                    bindingSource1.DataSource = dt;
                    radLabel2.Text = "QC Inspection";
                    radLabel3.DataBindings.Add("Text", bindingSource1, "TaskUID");
                    radLabel4.DataBindings.Add("Text", bindingSource1, "Factory");
                    dataRepeater1.DataSource = bindingSource1;
                    
                }
            }
        }

Open in new window


        private void dataRepeater1_ItemTemplate_Click(object sender, EventArgs e)
        {
            MessageBox.Show(Convert.ToString(radLabel3.Text));
        }

Open in new window

0
Comment
Question by:r3nder
[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
  • 5
6 Comments
 
LVL 20

Assisted Solution

by:Daniel Van Der Werken
Daniel Van Der Werken earned 1500 total points
ID: 38854939
You have to do a FindControl() on the repeater.

Something like this, in the event:

        private void dataRepeater1_ItemTemplate_Click(object sender, EventArgs e)
        {
            Label radLabel = (Label)sender.FindControl("radLabel3");
            MessageBox.Show(Convert.ToString(radLabel.Text));
        }

Open in new window


Actually, I'm not sure what your HTML looks like, so I can't tell for sure. Basically, with repeaters and datagrids and such, you have to call FindControl on the repeater item or whatever object is being passed into the event that is of type repeater-something.

Make sense?
0
 
LVL 6

Author Comment

by:r3nder
ID: 38854996
I have no HTML - this is winform
0
 
LVL 6

Author Comment

by:r3nder
ID: 38855041
FindControl does not exist in this context :(
0
RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

 
LVL 6

Accepted Solution

by:
r3nder earned 0 total points
ID: 38855555
here is what i have - I need the value of radlabel3 of the clicked index
        private void dataRepeater1_ItemTemplate_Click(object sender, EventArgs e)
        {
            string index = Convert.ToString(dataRepeater1.CurrentItemIndex); <-- I can get the index
            
                RadLabel radLabel = this.Controls.Find("radLabel3", true).FirstOrDefault() as RadLabel; <--- but the label text is always the first indexes radlabel3
            
           
            MessageBox.Show(Convert.ToString(radLabel.Text));
        }

Open in new window

0
 
LVL 6

Author Comment

by:r3nder
ID: 38855820
got it
task = dataRepeater1.CurrentItem.Controls["radLabel3"].Text;
0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 38872777
pointed me in the right direction - thanks
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Starting up a Project

718 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