Results 1 to 4 of 4

Thread: [RESOLVED] [2005] Which event to use in GridView?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602

    Resolved [RESOLVED] [2005] Which event to use in GridView?

    Hi!
    I have a problem with the GridView

    When I put a row in edit mode by pressing the "Edit" button, in one of the templatecolumns I have a dropdownlist. If the source data returned to this dropdown is null (Its a list of contacts, and no contacts have been added), I need to add a row to this dropdown with text="No contacts available..." and value = -1, because -1 is returned from the Bind() of the gridview.

    Which event should I use to check the datasource for the edit dropdown? If the rows in teh datasource is 0 then I want to add this "dummy" row. But I need to do it before the grid is trying to bind, and after the data has been bound to the dropdown...

    This works great with the footer, when I hade the add item functonality. But there, the dropdown exist all the time... The edit dropdown exist only after the edit postback.
    Here is the code for the edit dropdown:

    Code:
    <EditItemTemplate>
                                            <asp:DropDownList ID="ddlEditVendorContact"
                                                                 runat="server"
                                                                 CssClass="text" 
                                                                 DataSource='<%# GetVendorContacts() %>'
                                                                 DataTextField="contact_name" 
                                                                 DataValueField="vendor_contact_id" 
                                                                 SelectedValue='<%# Bind("vendor_contact_id") %>'>
                                            </asp:DropDownList>
                                        </EditItemTemplate>
    Basically, if the GetVendorContacts() return table with 0 rows I need to add a dummy record BEFORE the SelectedValue='<%# Bind("vendor_contact_id") %>' occurs.

    Is this at all possible?

    kind regards
    Henrik
    Last edited by MrNorth; Jun 1st, 2007 at 03:21 AM.

  2. #2
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: [2005] Which event to use in GridView?

    are you saying that the dropdown's databound event does not fire? as this is where i would perform this action

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  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: [2005] Which event to use in GridView?

    Use the GridView's RowEditing event. You will need to do a FindControl() to get a reference to the dropdownlist, which you should then cast, and add the row to.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602

    Re: [2005] Which event to use in GridView?

    Thanks for the suggestions, its working now!

    /Henrik

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