Professional Web Applications Themes

Compact code - ASP.NET Data Grid Control

I have mycontrol as custom control and I need to get some data from a control on a different page. My code is below. It is working perfectly fine, but since I have 10 more label to check is it some how I can make this code is more compact? If CType(myconrtol.FindControl("lblCompany"), Label).Visible = True Then dr(0) = CType(myconrtol.FindControl ("lblCompany"), Label).Text() dr(1) = myconrtol.Company dt.Rows.Add(dr) dr = dt.NewRow() End If If CType(myconrtol.FindControl("lblPlanName"), Label).Visible = True Then dr(0) = CType(myconrtol.FindControl ("lblPlanName"), Label).Text() dr(1) = myconrtol.PlanName dt.Rows.Add(dr) dr = dt.NewRow() End If...

  1. #1

    Default Compact code

    I have mycontrol as custom control and I need to get some
    data from a control
    on a different page. My code is below. It is working
    perfectly fine, but since
    I have 10 more label to check is it some how I can make
    this code is more
    compact?
    If CType(myconrtol.FindControl("lblCompany"),
    Label).Visible = True Then
    dr(0) = CType(myconrtol.FindControl
    ("lblCompany"), Label).Text()
    dr(1) = myconrtol.Company
    dt.Rows.Add(dr)
    dr = dt.NewRow()
    End If

    If CType(myconrtol.FindControl("lblPlanName"),
    Label).Visible = True Then
    dr(0) = CType(myconrtol.FindControl
    ("lblPlanName"), Label).Text()
    dr(1) = myconrtol.PlanName
    dt.Rows.Add(dr)
    dr = dt.NewRow()

    End If
    anonymous Guest

  2. #2

    Default Re: Compact code

    Hello,
    Assuming these controls are all part of a page, try looping through all
    of the controls on the page...

    For Each ctl In Me.Controls(1).Controls
    Try
    ...
    Catch
    End Try
    Next

    Jason

    Jason Guest

  3. #3

    Default Re: Compact code

    But I do I get to this code?
    dr(0) = CType(mycontrol.FindControl("lblCompany"),
    Label).Text()
    dr(1) = mycontrol.Company
    dt.Rows.Add(dr)
    anonymous Guest

  4. #4

    Default Re: Compact code

    Here is what I did based on your post, however I am not
    getting back the right controls name in custom mycontrols.
    For Each ctl In mycontrols.Controls 'Me.Controls
    (1).Controls
    Dim tb As Label
    Dim tx As TextBox
    If TypeOf ctl Is Label Then
    tb = CType(ctl, Label)
    dr(0) = tb.Text
    ElseIf TypeOf ctl Is TextBox Then
    tx = CType(ctl, TextBox)
    dr(0) = tx.Text
    Else
    End If
    dt.Rows.Add(dr)
    dr = dt.NewRow()
    Next
    anonymous Guest

Similar Threads

  1. Can't compact/repair Coldfusion db
    By dw in forum Coldfusion - Getting Started
    Replies: 2
    Last Post: June 24th, 01:28 PM
  2. Compact Access Db Remotely?
    By Sue Barth in forum ASP Database
    Replies: 4
    Last Post: June 18th, 01:37 PM
  3. Compact and repair database
    By Kurt H Hanssen in forum ASP Database
    Replies: 2
    Last Post: February 12th, 08:05 PM
  4. code to compact on close in A97
    By Rick Brandt in forum Microsoft Access
    Replies: 1
    Last Post: July 30th, 03:27 PM
  5. Code for compact and repair on close
    By carlee in forum Microsoft Access
    Replies: 1
    Last Post: July 28th, 08:45 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139