• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2371
  • Last Modified:

Adding rows to gridview programmatically.

I am trying to populate a gridview in asp.net 2 using vb. Below is what I have. It is not returning an error, but it is not displaying the results. Any assistance would be greatly appreciated.
Label1.Text = ""
        Label1.Text = EMailLogOptionsDropDownList.SelectedValue
        Dim EMailLogDataStoredProcedure As String
        Select Case EMailLogOptionsDropDownList.SelectedValue
            Case "1"
                EMailLogDataStoredProcedure = "usr_sel_EMailLog_BrokerAdministrationEMailLogOutput"
            Case "2"
                EMailLogDataStoredProcedure = "usr_sel_EMailLog_BrokerAdministrationEMailLogOutput_BrandedPageOwnerEMailOutput"
            Case "3"
                EMailLogDataStoredProcedure = "usr_sel_EMailLog_BrokerAdministrationEMailLogOutput_ManagerEmployeeEMailOutput"
        End Select

        Dim dt As New DataTable
        dt.Columns.Add("Sender", GetType(String))
        dt.Columns.Add("Recipient", GetType(String))
        dt.Columns.Add("Copied", GetType(String))
        dt.Columns.Add("Subject", GetType(String))
        dt.Columns.Add("Sent Date", GetType(DateTime))
       
        Dim BrokerEmail As String = BrokerEmail
        Dim EMailLogDataConnString As String = ConfigurationManager.AppSettings("****")
        Dim EMailLogDataConn As New SqlConnection(EMailLogDataConnString)
        Dim SQLEMailLogDataCmd As New SqlCommand(EMailLogDataStoredProcedure, EMailLogDataConn)
        Dim EMailLogData As SqlDataReader
        SQLEMailLogDataCmd.CommandType = CommandType.StoredProcedure
        SQLEMailLogDataCmd.Parameters.AddWithValue("@BrokerEMailAddress", BrokerEmail) 'Request.Cookies("BrokerEMailAddress").Value)
        SQLEMailLogDataCmd.Parameters.AddWithValue("@StartDate", StartDate.Text)
        SQLEMailLogDataCmd.Parameters.AddWithValue("@EndDate", EndDate.Text)
        EMailLogDataConn.Open()
        EMailLogData = SQLEMailLogDataCmd.ExecuteReader
        While EMailLogData.Read
            dt.Rows.Add(New Object() {EMailLogData("Sender"), EMailLogData("Recipient"), EMailLogData("Copied"), EMailLogData("Subject"), EMailLogData("SentDate")})
        End While
        GridView1.DataSource = dt
        GridView1.DataBind()

       Label1.Text = EMailLogDataStoredProcedure
        SQLEMailLogDataCmd.Dispose()
        SQLEMailLogDataCmd = Nothing
        EMailLogData.Close()
        EMailLogData = Nothing
        EMailLogDataConn.Close()
        EMailLogDataConn.Dispose()
        EMailLogDataConn = Nothing
        EMailLogDataConnString = Nothing
0
-cr-
Asked:
-cr-
  • 3
  • 2
1 Solution
 
RedKelvinCommented:
Hi,
Ensure that
While EMailLogData.Read
has actually got some data, otherwise there will be nothing to add to the grid
0
 
-cr-Author Commented:
I have executed the stored proc in SQL Server and it should be returning results.
0
 
RedKelvinCommented:
It should yes, but you are using parameters, it is always better to test at the program level.

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
-cr-Author Commented:
Yes when I am debugging I see the parameters being passed the same as I passed in sql server.
0
 
RedKelvinCommented:
just before binding the datatable to the grid, interrogate the number of rows in dt

dt.rows.count
0
 
GreymanMSCCommented:
Are you sure about that?  Because the following line declares a variable then initialises it with its declared value (which will be empty).  You later use it as a parameter value without setting it to anything else.  I really don't think it's doing what you think it should.

  Dim BrokerEmail As String = BrokerEmail
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now