GridView DDL and Label

Discussion in 'ASP .Net Web Controls' started by Chuck P, Nov 20, 2006.

  1. Chuck P

    Chuck P Guest

    In my item template I have a label called ProductName
    In my edit template I have a DDL called ProductName.

    My object datasource for the gridview contains only the ProductID.

    The DDL has an objectDatasource to Products table.

    What is the best way that when I am in the normal view the label gets filled
    with the ProductName.

    Currently I have a function in the aspx page GetDescription(eval("ProductID"))

    string GetDescription(string ID)
    {
    ienumerable inum= objectdatasource.select();
    foreach item in inum
    if inum.id ===id return inum.description;
    }

    Is their a better way to do this?
    I toyed with putting something in the gridview's row event's
     
    Chuck P, Nov 20, 2006
    #1
    1. Advertising

  2. Hi Chuck,

    Based on my understanding, you're using a data-bound DropDownList in
    EditTemplate of GridView and you want to know besides manually find the
    current row's product name by code, is there any better way to do this?

    Well, you could use data binding for the DropDownList and bind the
    SelectedValue property to current row's field. Though you must turn on the
    viewstate of this DropDownList to work correctly. See following thread:

    http://msdn.microsoft.com/newsgroups/managed/Default.aspx?dg=microsoft.publi
    c.dotnet.framework.aspnet&mid=83fb8b7a-f96f-4384-919f-b74c8abb9b8c


    Let me know if this answers your question. Thanks.

    Sincerely,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications. If you are using Outlook Express, please make sure you clear the
    check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
    promptly.

    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Nov 21, 2006
    #2
    1. Advertising

  3. Chuck P

    Chuck P Guest

    No that's a different issue. I would think mine has come up a lot but I
    haven't seen ti discussed.

    My issue is how to display a field that is not in the grid's data collection
    when in the item template.



    "Walter Wang [MSFT]" wrote:

    > Hi Chuck,
    >
    > Based on my understanding, you're using a data-bound DropDownList in
    > EditTemplate of GridView and you want to know besides manually find the
    > current row's product name by code, is there any better way to do this?
    >
    > Well, you could use data binding for the DropDownList and bind the
    > SelectedValue property to current row's field. Though you must turn on the
    > viewstate of this DropDownList to work correctly. See following thread:
    >
    > http://msdn.microsoft.com/newsgroups/managed/Default.aspx?dg=microsoft.publi
    > c.dotnet.framework.aspnet&mid=83fb8b7a-f96f-4384-919f-b74c8abb9b8c
    >
    >
    > Let me know if this answers your question. Thanks.
    >
    > Sincerely,
    > Walter Wang (, remove 'online.')
    > Microsoft Online Community Support
    >
    > ==================================================
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    > ications. If you are using Outlook Express, please make sure you clear the
    > check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
    > promptly.
    >
    > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    > where an initial response from the community or a Microsoft Support
    > Engineer within 1 business day is acceptable. Please note that each follow
    > up response may take approximately 2 business days as the support
    > professional working with you may need further investigation to reach the
    > most efficient resolution. The offering is not appropriate for situations
    > that require urgent, real-time or phone-based interactions or complex
    > project analysis and dump analysis issues. Issues of this nature are best
    > handled working with a dedicated Microsoft Support Engineer by contacting
    > Microsoft Customer Support Services (CSS) at
    > http://msdn.microsoft.com/subscriptions/support/default.aspx.
    > ==================================================
    >
    > This posting is provided "AS IS" with no warranties, and confers no rights.
    >
    >
     
    Chuck P, Nov 21, 2006
    #3
  4. Hi Chuck,

    Sorry for my misunderstanding.

    I now understand your question is how to display the productname for label
    in ItemTemplate. You already have a ObjectDataSource which will return all
    products info and you only have productid in the data bound to the
    GridView.

    I don't think it's possible to use declarative way to bind the label to the
    objectdatasource here since there're multiple row with different productid
    and the row is already bound to the datasource of the GridView.

    I think your solution works just fine, but you don't have to call
    objectdatasource.select() every time. For each row, the binding are in the
    same postback, you could use a member variable to cache the data from
    objectdatasource and use it to find productname according to each row's
    productid. This should improve performance.

    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Nov 22, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marina
    Replies:
    0
    Views:
    917
    Marina
    Aug 12, 2003
  2. mik
    Replies:
    2
    Views:
    457
  3. mik
    Replies:
    1
    Views:
    433
    Eliyahu Goldin
    May 12, 2008
  4. Mike Robbins

    GridView and DDL

    Mike Robbins, Mar 14, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    137
    Mike Robbins
    Mar 15, 2006
  5. Knut Krueger
    Replies:
    8
    Views:
    276
    Knut Krueger
    Aug 20, 2013
Loading...

Share This Page