HighTechTalks DotNet Forums  

DetailsView button in TemplateField click event not firing

ASP.net Web Controls microsoft.public.dotnet.framework.aspnet.webcontrols


Discuss DetailsView button in TemplateField click event not firing in the ASP.net Web Controls forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
paul.haines@wcbs.co.uk
 
Posts: n/a

Default DetailsView button in TemplateField click event not firing - 12-10-2007 , 06:10 AM






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

Reply With Quote
  #2  
Old   
John Padilla
 
Posts: n/a

Default RE: DetailsView button in TemplateField click event not firing - 12-15-2007 , 02:15 PM







I have a trick to do that!

this is my template code for a dropdownlist:

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

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

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

DataTextField="Category" DataValueField="Category" >
</aspropDownList>

</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(((DropDownLis t)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!


"paul.haines (AT) wcbs (DOT) co.uk" wrote:

Quote:
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


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.