Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6195871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:32:41+00:00 2026-05-24T03:32:41+00:00

I have the following function: public void rpSearchResults_ItemDataBound(Object Sender, RepeaterItemEventArgs e) { if (e.Item.ItemType

  • 0

I have the following function:

public void rpSearchResults_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        System.Data.Common.DbDataRecord rd = (System.Data.Common.DbDataRecord)e.Item.DataItem;

        Literal litCompanyName = (Literal)e.Item.FindControl("litCompanyName");
        Literal litCompanyLocation = (Literal)e.Item.FindControl("litCompanyLocation");
        Literal litCompanyActivity = (Literal)e.Item.FindControl("litCompanyActivity");
        HiddenField hdnUserID = (HiddenField)e.Item.FindControl("hdnUserID");
        HyperLink lnkEmail = (HyperLink)e.Item.FindControl("lnkEmail");
        HyperLink lnkMicrosite = (HyperLink)e.Item.FindControl("lnkMicrosite");
        Literal litRecommends = (Literal)e.Item.FindControl("litRecommends");

        litCompanyName.Text = rd["CompanyName"].ToString();

        // Construct location info
        litCompanyLocation.Text = "";
        string[] addressParts = {"City","Region","Postcode"};
        bool prior = false;
        foreach (String part in addressParts){
            if (prior) litCompanyLocation.Text = litCompanyLocation.Text + ", ";

            string addressBit = rd[part].ToString();
            if (addressBit == null || addressBit.Trim() == "") prior = false;
            else
            {
                litCompanyLocation.Text = litCompanyLocation.Text + rd[part].ToString();
                prior = true;
            }
        }

        // ... and so on, mapping stuff from the database to fields.
    }
}

It is fired by an event on my Repeater, and is used to populate a list of search results. All the various controls being found are present in the Item Template for the repeater.

This all works, but I hate having to do it like this. I hate having to search for a control by string, and I hate having to do casts to get the controls into a state I can manipulate. If anything goes wrong – for instance, if I make a typo – the error is only picked up at runtime, and it can often be quite difficult to track down, as these functions seem to fail silently, rather than creating a big noticeable error page.

This code is written now, and it works. But in the future I’d like to write it in a different way that is strongly typed, so that any errors will make themselves known at compile time. Is there any way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:32:42+00:00Added an answer on May 24, 2026 at 3:32 am

    You can put all your controls into a strongly-typed custom control (including ASCX user controls) and only have to use FindControl() once:

    CustomControl myControl= (CustomControl) e.Item.FindControl("oMyControl");
    
    myControl.litCompanyName.Text = rd["CompanyName"].ToString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following two routines in Flash Builder: public function getData():void { httpService
Let's say we have the following method declaration: Public Function MyMethod(ByVal param1 As Integer,
I have the following function that is pulling data from a database. The ajax
I have the following intentionally trivial function: void ReplaceSome(ref string text) { StringBuilder sb
I have the following serialization method: Private Function SerializeData(ByVal data As cData) As String
I have the following function: CREATE FUNCTION fGetTransactionStatusLog ( @TransactionID int ) RETURNS varchar(8000)
So: I have the following function, adapted from a formula found online, which takes
Let's say I have the following function: sumAll :: [(Int,Int)] -> Int sumAll xs
I have the following Oracle function: function get_job_no return number is V_job_no number; begin
Say I have the following code: function One() {} One.prototype.x = undefined; function Two()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.