Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 1st, 2008, 04:49 PM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default ItemDataBound to Grid Within Repeater

Hi,

Any help with this is very much appreciated.

I have a datagrid within a repeater that is working fine. The problem that I'm having is that I need to add totals to the footer of the datagrid. You can see in the red code below what I have tried but on debugging it never enters the ItemDataBound Sub.

    Protected Sub btnSearch_OnClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnSearch.Click
        Try
            _oConn.Open()
            Dim SQL As String = "Some SQL Query;"
            Dim CMD As SqlCommand = New SqlCommand(SQL, _oConn)
            CMD.Parameters.AddWithValue("@InqStart", txtInqStart.Text)
            CMD.Parameters.AddWithValue("@InqFinish", txtInqFinish.Text)
            Dim oDA As New SqlDataAdapter(CMD)
            Dim oDS As New DataSet
            oDA.Fill(oDS)
            rptAgencyDetail.DataSource = oDS
            rptAgencyDetail.DataBind()
        Catch ex As Exception
            Session("AlertPass") = False
            Session("AlertText") = ex.Message
        Finally
            _oConn.Close()
        End Try
    End Sub

    Protected Sub rptAgencyDetail_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) Handles rptAgencyDetail.ItemDataBound
        Try
            _oConn.Close()
            If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
                Dim grdInquiryDetails As DataGrid = e.Item.FindControl("grdInquiryDetails")
                Dim SQL As String = "Some SQL Query;"
                Dim oDA As New SqlDataAdapter(SQL, _oConn)
                Dim oDS As New DataSet
                oDA.Fill(oDS)
                grdInquiryDetails.DataSource = oDS
                grdInquiryDetails.DataBind()
                AddHandler grdInquiryDetails.ItemDataBound, AddressOf grdInquiryDetails_ItemDataBound
            End If
        Catch ex As Exception
            Session("AlertPass") = False
            Session("AlertText") = ex.Message
        Finally
            DBCount = 0

        End Try
    End Sub

    Protected Sub grdInquiryDetails_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles grdInquiryDetails.ItemDataBound
        If e.Item.ItemType = ListItemType.Footer Then
            e.Item.Cells(0).Text = grdInquiryDetails.Items.Count
        End If
    End Sub

Anybody got any ideas? Sure would be appreciated.

Thank you,
Richard

  #2 (permalink)  
Old July 1st, 2008, 04:51 PM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Hi,

Sorry I didn't mention this but I had to Dim the Datagrid outside of the Subs to add the WithEvents property:


    Protected WithEvents grdInquiryDetails As DataGrid

Thanks,
Richard

  #3 (permalink)  
Old July 1st, 2008, 06:16 PM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Hey. I got it. I got rid of the declaration of the grid withevents and the Handles grdInquiryDetails.ItemDataBound.

I added this to the attributes on the aspx page:

 OnItemDataBound="grdInquiryDetails_ItemDataBound"

And I left the AddHandler line in.

Thanks,
Richard

  #4 (permalink)  
Old July 9th, 2008, 01:24 AM
Registered User
 
Join Date: Jul 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your helpful resource.....

Quote:
quote:Originally posted by rstelma
 Hi,

Sorry I didn't mention this but I had to Dim the Datagrid outside of the Subs to add the WithEvents property:


    Protected WithEvents grdInquiryDetails As DataGrid

Thanks,
Richard

:)

Chandan
Imfinity India Pvt. Ltd.
  #5 (permalink)  
Old July 9th, 2008, 02:45 AM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

You're welcome. Wish I could fix all of my problems as easily.

Richard



Similar Threads
Thread Thread Starter Forum Replies Last Post
Datagrid ItemDataBound Event Problem Grahame2003 C# 1 December 3rd, 2011 03:10 AM
Confirm in ItemDataBound rstelma ASP.NET 1.0 and 1.1 Basics 3 December 6th, 2006 02:10 AM
Datagrid ItemDataBound column widht eresina ASP.NET 1.0 and 1.1 Basics 0 August 10th, 2005 04:42 AM
DataGrid ItemDataBound Wyatt70 ADO.NET 2 November 22nd, 2004 03:31 PM
Repeater collie VB.NET 2002/2003 Basics 1 December 2nd, 2003 05:30 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.