Solved

getting value of a label in a repeater

Posted on 2013-02-05
6
649 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 500 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
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

 
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

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VS C# how to design libary of functions 7 33
SQL State HYT00. Timeout expired proplem 8 44
.NET universe documentation poster 2 25
CSS styling problem 3 28
A short article about problems I had with the new location API and permissions in Marshmallow
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

752 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