Solved

getting value of a label in a repeater

Posted on 2013-02-05
6
630 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
  • 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now