Results 1 to 7 of 7
  1. #1
    Lounger
    Join Date
    May 2006
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    One more quirky nested grid problem (vb.net 2.0)

    At last I have finally broken through on the nested datagrid pages that I have been working on. I do however have one hiccup related to the child grid's footer. I want to put a simple link into the footer section of the child datagrid (i.e. "add subcategory") that will link to something like newsubcategory.aspx?id=xx where xx is the ID of the category that the new subcategory will be associated with. Since the footer is not on the same "level" of heirarchy as the individual items, my attempts at using
    <%#Container.DataItem("CategoryID")%>
    to spit out the category ID on the front-end form do no good... not sure what the error was exactly, but it mumbled something that was closely related to the "container".
    How exactly could I get the category ID into the child grid's footer? I could list it within the grid itself, but then the value would have to be pulled out of one of the rows of the data grid or something... and there's no guarantee that there will be rows in the grid anyway.

    your guidance is much appreciated [img]/forums/images/smilies/smile.gif[/img]

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: One more quirky nested grid problem (vb.net 2.0)

    Can you post the relevant code so it will be easier to provide a specific answer to this issue?

  3. #3
    Lounger
    Join Date
    May 2006
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: One more quirky nested grid problem (vb.net 2.0)

    Currently, here is what my datagrid looks like... basically one datagrid with another datagrid inside, named "innergrid" and "outergrid":


    <aspataGrid runat="server" ID="outergrid" AutoGenerateColumns="false" ShowFooter="true" CssClass="OuterActivityGrid" OnItemCommand="outergrid_buttonClicked" >
    <Columns>
    <asp:BoundColumn DataField="ActivityGroupID" ReadOnly="true" Visible="false" />

    <asp:templatecolumn ItemStyle-HorizontalAlign="left" ItemStyle-VerticalAlign="top" FooterStyle-CssClass="parentFooter">
    <ItemTemplate>
    <asp:label ID="ActivityGroupIDLabel" visible="false" runat="server"><%#Container.DataItem("ActivityGrou pID")%></asp:label>
    <%#Container.DataItem("Name")%>
    </ItemTemplate>
    <FooterTemplate>
    <asp:TextBox ID="ActivityGroupNameTBox" runat="server" />
    <asp:Button CommandName="add" Text="Add" ID="btnAdd" Runat="server" />
    </FooterTemplate>
    </asp:templatecolumn>

    <asp:TemplateColumn ItemStyle-VerticalAlign="top">
    <ItemTemplate>
    <asp:imagebutton CommandName="delete" ImageUrl="../images/delete.jpg" ID="deleteButton" Runat="server" ImageAlign="top" />
    </ItemTemplate>
    </asp:TemplateColumn>

    <asp:ButtonColumn ButtonType="linkButton" Text="[img]../images/up_arrow.gif[/img]" CommandName="moveUp" ItemStyle-VerticalAlign="top" />
    <asp:ButtonColumn ButtonType="linkbutton" Text="[img]../images/down_arrow.gif[/img]" CommandName="moveDown" ItemStyle-VerticalAlign="top" />
    <asp:TemplateColumn ItemStyle-HorizontalAlign="left" ItemStyle-CssClass="InnerActivityGrid">
    <ItemTemplate>
    <aspataGrid ID="innerGrid" runat="server" AutoGenerateColumns="false" ItemStyle-horizontalalign="left" ShowHeader="false" ShowFooter="true" OnItemCommand="innergrid_buttonClicked" OnItemDataBound="innergrid_itemdatabound">
    <Columns>
    <asp:BoundColumn DataField="ActivityID" ReadOnly="true" Visible="false" />
    <asp:BoundColumn DataField="ActivityGroupID" ReadOnly="true" Visible="false" />
    <asp:TemplateColumn>
    <itemtemplate>
    "><%#Container.DataItem("Name")%>
    </itemtemplate>
    <FooterTemplate>
    THIS IS WHERE MY LINK NEEDS TO GO
    </FooterTemplate>
    </asp:TemplateColumn>

    <asp:TemplateColumn ItemStyle-VerticalAlign="top">
    <ItemTemplate>
    <asp:imagebutton CommandName="deleteChild" ImageUrl="../images/delete.jpg" ID="deleteChildButton" Runat="server" ImageAlign="top" />
    </ItemTemplate>
    </asp:TemplateColumn>

    <asp:ButtonColumn ButtonType="linkButton" Text="[img]../images/up_arrow.gif[/img]" CommandName="moveChildUp" ItemStyle-VerticalAlign="top" />
    <asp:ButtonColumn ButtonType="linkbutton" Text="[img]../images/down_arrow.gif[/img]" CommandName="moveChildDown" ItemStyle-VerticalAlign="top" />

    </Columns>
    </aspataGrid>
    </ItemTemplate>
    </asp:TemplateColumn>

    </Columns>
    </aspataGrid>



    Notice "THIS IS WHERE MY LINK NEEDS TO GO"-- this is where I need to put a link such as newpage.aspx?id=xx and xx has to be the ID of the "Activity Group" in which we are working, i.e. the associated row in the parent grid. Normal methods will not work since the footer is evidently not associated with the datasource?


    And here is some code. This subroutine is fired by page_load


    Sub BindData()
    Dim categorySQL As String = "select * from tblActivityGroups where ConferenceID = " & Request.QueryString("id") & " order by Rank asc"
    ' Dim activitySQL As String = "select * FROM tblActivities order by Rank asc"
    Dim activitySQL As String = "select * from tblActivities where ActivityID in (select ActivityID FROM (tblConferences INNER JOIN tblActivityGroups ON tblConferences.ConferenceID = tblActivityGroups.ConferenceID) INNER JOIN tblActivities ON tblActivityGroups.ActivityGroupID = tblActivities.ActivityGroupID where tblConferences.ConferenceID=" & Request.QueryString("id") & " ) order by Rank asc"

    Dim myCatCommand As New OleDbCommand(categorySQL, myConnection)
    Dim myCatDA As New OleDbDataAdapter(myCatCommand)

    Dim myActCommand As New OleDbCommand(activitySQL, myConnection)
    Dim myActDA As New OleDbDataAdapter(myActCommand)

    Try
    myConnection.Open()
    myCatDA.Fill(CatActivitiesDS, "tblActivityGroups")
    myActDA.Fill(CatActivitiesDS, "tblActivities")
    Catch ex As Exception
    Finally
    myConnection.Close()
    End Try

    outergrid.DataSource = CatActivitiesDS.Tables("tblActivityGroups")
    outergrid.DataBind()

    End Sub



    and the parent grid's databound event

    Protected Sub outergrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles outergrid.ItemDataBound
    If e.Item.ItemType = ListItemType.Header Then
    e.Item.Cells(1).HorizontalAlign = HorizontalAlign.Left
    e.Item.Cells(1).Text = "Conference Activities"
    End If

    If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
    Dim deleteButton As ImageButton = CType(e.Item.FindControl("deleteButton"), ImageButton)
    deleteButton.Attributes.Add("onclick", "if(confirm('Are you sure you want to delete this Activity Group?')){}else{return false}")

    'Find out the CategoryID, filter the data
    Dim CatID As Integer = e.Item.DataItem("ActivityGroupID")
    Dim filteredActivities As DataView = CatActivitiesDS.Tables("tblActivities").DefaultVie w
    filteredActivities.RowFilter = "ActivityGroupID=" & CatID

    'Bind the Data to the DataGrid
    Dim child As DataGrid
    child = e.Item.FindControl("innerGrid")
    child.DataSource = filteredActivities
    child.DataBind()
    End If

    If e.Item.ItemType = ListItemType.Footer Then
    End If
    End Sub



    and the child grid's databound event

    Sub innergrid_itemdatabound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
    If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
    Dim deleteChildButton As ImageButton = CType(e.Item.FindControl("deleteChildButton"), ImageButton)
    deleteChildButton.Attributes.Add("onclick", "if(confirm('Are you sure you want to delete this Activity?')){}else{return false}")
    End If

    If e.Item.ItemType = ListItemType.Footer Then
    'e.Item.Cells(2).Text = "Add Activity" & e.Item.DataItem("ActivityGroupID").ToString & ""

    End If
    End Sub



    Hope that gives you an idea of what is going on. Really it is a lot like the example I posted earlier-- I just don't know how to get the queried ID number into the footer.
    Thanks for the help

  4. #4
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: One more quirky nested grid problem (vb.net 2.0)

    Looks like you're on the right track.

    All you need to do is create a label (or some other) control in the footer. Also, create a variable at the top of the ItemDataBound method (Dim categoryId as Integer). Assign the CatID to that variable. Then, in the "If e.Item.ItemType = ListItemType.Footer Then" line, you can use FindControl method to locate and set the value of the control in the Footer.

    Hope this helps..

  5. #5
    Lounger
    Join Date
    May 2006
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: One more quirky nested grid problem (vb.net 2.0)

    OK, here's what my child grid itemdatabound event looksl ike...

    Sub innergrid_itemdatabound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
    Dim ActivityGroupID As String = "" '??
    If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
    Dim deleteChildButton As ImageButton = CType(e.Item.FindControl("deleteChildButton"), ImageButton)
    deleteChildButton.Attributes.Add("onclick", "if(confirm('Are you sure you want to delete this Activity?')){}else{return false}")
    End If

    If e.Item.ItemType = ListItemType.Footer Then
    Dim footerLabel As Label = CType(e.Item.FindControl("footerLabel"), Label)
    footerLabel.Text = "This is a link." & ActivityGroupID
    End If
    End Sub

    and as you would assume, footerLabel is a label in the child grid's footer
    The only problem is, how do I assign the category ID to this variable...? I took a stab at it and tried e.item.dataitem("ActivityGroupID") and it tells me
    Object variable or With block variable not set.

    Hmm...

  6. #6
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: One more quirky nested grid problem (vb.net 2.0)

    I think I misunderstood from your last post where the CategoryId (same as ActivityGroupId, right?) was coming from.

    It appears that the CategoryId is coming from the parent-level record, right? If so, then you'll need to declare the ActivityGroupId variable at the page-level and not within the ItemDataBound method. This means that you'll want to place "Private ActivityGroupId as String" somewhere below the Class declaration and NOT within any method. That way, it will be accessible by any method or property within the class.

    You'll want to assign this value in the ItemDataBound method of the Parent item (assuming that's where the data is coming from). Then you can access it from the ItemDataBound method of the child grid. Keep in mind that it will be reassigned for each parent item that is generated. However, since the child ItemDataBound is called immediately after the Parent ItemDataBound, it should always be the correct value.

    Hope this helps.

  7. #7
    Lounger
    Join Date
    May 2006
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: One more quirky nested grid problem (vb.net 2.0)

    Ah ha. I had not thought of that, and you are most correct, it works great. Muchos thanks for the help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •