Link to home
Start Free TrialLog in
Avatar of Graham_Forbes
Graham_ForbesFlag for United Kingdom of Great Britain and Northern Ireland

asked on

set label to parameter value

hello

I am trying to set ASP.NET label values to values from an SQL parameter. I have around 300 parameters and I have a solution, but it is slow.

my labels are all named lblname and my parameters are all pname

see code:

 For Each p As SqlParameter In cmdselect.Parameters
           ' build a string with label name
            If p.Value IsNot Nothing  Then
                labelid = "lbl" + p.ParameterName.Substring(1, p.ParameterName.Length - 1)
                Try
                    Dim myControl1 As Label = CType(FindControl(labelid), Label)
                    If myControl1.ID = labelid Then
                        myControl1.Text = p.Value
                    End If
              Catch ex As Exception
               End Try
           End If
       Next
  
'

Open in new window


The above works but is slow, thinking I should maybe create an array in the INIT routine with the names of the control and what the parmeter names are, somthing like

 the above works, but is slow, thinking I need
       Dim ctl As Control
      dim ctlarray as array
        Dim mypanel As View
        mypanel = FindControl("viewbudetrypricing")

        For Each ctl In mypanel.Controls
          ctlarray(count) = ctl.id
        Next

Open in new window


thanks for any help.
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

I dont think that would help as in the end you are looping through the parameter collection and you are using the FindControl which both are slow processes. Why 300 parameters? May be you should rethink your approach.
ASKER CERTIFIED SOLUTION
Avatar of Graham_Forbes
Graham_Forbes
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Graham_Forbes

ASKER

no answer