Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > DetailsView button in TemplateField click event not firing

Reply
Thread Tools

DetailsView button in TemplateField click event not firing

 
 
paul.haines@wcbs.co.uk
Guest
Posts: n/a
 
      12-10-2007
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
 
 
 
 
John Padilla
Guest
Posts: n/a
 
      12-15-2007

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!


"(E-Mail Removed)" 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
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
image button click event fires before click event of button Purvi T ASP .Net 0 10-19-2004 06:19 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net Building Controls 1 05-28-2004 06:23 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net 2 05-25-2004 11:45 PM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net Datagrid Control 0 05-25-2004 01:45 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net Web Controls 0 05-25-2004 01:45 AM



Advertisments