Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ASP.NET Formview edit button, outside of formview?

Posted on 2009-04-22
1
Medium Priority
?
1,517 Views
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%">
    <tr>
        <td class="sub_table_topleft" />
        <td class="sub_table_top" />
        <td class="sub_table_topright-edit">
        </td>
    </tr>
    <tr>
        <td class="sub_table_notes" />
        <td>
            <asp:FormView ID="FormView1" runat="server" 
                          DataKeyNames="SID" 
                          DataSourceID="NotesDataSource1">
                <EditItemTemplate>
                    <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"   
                                    CausesValidation="True" 
                                    CommandName="Update" Text="Update" />
                    <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="notesLabel" runat="server" Text='<%# Bind("notes") %>' />
                    <asp:LinkButton ID="EditButton" runat="server" 
                                    CausesValidation="False" 
                                    CommandName="Edit" Text="Edit" />
                </ItemTemplate>
            </asp:FormView>
            <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">
                <SelectParameters>
                    <asp:QueryStringParameter Name="ServerName" QueryStringField="ServerName" 
                        Type="String" />
                </SelectParameters>
                <DeleteParameters>
                    <asp:Parameter Name="SID" Type="Int32" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="notes" Type="String" />
                    <asp:Parameter Name="SID" Type="Int32" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="notes" Type="String" />
                </InsertParameters>
            </asp:SqlDataSource>
            <asp:Label ID="NotesLbl" runat="server" Text=""></asp:Label>
        </td>
        <td class="sub_table_right" />
    </tr>
    <tr>
        <td class="sub_table_bottomleft" />
        <td class="sub_table_bottom" />
        <td class="sub_table_bottomright" />
    </tr>
</table>

Open in new window

0
Comment
Question by:Cerixus
1 Comment
 
LVL 15

Accepted Solution

by:
NazoUK earned 2000 total points
ID: 24212875
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.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

810 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