problems with listbox id changing within datagrid control

Discussion in 'ASP .Net Datagrid Control' started by Paul Reilly, Jun 21, 2004.

  1. Paul Reilly

    Paul Reilly Guest


    I've created a datagrid that has edititemtemplates. One of the
    edititemtemplate columns is actually two listboxes that are bound from
    sql calls when the edit button is clicked - they represent a
    "container" structure, where you can move elements from one side to
    the other. I do not know of any server side .net "container" options
    so I am implementing it client side javascript. I've done it before
    and it's fairly straight forward - you have buttons that just call
    javascript functions passing in the select box's name's (id's).

    The problem I am having is that when I have these listboxes within the
    datagrid, their names are changed in the compiled output. This is a
    simplified version of the edititemtemplate in question:

    <asp:ListBox RUNAT="server" id="available"
    DataSource=<%# FillLeft((int)DataBinder.Eval(Container.DataItem,"id"))%>

    <INPUT TYPE="BUTTON" VALUE="&gt;&gt;"

    <asp:ListBox RUNAT="server"
    DataTextField="name" MULTIPLE
    DataSource=<%# FillRight((int)DataBinder.Eval(Container.DataItem,"id"))%>

    This column resides within the "resultsDataGrid" dataGrid.

    If you notice the input box in the middle, it calls javascript
    functions that pass the listbox name as parameters. However when I
    view this page in a browser, the name of the available select box is
    not "available" it is something dynamic such as
    "resultsDataGrid:_ct12:available". How can I pass the real select name
    to my javascript functions considering .net is setting it dynamically.

    Thanks for the help!

    Paul Reilly, Jun 21, 2004
    1. Advertisements

  2. Paul Reilly

    Rick Spiewak Guest

    You could create the javascript function for each item dynamically in the
    code behind during the itemcreated event (adding the attribute) knowing what
    the rendered ID will be (it won't have that value while your code is
    running, however!). Or, you could put your manipulation code in the
    codebehind on the click event for the button.
    Rick Spiewak, Jun 22, 2004
    1. Advertisements

  3. Paul Reilly

    Paul Reilly Guest

    Thanks for your thoughts - my .NET knowledge is minimal though and I'm
    having problems figuring out how to reference the names for the
    listboxes - I could just pass an asp variable into the javascript
    functions in the aspx, so at runtime the compiled code had the correct
    variables in the function call, but I'm not sure how to access that
    property. Any ideas? Thanks.

    Paul Reilly, Jun 22, 2004
  4. Paul Reilly

    Rick Spiewak Guest

    During the itemcreated event, you will be able to compute the runtime ids of
    the controls, and attach javascript to the button in the item as needed,
    using the attributes collection of the button and adding an onclick
    attribute. If you use view source on your page, you should be able to figure
    out how to compute the runtime id based on the item index. (If I had code
    that did this, I'd give it to you, this "Socratic" method isn't my usual
    style, but it should get you there. Just implement the itemcreated event and
    set a breakpoint in it, and play around...)
    Rick Spiewak, Jun 23, 2004
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.