Sending a dynamic variable to a user control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Gadlin

    #1

    Sending a dynamic variable to a user control

    Hi there! First off, let me apologize for the basic
    question... I'm very new to .NET programming.

    I'm building a web site using VB.NET, and am trying to
    include several custom user controls. One of these user
    controls handles the navigation.

    This user control polls the database for the section
    headers that the current user has access to. It grabs
    those headers from the database, let's say 5 of them, then
    proceeds to print them to the screen.

    After each header, a second user control is embedded.
    This user control polls the database again for all of the
    individual pages under that section header the user has
    access to... and then prints those to the screen one at a
    time.

    I've built the components, and they seem to work just
    fine. My problem lies in embedding one component within
    the other, and dynamically assigning one of its properties.

    Here's what I'd LIKE to do:

    <intranet:lin ks runat="server" ID="myLinks" header="4" />

    Where it says header="4", I'd like that 4 to be a dynamic
    number. This line of code appears within a repeater, that
    is bound to a dataset.

    I've tried the following:

    intranet:links runat="server" ID="myLinks" header="<%#
    DataBinder.Eval (Container.Data Item, "ID") %>" />

    But that gives me errors. What's the proper way to pass
    that ID to the user control as its header property?

    If you've read this far, thank you... I'm guessing that
    I'm misunderstandin g something VERY basic here. This
    would have been simple for me to do using old school ASP,
    but the .NET has got me flummoxed.

    Thanks for your help!!!!!

    Please email steve.gadlin@he itman.com with your responses.

    Thanks,
    Steve Gadlin
  • Tim Stephenson

    #2
    Re: Sending a dynamic variable to a user control

    One way might be to place all the code within a single control, inserting a
    repeater after the section header which you can databind to the correct
    data.
    Alternatively, there's an "onDataBoun d" event which is fired each time a row
    gets bound. It might be possible to use this to set the right headers.

    Also, from a performance perspective you're making a lot of possibly
    unnecessary database calls. Try filling two datatables with all the sections
    and page titles that are available, and then using a dataview
    (datatable.defa ultview.rowfilt er) to filter the data for each section. This
    would give you two calls to the db, rather than one call for each section.

    You could then either loop through each of the section headers, adding a
    repeater with the right set of data for the page titles, or use the
    databound event to do the same thing each time a new header is added.


    --

    Regards

    Tim Stephenson MCSD.NET
    Charted MCAD & MCSD.NET Early Achiever

    "Steve Gadlin" <steve.gadlin@h eitman.com> wrote in message
    news:26b6701c38 ea1$140533f0$a6 01280a@phx.gbl. ..[color=blue]
    > Hi there! First off, let me apologize for the basic
    > question... I'm very new to .NET programming.
    >
    > I'm building a web site using VB.NET, and am trying to
    > include several custom user controls. One of these user
    > controls handles the navigation.
    >
    > This user control polls the database for the section
    > headers that the current user has access to. It grabs
    > those headers from the database, let's say 5 of them, then
    > proceeds to print them to the screen.
    >
    > After each header, a second user control is embedded.
    > This user control polls the database again for all of the
    > individual pages under that section header the user has
    > access to... and then prints those to the screen one at a
    > time.
    >
    > I've built the components, and they seem to work just
    > fine. My problem lies in embedding one component within
    > the other, and dynamically assigning one of its properties.
    >
    > Here's what I'd LIKE to do:
    >
    > <intranet:lin ks runat="server" ID="myLinks" header="4" />
    >
    > Where it says header="4", I'd like that 4 to be a dynamic
    > number. This line of code appears within a repeater, that
    > is bound to a dataset.
    >
    > I've tried the following:
    >
    > intranet:links runat="server" ID="myLinks" header="<%#
    > DataBinder.Eval (Container.Data Item, "ID") %>" />
    >
    > But that gives me errors. What's the proper way to pass
    > that ID to the user control as its header property?
    >
    > If you've read this far, thank you... I'm guessing that
    > I'm misunderstandin g something VERY basic here. This
    > would have been simple for me to do using old school ASP,
    > but the .NET has got me flummoxed.
    >
    > Thanks for your help!!!!!
    >
    > Please email steve.gadlin@he itman.com with your responses.
    >
    > Thanks,
    > Steve Gadlin[/color]


    Comment

    Working...