Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How can I type cast an string as an htmlTable ?

How can I type cast an string as an htmlTable ?

Scheduled Pinned Locked Moved C#
questionhelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MasudM
    wrote on last edited by
    #1

    Hi I have a problem with type casting . I have the string which is the name of one control(HtmlTable) . I know the control I want to type cast the name as the control. I tried the following and I get "Invalid Casting ! " string TableName = "Table1"; (HtmlTable)(TableName) and (HtmlTable)((object)(TableName)) Thanks

    C M 2 Replies Last reply
    0
    • M MasudM

      Hi I have a problem with type casting . I have the string which is the name of one control(HtmlTable) . I know the control I want to type cast the name as the control. I tried the following and I get "Invalid Casting ! " string TableName = "Table1"; (HtmlTable)(TableName) and (HtmlTable)((object)(TableName)) Thanks

      C Offline
      C Offline
      Corinna John
      wrote on last edited by
      #2

      Do you know the container of the control? Then you can find the name in the Controls colleciton: HtmlTable myTable = null; foreach(Control ctl in container.Controls){ if(ctl.Name == tableName){ myTable = (HtmlTable)ctl; break; } } If you don't know, where the control is, you can find it "by name": String tableName = "Table1"; Object ctl = null; System.Reflection.FieldInfo info = this.GetType().GetField(tableName); if(info != null){ ctl = info.GetValue(this); } HtmlTable myTable = (HtmlTable)ctl;

      H 1 Reply Last reply
      0
      • C Corinna John

        Do you know the container of the control? Then you can find the name in the Controls colleciton: HtmlTable myTable = null; foreach(Control ctl in container.Controls){ if(ctl.Name == tableName){ myTable = (HtmlTable)ctl; break; } } If you don't know, where the control is, you can find it "by name": String tableName = "Table1"; Object ctl = null; System.Reflection.FieldInfo info = this.GetType().GetField(tableName); if(info != null){ ctl = info.GetValue(this); } HtmlTable myTable = (HtmlTable)ctl;

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        Or by referencing the container control, you can use FindControl, passing the name. Cast the return (after checking for null) to an HtmlTable then.

        Microsoft MVP, Visual C# My Articles

        1 Reply Last reply
        0
        • M MasudM

          Hi I have a problem with type casting . I have the string which is the name of one control(HtmlTable) . I know the control I want to type cast the name as the control. I tried the following and I get "Invalid Casting ! " string TableName = "Table1"; (HtmlTable)(TableName) and (HtmlTable)((object)(TableName)) Thanks

          M Offline
          M Offline
          MasudM
          wrote on last edited by
          #4

          thanks that really helped

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups