Solved

How do I on rowcommand of gridview hide the panel the gridview is in?

Posted on 2009-07-06
4
1,159 Views
Last Modified: 2012-06-27
I have an aspx page - visual basic.  Below is a simplified version of the code.  
The page comes up in "Add" mode - the form is defaulted to insert, and the gridview is displayed showing the recent items.  Template fields in the gridview enable showdetails, delete, close, and edit.  

Clicking Edit uses the gridview rowcommand to bind the form to the selected ID, change the mode to edit, and refresh the updatepanel  containing the form.  Updating returns to insert mode, gridview is refreshed on page_prerender.  Works great.

However, I would like the panel displaying the recent notes in the gridviwe to hide when the page is in edit mode.  So clicking on the edit in the gridview would use the rowcommand to change to edit mode and hide the panel the gridview is in.  After the record is updated (or canceled) the page returns to insert mode and the panel containing the gridview is visible again.

I've tried many many approaches and cannot find the correct one.  The most recent approach is to use a collapsible panel extender  on the panel containing the gridview and set the collapsed and clientstates to true when changing to edit mode.  However, I cannot get it to work.  Anywhere I have tried to put the collapse code it does nothing unless I just stick it in a button outside the panel - which is not automated.  How can I make this work?  

Thanks!
Full Code
 
                    <%'**** ADD EDIT FORM PANEL ***%>                                             
                    <asp:UpdatePanel ID="UpdatePnlAddEdit" runat="server" UpdateMode="Conditional">
                        <ContentTemplate>
                            <asp:SqlDataSource ID="SqlNotes" ...                                                                                                <EditItemTemplate>
                                    <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                                        Text="Update">
                                    </asp:LinkButton>
                                    <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                                        Text="Cancel">
                                </EditItemTemplate>
                            </asp:FormView>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                    <%'**** END ADD EDIT FORM PANEL ***%>                                             
 
 
~~~~I want this entire panel to hide when the edit button is clicked (form goes into edit mode) and show when the page returns to insert mode - onupdate or cancel of the form ~~~~~~~~
 
<asp:Panel ID="PanelNotes" runat="server">
                    <span class="subheading2" id="NotesHeader">NOTES ADDED BY YOU IN THE LAST 24 HOURS</span><br /> 
                    <%'**** Notes Panel ***%>                                             
                    <asp:UpdatePanel ID="PanelListNotes" runat="server" UpdateMode="Conditional">
                        <ContentTemplate>
                            <asp:SqlDataSource ID="SqlRecentQuickNotes" ...                                                            </asp:SqlDataSource>
                            <asp:GridView ID="gvRecentNotes" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlRecentQuickNotes" CellPadding="4" ForeColor="#333333" GridLines="None" DataKeyNames="NoteID" HorizontalAlign="Right" Width="100%">
                                <Columns>
                                    <asp:BoundField DataField="Note" HeaderText="Note" SortExpression="Note" />
                                    <asp:TemplateField>
                                        <ItemTemplate>
                                            <asp:ImageButton id="btnVieDetails" runat="server" ImageUrl="~/images/magnifier.png" ToolTip="View details" AlternateText="Details" CommandName="ViewDetails" commandargument='<%# Eval("NoteID")%>' />
                                        </ItemTemplate>
                                    </asp:TemplateField>                                
                                    <asp:TemplateField>
                                        <ItemTemplate>
                                            <asp:ImageButton id="btnEdit" runat="server" ImageUrl="~/images/pencil.png" ToolTip="Edit Note" AlternateText="Edit Note" CommandName="EditNote"  commandargument='<%# Eval("NoteID")%>' />
                                        </ItemTemplate>
                                    </asp:TemplateField>                                
                                    <asp:TemplateField>
                                </Columns>
                        </asp:GridView><br />
                        </ContentTemplate>
                    </asp:UpdatePanel>  
                    <%'**** END Notes Panel ***%>                     
</asp:Panel> 
 
 
 
                    <asp:Button ID="btnHideNotes" runat="server" Text="Button" />
    <ajaxToolkit:CollapsiblePanelExtender ID="cpeNotes" runat="Server"
        TargetControlID="PanelNotes"
        ExpandControlID="btnHideNotes"
        CollapseControlID="btnHideNotes"
        Collapsed="False"
        ImageControlID="edit_ToggleImage" 
        ExpandedImage="~/images/collapse_blue.jpg"
        CollapsedImage="~/images/expand_blue.jpg"
        SuppressPostBack="false"        />                      
 
 
 
CodeBehind
 
    Protected Sub gvRecentNotes_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvRecentNotes.RowCommand
        Select Case e.CommandName
            Case "EditNote"
                SqlNotes.SelectParameters("NoteID").DefaultValue = e.CommandArgument
                fvAddEditNote.Visible = True
                fvAddEditNote.DataBind()
                fvAddEditNote.ChangeMode(FormViewMode.Edit)
                UpdatePnlAddEdit.Update()
                cpeNotes.ClientState = True  ~~~~~~These do nothing inside of here - not sure why
                cpeNotes.Collapsed = True
        End Select
    End Sub
 
    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        gvRecentNotes.DataBind()
    End Sub

Open in new window

0
Comment
Question by:okcuser
  • 2
  • 2
4 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24788070
You have this Panel:

<asp:Panel ID="PanelNotes" runat="server">

and the UpdatePanel:

 <asp:UpdatePanel ID="PanelListNotes" runat="server" UpdateMode="Conditional">

Which panel are you trying to hide?

0
 

Author Comment

by:okcuser
ID: 24788147
Either.  I originally only had the updatepanel, but I added the PanelNotes wrapper to set the collapsable panel to.

I've also tried not using the panel and just setting the visible property on the gridview in the rowcommand.  That turns it off fine, but I cannot find any place that I can set the visible back to true and have it show.
0
 

Author Comment

by:okcuser
ID: 24788182
I imagine this all has something to do with the conditional updates on the udpate panels, but I'm coming from classic asp and setting the visible property on a panel when the user is in "edit mode" doesn't seem like it should be that hard.  Just can't find the right place to turn gridview visible off/on or expand/collapse the panel around the gridview.  
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 24788868
If you have a <div> element, then you can use JavaScript to set style.display = 'none', or use a CSS class to a style for visible, and a different style for hidden.

Example:


script language="JavaScript">
	function setStyle(me, s)
         {
	    me.style.display=s;
	}
</script>

Open in new window

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying 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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

792 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