Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeUsing DNN Platf...Using DNN Platf...Administration ...Administration ...Rowcommand bluesRowcommand blues
Previous
 
Next
New Post
1/6/2009 11:15 AM
 

I am creating a search module.  The basic module has a text box (where the user can type in the search criteria) and combos after which results are displayed in a gridview.

The gridview is set up to include a child gridview in a template field.  The child gridview should display data only when selecting the row on the parent grid.  I have code in the rowcommand event handler for the parent grid to bind the child gridview's datasource to the selected row's datakeyname.

I am quite new to ASP.Net so maybe there are obvious issues with my code (please bare with me)  Here are the issues I am battling with:

1)  The rowcommand event handler only fires (predictably) when I'm logged in as Host.  As this is a public search grid, I want any user (logged in or not) to be able to search the grid. 

2)  When I do log in as Host, the parent data loads without problem.  When I click on any of the parent rows for the FIRST time, every child grid for every parent row becomes visible, except for the one that I clicked on.  I have a suspision that the events are firing twice on the first click (because I have code that says "childgrd.visible = not childgrd.visible" to toggle the visibility based on the user's click)

3) (Last issue)  Every time I click a parent item, each child grid (that is displayed at that point) shows the child data for the last selected parent row.  I.e. if I have a parent grid that lists store names and a child grid that shows address data and I click on store 1, then the child grid becomes visible showing store 1's data.  Then I click on store 2.  The child grid below store 2 is displayed showing store 2 address data, however, the child grid under store 1 now also shows address data for store 2

I have been looking through the code for hours and I'm either misunderstanding the entire setup or I'm looking over my own stupid mistake.  If anyone can assist, I would appreciate it.

Below my code:

<tr>
<td>

<asp:GridView ID="GridViewMainListing" runat="server" Width="100%"
AutoGenerateColumns="False" DataKeyNames="ResultsListingItemId"
DataSourceID="ObjectDataSource_MainListing"
CssClass="NestedGridView1Style"
OnRowCommand="GridViewMainListing_RowCommand">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ToolTip="Click here to see the hours" Text="Select" runat="server" ID="btnSelect" CommandName="Select"></asp:Button>
<!--<asp:CommandField ShowSelectButton="True" ButtonType="Button"><ItemStyle Width="10%" /></asp:CommandField>-->
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
<table cellpadding="2" cellspacing="0" border="0" width="100%" align="left">
<!-- this row has the Header-->
<tr>
 <td width="25%">
Name
</td>
<td width="25%">
Centre / Street
</td>
<td width="20%">
Contact No
</td>
<td width="20%">
Suburb
</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table border="0" cellpadding="2" cellspacing="0" width="100%" align="left">
<!-- this row has the parent grid -->
<tr>
<td width="25%">
<asp:Label ID="lblCompanyName" runat="server" Text='<%# Eval("ResultsListingName") %>'></asp:Label>
</td>
<td width="25%">
<asp:Label ID="lblCity" runat="server" Text='<%# Eval("ResultsListingCentreOrStreet") %>'></asp:Label>
</td>
<td width="20%">
<asp:Label ID="lblCountry" runat="server" Text='<%# Eval("ResultsListingContactNo") %>'></asp:Label>
</td>
<td width="20%">
<asp:Label ID="lblSuburb" runat="server" Text='<%# Eval("ResultsListingSuburb") %>'></asp:Label>
</td>
</tr>
<!-- this row has the child grid-->
<tr>
<td colspan="4">
<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr>
<!-- this cell has the list of hours for the selected listing -->
<td>

<asp:GridView ID="GridviewDetail" runat="server" DataKeyNames="ResultsDetailItemId" Visible="True"
DataSourceID="ObjectDataSource_DetailListing" AutoGenerateColumns="False"
CssClass="GridView1ChildStyle"
Width="90%"
HorizontalAlign="Right">
<HeaderStyle CssClass="Header" />
<Columns>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:Label ID="lblResultsDescription" Width="50%" runat="server" Text='<%# Eval("ResultsDescription") %>'></asp:Label>
<!--<asp:Label ID="Label3" Width="50%" runat="server" Text='<%#Bind("ResultsDescription") %>'></asp:Label>-->
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Hours">
<ItemTemplate>
<asp:Label ID="lblResultsHours" Width="50%" runat="server" Text='<%# Eval("ResultsHours") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
 
<asp:ObjectDataSource ID="ObjectDataSource_DetailListing" runat="server"
OldValuesParameterformatString="original_{0}"
SelectMethod="GetLSTResultsDetail" TypeName="PracticalComforts.Modules.LSTResults.LSTResultsController" >
<SelectParameters>
<asp:ControlParameter ControlID="GridViewMainListing" Name="ResultsListingItemId" PropertyName="SelectedDataKey.Values[0]" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
 
</asp:GridView>
<br />
&nbsp;&nbsp;
<br />
<td>
</tr>

-----------------------------------------------------------------------------------------------------------------------------------------------------------

 

Herewith the code behind:

 

  Protected Sub GridViewMainListing_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridViewMainListing.RowCommand

            'variables
            Dim gv As GridView = DirectCast(sender, GridView)
            Dim rowIndex As Integer = e.CommandArgument

            Select Case e.CommandName
                Case "Select"
                    Dim childgv As GridView = DirectCast(gv.Rows(rowIndex).FindControl("GridviewDetail"), GridView)
                    If Not childgv Is Nothing Then
                        'visibility of child grid
                        childgv.Visible = Not childgv.Visible

                        'refresh the data source
                        Dim odsHours As ObjectDataSource = DirectCast(gv.Rows(rowIndex).FindControl("ObjectDataSource_DetailListing"), ObjectDataSource)
                        odsHours.SelectParameters("ResultsListingItemId").DefaultValue = gv.DataKeys(rowIndex)(0).ToString

                    End If
            End Select

        End Sub

        Protected Sub GridViewMainListing_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridViewMainListing.RowDataBound

            If e.Row.RowType = DataControlRowType.DataRow Then

                'set the command argument
                Dim btnSelect As Button = e.Row.Cells(0).FindControl("btnSelect")
                btnSelect.CommandArgument = e.Row.RowIndex.ToString
            End If

        End Sub

 
New Post
1/12/2009 2:08 AM
 

First off, allow me to start by thanking Phillip Williams of Web Software Applications (www.webswapp.com) who has helped me tremendously with most of the issues that I have experienced above.

He helped me solve two of my problems:

2)  When I do log in as Host, the parent data loads without problem.  When I click on any of the parent rows for the FIRST time, every child grid for every parent row becomes visible, except for the one that I clicked on.  I have a suspision that the events are firing twice on the first click (because I have code that says "childgrd.visible = not childgrd.visible" to toggle the visibility based on the user's click)

3) (Last issue)  Every time I click a parent item, each child grid (that is displayed at that point) shows the child data for the last selected parent row.  I.e. if I have a parent grid that lists store names and a child grid that shows address data and I click on store 1, then the child grid becomes visible showing store 1's data.  Then I click on store 2.  The child grid below store 2 is displayed showing store 2 address data, however, the child grid under store 1 now also shows address data for store 2

I am still unsure how problem number 2 got resolved, but I have pasted my code below with the changes.  Problem number 3 was resolved by changing the parameter of the object datasource that populated the child grid.

As for problem number 1 (as mentioned in my original post), I will be logging this as a seperate issue in the DotNetNuke forums as I don't think it is related to my code.  I have also got more information as to exactly when the behaviour occurs and want to isolate that issue from this post.

Below my code:

<table>
    <tr>
        <td>
            <asp:Label ID="Label1" runat="server" Enablev13wstat3="false" CssClass="ErrMessage"></asp:Label>
            <br />
            <asp:ValidationSummary ID="valSumm" runat="server" ShowMessageBox="true" ShowSummary="false"  />
            <br />
        </td>
    </tr>
    <tr>
        <td>
            <asp:GridView ID="GridviewMainListing"
            runat="server"
            AllowPaging="True"
            DataKeyNames="ResultsListingItemId"
            DataSourceID="odsMainListing"
            AutoGenerateColumns="False"
            CssClass="NestedGridView1Style">
            <SelectedRowStyle CssClass="Green" />
            <HeaderStyle CssClass="Pink" />
            <Columns>
                <asp:ButtonField ButtonType="Button" CommandName="Select" Text="View" />
                <asp:TemplateField>
                    <HeaderTemplate>
                        <table cellpadding="2" cellspacing="0" border="0" width="100%" align="left">
                            <!-- this row has the parent grid -->
                            <tr>
                                    <td width="25%">
                                        Name
                                    </td>
                                    <td width="30%">
                                        Centre/Street
                                    </td>
                                    <td width="25%">
                                        Contact No
                                    </td>
                                    <td width="20%">
                                        Suburb
                                    </td>
                            </tr>
                        </table>
                    </HeaderTemplate>
                    <ItemTemplate>               
                        <table border="0" cellpadding="2" cellspacing="0" width="100%">
                            <!-- this row has the parent grid -->
                            <tr>
                                <td width="25%">
                                    <asp:Label ID="lblListingName" runat="server" Text='<%# Eval("ResultsListingName") %>'></asp:Label>
                                </td>
                                <td width="30%">
                                    <asp:Label ID="lblListingCentreorStreet" runat="server" Text='<%# Eval("ResultsListingCentreOrStreet") %>'></asp:Label>
                                </td>
                                <td width="25%">
                                    <asp:Label ID="lblListingContactNumber" runat="server" Text='<%# Eval("ResultsListingContactNo") %>'></asp:Label>
                                </td>
                                <td width="20%">
                                    <asp:Label ID="lblListingSuburb" runat="server" Text='<%# Eval("ResultsListingSuburb") %>'></asp:Label>
                                </td>
                            </tr>
                            <!-- this row has the child grid and its details view-->
                            <tr>
                                <td colspan="3" >
                                    <table border="0" cellpadding="3" cellspacing="0" width="100%" >
                                        <tr>
                                            <!-- this cell has the list of orders for the selected customer -->
                                            <td align="right">
                                                    <asp:GridView ID="ChildGridviewMainListing"
                                                    runat="server"
                                                    DataKeyNames="ResultsDetailItemId"
                                                    Visible="False"
                                                    DataSourceID="odsHours"
                                                    AutoGenerateColumns="False"
                                                    CssClass="GridView1ChildStyle"
                                                    Width="90%">
                                                    <HeaderStyle CssClass="Header" />
                                                    <Columns>
                                                        <asp:TemplateField HeaderText="Description">
                                                            <ItemTemplate>
                                                                <asp:Label ID="lblResultsDescription" runat="server" Text='<%# Bind("ResultsDescription") %>'></asp:Label>
                                                            </ItemTemplate>
                                                        </asp:TemplateField>
                                                        <asp:TemplateField HeaderText="Hours">
                                                            <ItemTemplate>
                                                                <asp:Label ID="lblResultsHours" runat="server" Text='<%# Bind("ResultsHours") %>'></asp:Label>
                                                            </ItemTemplate>
                                                        </asp:TemplateField>
                                                    </Columns>
                                                </asp:GridView>
                                            </td>
                                            <!--This cell has the order detail -->
                                        </tr>
                                    </table>
                                    <asp:ObjectDataSource ID="odsHours"
                                    runat="server"
                                    SelectMethod="GetLSTResultsDetail"
                                    TypeName="PracticalComforts.Modules.LSTResults.LSTResultsController"
                                    OldValuesParameterformatString="original_{0}">
                                        <SelectParameters>
                                            <asp:Parameter  Name="ResultsListingItemId" Type="Int32" />
                                        </SelectParameters>
                                    </asp:ObjectDataSource>
                                </td>
                            </tr>
                        </table>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            </asp:GridView>
            <asp:ObjectDataSource ID="odsMainListing"
            runat="server"
            SelectMethod="GetLSTResultsMain"
            TypeName="PracticalComforts.Modules.LSTResults.LSTResultsController"
            OldValuesParameterformatString="original_{0}">
            </asp:ObjectDataSource>           
        </td>
    </tr>
</table>

Thanks again Phillip!

Michelle

 
New Post
1/13/2009 12:23 AM
Accepted Answer 

In case anyone wondered, problem number 1 was the cache setting on the module, I set it to 0 and the issue was resolved.

Thanks to William Severance for helping me with that!

 
Previous
 
Next
HomeHomeUsing DNN Platf...Using DNN Platf...Administration ...Administration ...Rowcommand bluesRowcommand blues


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out