Results 1 to 8 of 8

Thread: Programatically access an HTML table control

  1. #1

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Programatically access an HTML table control

    How do I programatically access an HTML table control from within VB? I actually want to access one of the table headers and set the text dependent on some logic.

    I have given the table an ID="tbJobs" and the table header cell an ID="tbCustomField".

    Any ideas?
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Programatically access an HTML table control

    In the CodeBehind...
    VB Code:
    1. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.     Me.tbJobs.Rows(0).Cells(0).Text = "My Table Header"
    3.     '...
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Programatically access an HTML table control

    You also have to give the table a runat attribute.

    <table id="abc" runat="server"...>


    Note, however. Once you make this change in the html view, go to design view, save the page, and THEN go into the codebehind.

  4. #4

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: Programatically access an HTML table control

    Well, here's the rub. When i give it the runat="server" attribute, it complains that it can't convert a repeater control into a table header. This is because I am using an HTML table to format data displayed with a repeater control. It's kind of embedded in my HTML table. And it doesn't like it when I set the table to run at the server...
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Programatically access an HTML table control

    Ah, you see, that was a bit of important information: The table is part of the template of a repeater control.

    You need to get the repeater's ItemDataBound event. It's in there that you can check to see, first, the type of the row you are looking at (It could be ListItemType.Header, .Item, .Footer), and then if that condition is met, do a .FindControl() on the EventArg parameter of the event. (e.FindControl("tableid"))

  6. #6

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: Programatically access an HTML table control

    And using the ItemDataBound event...my HTML table does not need to be runat="server"?
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Programatically access an HTML table control

    No, it doesn't. Because the table will then only exist as part of the control collection of the item/header/footer in your repeater control. It's the same for a datagrid and I can vaguely recall talking to you about a similar situation back when...

  8. #8

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: Programatically access an HTML table control

    Are you accusing me of having a short memory? Why you...you...whatever you name is!
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

Posting Permissions

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



Click Here to Expand Forum to Full Width