FormView control disappears whenever I change it's mode in a collapsible panel?

Last post 11-12-2008 3:40 PM by benfinkel. 4 replies.

Sort Posts:

  • FormView control disappears whenever I change it's mode in a collapsible panel?

    11-11-2008, 3:35 PM
    • Member
      8 point Member
    • benfinkel
    • Member since 04-04-2008, 2:26 PM
    • Posts 36

    Hello all,

    I followed a tutorial I found on the web:  http://mosesofegypt.net/post/Building-a-grouping-Grid-with-GridView-and-ASPNET-AJAX-toolkit-CollapsiblePanel.aspx

    Here is what I have  An UpdatePanel with a Gridview in it, inside of that GridView's ItemTemplate is my control panel (+/-), a panel with a FormView in it and another GridView, and the CollapsiblePanelExtender.  It all works okay until I change the mode of the FormView.  I've got both an ItemTemplate and EditItemTemplate defined for the FV, and if I set the default mode I can get either template to show, but the command button to switch the FV's mode causes the FV to disappear completely.  I know the panel with the FV in it is still visible because I have a GridView in there that I can see, but the FV itself goes away no matter which Mode I start it in.

     

    Any ideas?

     

    Thanks!

     

            <asp:SqlDataSource ID="sdsWeeks" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:CARDS %>" 
                    SelectCommand="GetWeeks" SelectCommandType="StoredProcedure">
                    <SelectParameters>
                        <asp:SessionParameter Name="SiteID" SessionField="SiteID" Type="Int32" />
                    </SelectParameters>
            </asp:SqlDataSource>
            <cc1:ToolkitScriptManager ID="tsm" runat="server"></cc1:ToolkitScriptManager>
            <asp:UpdatePanel ID="pnlUpdate" runat="server">            
                <ContentTemplate>        
                    <asp:Gridview ID="gvScreeningLog" runat="server" AutoGenerateColumns="False" 
                                    CellPadding="4" ForeColor="#333333" GridLines="None"
                                    Font-Names="Verdana" Font-Size="Small"
                                    DataSourceID="sdsWeeks" DataKeyNames="ScreeningWeekID" 
                                    OnRowCreated="gvScreeningLog_RowCreated"
                                    AllowPaging="True" PageSize="5" Width="400px">   
                        <Columns>                                    
                            <asp:TemplateField HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" HeaderText="Week Beginning">
                                <ItemTemplate>
                                    <asp:SqlDataSource ID="sdsLogDetails" runat="server" 
                                            ConnectionString="<%$ ConnectionStrings:CARDS %>" 
                                            SelectCommand="GetScreeningLogDetails" SelectCommandType="StoredProcedure">
                                            <SelectParameters>
                                                <asp:Parameter Name="ScreeningWeekID" Type="Int32" />
                                            </SelectParameters>     
                                    </asp:SqlDataSource>   
                                    <asp:SqlDataSource ID="sdsWeekDetails" runat="server" 
                                            ConnectionString="<%$ ConnectionStrings:CARDS %>" 
                                            SelectCommand="GetWeekDetails" SelectCommandType="StoredProcedure"
                                            UpdateCommand="UpdateWeekDetails" UpdateCommandType="StoredProcedure">
                                            <SelectParameters>
                                                <asp:Parameter Name="ScreeningWeekID" Type="Int32" />
                                            </SelectParameters> 
                                            <UpdateParameters>
                                                <asp:SessionParameter Name="Username" Type="String" SessionField="Username" />
                                            </UpdateParameters>    
                                    </asp:SqlDataSource>                                     
                                        <asp:Panel ID="panWeeks" runat="server">
                                            <asp:Image ID="imgPlus" runat="server" ImageUrl="~/images/plus.png" />
                                            <span><%# Eval("WeekBeginning") %> ( <%# Eval("TotalCount") %> Total)</span>
                                        </asp:Panel>
                                        <asp:Panel ID="panLog" runat="server">
                                            <table>
                                                <tr>
                                                    <td style="width: 25px">
                                                    </td>
                                                    <td>                                                
                                                        <asp:FormView ID="fvWeekDetail" runat="server"
                                                            DataSourceID="sdsWeekDetails" DataKeyNames="ScreeningWeekID"
                                                            ForeColor="Black" style="border-bottom: solid 1px DarkOliveGreen">
                                                            <ItemTemplate>
                                                                <table>
                                                                    <tr>
                                                                        <td>
                                                                            <asp:Label ID="lblTotalCount" runat="server" Text="Total # of Patients Admitted:" Font-Bold="true"></asp:Label>                                                                        
                                                                        </td>
                                                                        <td>
                                                                            <asp:Label ID="lblTotalCountData" runat="server" Text='<%# Eval("TotalCount") %>'></asp:Label>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td>
                                                                            <asp:Label ID="lblOver12" runat="server" Text="Total # of Patients Over 12 Years:" Font-Bold="true"></asp:Label>                                                                        
                                                                        </td>
                                                                        <td>
                                                                            <asp:Label ID="lblOver12Data" runat="server" Text='<%# Eval("TotalOver12") %>'></asp:Label>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td>
                                                                            <asp:Label ID="lblIntubated" runat="server" Text="Total # of Patients Intubated:" Font-Bold="true"></asp:Label>                                                                        
                                                                        </td>
                                                                        <td>
                                                                            <asp:Label ID="lblIntubatedData" runat="server" Text='<%# Eval("TotalIntubated") %>'></asp:Label>
                                                                        </td>
                                                                    </tr>                                                                                                                                
                                                                    <tr>
                                                                        <td>
                                                                            <asp:Label ID="lblARDS" runat="server" Text="Total # of Patients with ALI/ARDS:" Font-Bold="true"></asp:Label>                                                                        
                                                                        </td>
                                                                        <td>
                                                                            <asp:Label ID="lblARDSData" runat="server" Text='<%# Eval("TotalARDS") %>'></asp:Label>
                                                                        </td>
                                                                    </tr>   
                                                                    <tr>
                                                                        <td>
                                                                            <asp:Label ID="lblDirect" runat="server" Text="Total # of Patients with Direct ALI/ARDS:" Font-Bold="true"></asp:Label>                                                                        
                                                                        </td>
                                                                        <td>
                                                                            <asp:Label ID="lblDirectData" runat="server" Text='<%# Eval("TotalDirect") %>'></asp:Label>
                                                                        </td>
                                                                    </tr>    
                                                                    <tr align="right">
                                                                        <td>
                                                                        </td>
                                                                        <td>                                                                       
                                                                            <asp:Button ID="cmdEditWeek" runat="server" Text="Edit" CommandName="Edit"
                                                                            BackColor="#F7F6F3" BorderColor="#E6E2D8" Width="50px"
                                                                            BorderStyle="Outset" BorderWidth="1px" Font-Names="Verdana" 
                                                                            Font-Size="Small" ForeColor="DarkOliveGreen" />                                                                    
                                                                        </td>
                                                                    </tr>                                                                                                                            
                                                                </table>
                                                            </ItemTemplate>                                                        
                                                            <EditItemTemplate>
                                                                <table>
                                                                    <tr>
                                                                        <td>
                                                                            <asp:Label ID="lblTotalCount" runat="server" Text="Total # of Patients Admitted:" Font-Bold="true"></asp:Label>                                                                        
                                                                        </td>
                                                                        <td>
                                                                            <asp:Textbox ID="tbTotalCount" runat="server" Text='<%# Bind("TotalCount") %>' Width="25px"></asp:Textbox>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td>
                                                                            <asp:Label ID="lblOver12" runat="server" Text="Total # of Patients Over 12 Years:" Font-Bold="true"></asp:Label>                                                                        
                                                                        </td>
                                                                        <td>
                                                                            <asp:Textbox ID="tbOver12" runat="server" Text='<%# Bind("TotalOver12") %>' Width="25px"></asp:Textbox>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td>
                                                                            <asp:Label ID="lblIntubated" runat="server" Text="Total # of Patients Intubated:" Font-Bold="true"></asp:Label>                                                                        
                                                                        </td>
                                                                        <td>
                                                                            <asp:Textbox ID="tbIntubated" runat="server" Text='<%# Bind("TotalIntubated") %>' Width="25px"></asp:Textbox>
                                                                        </td>
                                                                    </tr>                                                                                                                                
                                                                    <tr>
                                                                        <td>
                                                                            <asp:Label ID="lblARDS" runat="server" Text="Total # of Patients with ALI/ARDS:" Font-Bold="true"></asp:Label>                                                                        
                                                                        </td>
                                                                        <td>
                                                                            <asp:Textbox ID="tbARDS" runat="server" Text='<%# Bind("TotalARDS") %>' Width="25px"></asp:Textbox>
                                                                        </td>
                                                                    </tr>   
                                                                    <tr>
                                                                        <td>
                                                                            <asp:Label ID="lblDirect" runat="server" Text="Total # of Patients with Direct ALI/ARDS:" Font-Bold="true"></asp:Label>                                                                        
                                                                        </td>
                                                                        <td>
                                                                            <asp:Textbox ID="tbDirect" runat="server" Text='<%# Bind("TotalDirect") %>' Width="25px"></asp:Textbox>
                                                                        </td>
                                                                    </tr>     
                                                                    <tr align="right">
                                                                        <td>
                                                                        </td>
                                                                        <td>                                                                   
                                                                        </td>
                                                                    </tr>                                                                                                                                                                                            
                                                                </table>                                                        
                                                            </EditItemTemplate>
                                                        </asp:FormView>                                
                                                        <asp:GridView ID="gvLog" runat="server" CellPadding="4" 
                                                            ForeColor="#333333" GridLines="None"
                                                            DataSourceID="sdsLogDetails" AutoGenerateColumns="False"
                                                            DataKeyNames="ScreeningID" >
                                                            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                                            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                                            <Columns>
                                                                <asp:BoundField DataField="ReasonExcluded" HeaderText="Reason Excluded" 
                                                                    SortExpression="ReasonExcluded" />
                                                                <asp:BoundField DataField="ReasonExcludedDD" HeaderText="Reason Excluded DD" 
                                                                    SortExpression="ReasonExcludedDD" />
                                                            </Columns>
                                                            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                                                            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                                                            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                                            <EditRowStyle BackColor="#999999" />
                                                            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                                                        </asp:GridView>
                                                    </td>
                                                </tr>
                                            </table>
                                        </asp:Panel> 
                                        
                                        <cc1:collapsiblepanelextender ID="cpeLog" runat="server"
                                            TargetControlID="panLog"
                                            ExpandControlID="panWeeks" CollapseControlID="panWeeks"
                                            CollapsedSize="0" Collapsed="True"
                                            AutoCollapse="False" AutoExpand="False" ScrollContents="false" 
                                            ImageControlID="imgPlus"
                                            ExpandedImage="~/images/minus.png" CollapsedImage="~/images/plus.png"
                                            ExpandDirection="Vertical"                                     >
                                        </cc1:collapsiblepanelextender>  
                                </ItemTemplate>
                                <HeaderStyle HorizontalAlign="Left" />
                                <ItemStyle HorizontalAlign="Left" />
                            </asp:TemplateField>            
                        </Columns>                                     
                        <PagerSettings Mode="NumericFirstLast" />
                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />                    
                        <PagerStyle BackColor="#006600" ForeColor="White" HorizontalAlign="Center" Height="10px" Font-Size="Smaller" />
                        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                        <HeaderStyle BackColor="#006600" Font-Bold="True" ForeColor="White" />
                        <EditRowStyle BackColor="#999999" />
                        <AlternatingRowStyle BackColor="White" ForeColor="#006600" />
                    </asp:Gridview>     
                </ContentTemplate>
            </asp:UpdatePanel>  
     
  • Re: FormView control disappears whenever I change it's mode in a collapsible panel?

    11-11-2008, 4:23 PM
    • Member
      8 point Member
    • benfinkel
    • Member since 04-04-2008, 2:26 PM
    • Posts 36

    Interestingly, when I add an 'Edit' button to the rows of the buried GridView it disappears as well.   What am I missing?

  • Re: FormView control disappears whenever I change it's mode in a collapsible panel?

    11-12-2008, 11:27 AM
    • Member
      8 point Member
    • benfinkel
    • Member since 04-04-2008, 2:26 PM
    • Posts 36

    The entire page appears to post-back, and the formview disappears entirely.  This is killing me! :)

  • Re: FormView control disappears whenever I change it's mode in a collapsible panel?

    11-12-2008, 3:25 PM
    • Member
      8 point Member
    • benfinkel
    • Member since 04-04-2008, 2:26 PM
    • Posts 36

    Getting closer.

     The Datasource for the FormView in each GridView row has to be manually bound based on the row it's in, which is done with a piece of C# code (see below).  When I commit the record and the page refreshes the C# code does not work because, for some reason, the Row.DataItem is null.  Getting closer

     

        protected void gvScreeningLog_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                SqlDataSource ctrl = e.Row.FindControl("sdsLogDetails") as SqlDataSource;
                if (ctrl != null && e.Row.DataItem != null)
                {
                    ctrl.SelectParameters["ScreeningWeekID"].DefaultValue = ((DataRowView)e.Row.DataItem)["ScreeningWeekID"].ToString();
                }
    
                ctrl = e.Row.FindControl("sdsWeekDetails") as SqlDataSource;
                if (ctrl != null && e.Row.DataItem != null)
                {
                    ctrl.SelectParameters["ScreeningWeekID"].DefaultValue = ((DataRowView)e.Row.DataItem)["ScreeningWeekID"].ToString();
                }
            }
        }
     
  • Re: FormView control disappears whenever I change it's mode in a collapsible panel?

    11-12-2008, 3:40 PM
    Answer
    • Member
      8 point Member
    • benfinkel
    • Member since 04-04-2008, 2:26 PM
    • Posts 36

    And I've corrected it by using the DataKey instead of reference the DataItem like so:

     

     

        protected void gvScreeningLog_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                SqlDataSource ctrl = e.Row.FindControl("sdsLogDetails") as SqlDataSource;
                int index = Convert.ToInt32(e.Row.RowIndex);
    
                if (ctrl != null)
                {
                    ctrl.SelectParameters["ScreeningWeekID"].DefaultValue = ((GridView)sender).DataKeys[index].Value.ToString();
                    
                }
    
                ctrl = e.Row.FindControl("sdsWeekDetails") as SqlDataSource;
                if (ctrl != null)
                {
                    ctrl.SelectParameters["ScreeningWeekID"].DefaultValue = ((GridView)sender).DataKeys[index].Value.ToString();
                }
            }
        }
     
Page 1 of 1 (5 items)