Groups | Blog | Home
all groups > asp.net webcontrols > april 2008 >

asp.net webcontrols : FormView Page_PreRender problem



colin_nz via DotNetMonster.com
4/15/2008 7:07:57 AM
Hi

Very new to C# and ASP.Net

In VS2008 (targeting ASP.Net 2.0), I have a SqlDataSource for a FormView
which gets a parameter from a dropdown list control.

The selected value in the dropdown list determines what record is shown in
the formview and this works.

I now want to hide/show the FormView's Edit and Delete buttons depending on
values in some of the fields in the FromView.

I am trying to do this in the FormView's PreRender event. In order to
retrieve the field values using FindControl, I first have to call DataBind().
This also works.

Unfortunately, calling DataBind() in the PreRender event stops the "dropdown
list determines what record is shown' from working. Now, no matter what value
is selected in the dropdown list, the FormView always shows the first record.

Without calling DataBind(), (LinkButton)ClientFormView.Row.FindControl
("DeleteButton"); returns null.

Any ideas how I can hide/show the FormView's Edit and Delete buttons and
still have the dropdown list working as intended?

Thanks

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net-web-controls/200804/1
colin_nz via DotNetMonster.com
4/15/2008 7:40:29 AM
Never mind.

I solved it by changing the Pre_Render event into a ShowButtons() function
(without the Databind()) and call the function from the aspx code

<asp:LinkButton
ID="DeleteButton"
runat="server"
CausesValidation="False"
CommandName="Delete"
Text="Delete"
Visible=<%# ShowButtons() %>
/>

--
Message posted via http://www.dotnetmonster.com
AddThis Social Bookmark Button