DetailsView button in TemplateField click event not firing

P

paul.haines

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
 
J

John Padilla

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!
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top