-cr-
asked on
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 = EMailLogOptionsDropDownLis t.Selected Value
Dim EMailLogDataStoredProcedur e As String
Select Case EMailLogOptionsDropDownLis t.Selected Value
Case "1"
EMailLogDataStoredProcedur e = "usr_sel_EMailLog_BrokerAd ministrati onEMailLog Output"
Case "2"
EMailLogDataStoredProcedur e = "usr_sel_EMailLog_BrokerAd ministrati onEMailLog Output_Bra ndedPageOw nerEMailOu tput"
Case "3"
EMailLogDataStoredProcedur e = "usr_sel_EMailLog_BrokerAd ministrati onEMailLog Output_Man agerEmploy eeEMailOut put"
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.AppSe ttings("** **")
Dim EMailLogDataConn As New SqlConnection(EMailLogData ConnString )
Dim SQLEMailLogDataCmd As New SqlCommand(EMailLogDataSto redProcedu re, EMailLogDataConn)
Dim EMailLogData As SqlDataReader
SQLEMailLogDataCmd.Command Type = CommandType.StoredProcedur e
SQLEMailLogDataCmd.Paramet ers.AddWit hValue("@B rokerEMail Address", BrokerEmail) 'Request.Cookies("BrokerEM ailAddress ").Value)
SQLEMailLogDataCmd.Paramet ers.AddWit hValue("@S tartDate", StartDate.Text)
SQLEMailLogDataCmd.Paramet ers.AddWit hValue("@E ndDate", EndDate.Text)
EMailLogDataConn.Open()
EMailLogData = SQLEMailLogDataCmd.Execute Reader
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 = EMailLogDataStoredProcedur e
SQLEMailLogDataCmd.Dispose ()
SQLEMailLogDataCmd = Nothing
EMailLogData.Close()
EMailLogData = Nothing
EMailLogDataConn.Close()
EMailLogDataConn.Dispose()
EMailLogDataConn = Nothing
EMailLogDataConnString = Nothing
Label1.Text = ""
Label1.Text = EMailLogOptionsDropDownLis
Dim EMailLogDataStoredProcedur
Select Case EMailLogOptionsDropDownLis
Case "1"
EMailLogDataStoredProcedur
Case "2"
EMailLogDataStoredProcedur
Case "3"
EMailLogDataStoredProcedur
End Select
Dim dt As New DataTable
dt.Columns.Add("Sender", GetType(String))
dt.Columns.Add("Recipient"
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.AppSe
Dim EMailLogDataConn As New SqlConnection(EMailLogData
Dim SQLEMailLogDataCmd As New SqlCommand(EMailLogDataSto
Dim EMailLogData As SqlDataReader
SQLEMailLogDataCmd.Command
SQLEMailLogDataCmd.Paramet
SQLEMailLogDataCmd.Paramet
SQLEMailLogDataCmd.Paramet
EMailLogDataConn.Open()
EMailLogData = SQLEMailLogDataCmd.Execute
While EMailLogData.Read
dt.Rows.Add(New Object() {EMailLogData("Sender"), EMailLogData("Recipient"),
End While
GridView1.DataSource = dt
GridView1.DataBind()
Label1.Text = EMailLogDataStoredProcedur
SQLEMailLogDataCmd.Dispose
SQLEMailLogDataCmd = Nothing
EMailLogData.Close()
EMailLogData = Nothing
EMailLogDataConn.Close()
EMailLogDataConn.Dispose()
EMailLogDataConn = Nothing
EMailLogDataConnString = Nothing
ASKER
I have executed the stored proc in SQL Server and it should be returning results.
It should yes, but you are using parameters, it is always better to test at the program level.
ASKER
Yes when I am debugging I see the parameters being passed the same as I passed in sql server.
just before binding the datatable to the grid, interrogate the number of rows in dt
dt.rows.count
dt.rows.count
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ensure that
While EMailLogData.Read
has actually got some data, otherwise there will be nothing to add to the grid