Monday, March 12, 2012

How to handle events for controls within templates?

I have a FormView control, containing an EditItemTemplate with a dropdown listbox. I want to handle the SelectedIndexChanged event so I can hide or show part of the form...

If I double-click the dropdown to create the event handler, I get the function dropdown1_SelectedIndexChanged()... but without " handles Dropdown1.SelectedIndexChanged"

Obviously the dropdown1 control is inside the EditItemTemplate - but it still generates events? how does one get these?

This is getting frustrating: every time I try to design stuff logically in a componentised way, I get kicked in the teeth with a "gotcha". It was easier using classic ASP and just throwing the html out using Response.Write!!

Hello.

I think that you're using vb.net, right? in c# I don't see any trouble with this. Doesn't something like this work in vb.net:

<asp:DropDownListrunat="server"id="T"OnSelectedIndexChanged="p"AutoPostBack="true">

<asp:ListItemText="1"/>

<asp:ListItemText="2"/>

</asp:DropDownList>

then just define the p method without using the handles (but with the normal parameter list).


Ah, many many hanks: I didn't realise thats how it worked (instead of event-based handling). It so frustrated me last night i turned off the PC and polished off a bottle of wine.

That part works at last!

Now all I need to do is figure out how to control my datasource and formview to tell them to open in edit or insert mode by default (and not select).

Labels: , , , , , , , , , , , , , ,

How to handle cancel command on a formview inside of a datalist?

I have no problem using the findcontrol method to work with the formview, but I want to hide the formview when the cancel button is pressed. I am new and at a loss... been looking everywhereI can't tell if the Cancel button is on your FormView or on your DataList, but either way, you'd do the same thing. When you handle the Cancel button (you have to do it manually in DataList, in FormView you can handle the OnModeChanging event and see if CancelingEdit in the event args is true), use FindControl to find the FormView and set FormView.Visible = false.
Hope this helps...

Labels: , , , , , , , , , , , ,