Solved

getting value of a label in a repeater

Posted on 2013-02-05
6
625 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 19

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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 …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

757 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

21 Experts available now in Live!

Get 1:1 Help Now