ASP.NET Formview edit button, outside of formview?

Posted on 2009-04-22
Last Modified: 2012-08-13
I have a table and in one of the cells i have a FormView that simply has a single text field.  I want the edit button to be in a separate cell.  If I try putting the table within the formview, it gives errors such as "<TR> is not a recognized property of FormView".  Attached is the entire table.  I would like the edit button to be in the cell with the assigned CSS class "sub_table_topright-edit".  And actually, what I'd really like is for that cell itself to be the "button".  For instance with a javascript "onclick" event, if possible.
<table cellpadding="0" cellspacing="0" style="width: 100%">


        <td class="sub_table_topleft" />

        <td class="sub_table_top" />

        <td class="sub_table_topright-edit">




        <td class="sub_table_notes" />


            <asp:FormView ID="FormView1" runat="server" 




                    <asp:TextBox ID="notesTextBox" runat="server" Text='<%# Bind("notes") %>' style="width:100%" Rows="3" MaxLength="500" TextMode="MultiLine" Width="100%" />

                    <asp:LinkButton ID="UpdateButton" runat="server"   


                                    CommandName="Update" Text="Update" />

                    <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />



                    <asp:Label ID="notesLabel" runat="server" Text='<%# Bind("notes") %>' />

                    <asp:LinkButton ID="EditButton" runat="server" 


                                    CommandName="Edit" Text="Edit" />



            <asp:SqlDataSource ID="NotesDataSource1" runat="server" 

                ConnectionString="<%$ ConnectionStrings:PortalProdConnectionString1 %>" 

                SelectCommand="SELECT [SID], [notes] FROM [ServerData] WHERE ([ServerName] = @ServerName)" 

                UpdateCommand="UPDATE [ServerData] SET [notes] = @notes WHERE [SID] = @SID">


                    <asp:QueryStringParameter Name="ServerName" QueryStringField="ServerName" 

                        Type="String" />



                    <asp:Parameter Name="SID" Type="Int32" />



                    <asp:Parameter Name="notes" Type="String" />

                    <asp:Parameter Name="SID" Type="Int32" />



                    <asp:Parameter Name="notes" Type="String" />



            <asp:Label ID="NotesLbl" runat="server" Text=""></asp:Label>


        <td class="sub_table_right" />



        <td class="sub_table_bottomleft" />

        <td class="sub_table_bottom" />

        <td class="sub_table_bottomright" />



Open in new window

Question by:Cerixus
    1 Comment
    LVL 15

    Accepted Solution

    The FormView exposes it's modes and methods in it's public interface, so you could put a normal button on the page then call FormView.ChangeMode in it's button click handler. You can also call FormView.UpdateItem or FormView.InsertItem to perform the relevant update operations.

    Getting the table cell itself to act as a button is a little trickier. One method would be to put a dummy button on the page with style="display:none" set. eg.
    <asp:Button runat="server" ID="btnDummy" style="display:none;" OnClick="btnDummy_Click" />

    Then assign the table cell you want to act as the button an id:

    <td runat="server" id="tdButton" />

    Then in your Page_Load

    string eref = Page.ClientScript.GetPostBackClientHyperlink(btnDummy, "");
    tdclick.Attributes["onclick"] = eref;

    When the table cell is clicked it will act as if btnDummy was clicked and activate the event handler for that button.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now