DetailsView button in TemplateField click event not firing

Discussion in 'ASP .Net Web Controls' started by paul.haines@wcbs.co.uk, Dec 10, 2007.

  1. Guest

    I have a DetailsView with a number of TemplateFields, (plus other
    types of fields). One has a button and a click event handler. Another
    has DropDownList, which has its selected value initialised when
    editing, (from a session variable source).

    Unfortunately I've found that to get the click event to fire I need to
    re-bind the DetailsView when posting back the page, but this loses the
    newly selected option in the DropDownList. If I don't re-bind then I
    keep the chosen option, but the button's event never fires.

    Any ideas what I can do to solve this? Or have I done something wrong
    with my current method?

    Thanks for any help,
    Paul
     
    , Dec 10, 2007
    #1
    1. Advertising

  2. John Padilla Guest

    I have a trick to do that!

    this is my template code for a dropdownlist:

    <asp:TemplateField HeaderText="Menu Group"
    SortExpression="Category">
    <EditItemTemplate>
    <asp:DropDownList
    ID="ddEditCategory" runat="server"

    ValidationGroup='<%# Bind("Category") %>'

    OnDataBound="ddEditCategory_DataBound"
    DataSource
    ="<%#odsPageGroupList%>"

    DataTextField="Category" DataValueField="Category" >
    </asp:DropDownList>

    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="Label2"
    runat="server" Text='<%# Bind("Category") %>'></asp:Label>
    </ItemTemplate>

    I cheated by puting the value of the Category value, the text value, in the
    ValidationGroup proeprty.

    Then in the OnDataBound event for the dropdownlist
    (ddEditCategory_DataBound) I have this code:

    protected void ddEditCategory_DataBound(object sender, EventArgs e)
    {
    ((DropDownList)sender).SelectedIndex =
    ((DropDownList)sender).Items.IndexOf(((DropDownList)sender).Items.FindByText(((DropDownList)sender).ValidationGroup));
    }

    Now some people may scream a this so if that is the case you can add a
    property of your to a control that you create that inhertis from the
    dropdownlist and go through all the hoops, but this is a quick and dirty (and
    i mean Dirty) way to do what you want!

    Hope this helps!


    "" wrote:

    > I have a DetailsView with a number of TemplateFields, (plus other
    > types of fields). One has a button and a click event handler. Another
    > has DropDownList, which has its selected value initialised when
    > editing, (from a session variable source).
    >
    > Unfortunately I've found that to get the click event to fire I need to
    > re-bind the DetailsView when posting back the page, but this loses the
    > newly selected option in the DropDownList. If I don't re-bind then I
    > keep the chosen option, but the button's event never fires.
    >
    > Any ideas what I can do to solve this? Or have I done something wrong
    > with my current method?
    >
    > Thanks for any help,
    > Paul
    >
     
    John Padilla, Dec 15, 2007
    #2
    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. Purvi T
    Replies:
    0
    Views:
    880
    Purvi T
    Oct 19, 2004
  2. Amy
    Replies:
    0
    Views:
    1,011
  3. sloan
    Replies:
    2
    Views:
    4,917
    aryan_subhash
    Oct 17, 2007
  4. mesut
    Replies:
    0
    Views:
    581
    mesut
    Jun 29, 2007
  5. GauravGupta
    Replies:
    4
    Views:
    2,123
    Shilpa1234
    Jan 19, 2012
Loading...

Share This Page