okcuser
asked on
How do I on rowcommand of gridview hide the panel the gridview is in?
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!
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
ASKER
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.
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.
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<asp:Panel ID="PanelNotes" runat="server">
and the UpdatePanel:
<asp:UpdatePanel ID="PanelListNotes" runat="server" UpdateMode="Conditional">
Which panel are you trying to hide?