I need help with datagrid

S

student

Hi all, I'm having trouble with my datagrid, it is suppose to display a row
from a table called "Calls" based on what is selected in the dropdownlist
which displays the first and last name from another table called "Contacts".
The problem is only the dropdownlist is showing in the browser and nothing
from the datagrid shows.
Could someone please point out my error, I am new at this, and would
appreciate some help.
thanks,
student
Here's the code:
Imports System.Data.SqlClient
Imports System.Data
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents SqlSelectCommand1 As
System.Data.SqlClient.SqlCommand
Protected WithEvents SqlInsertCommand1 As
System.Data.SqlClient.SqlCommand
Protected WithEvents SqlUpdateCommand1 As
System.Data.SqlClient.SqlCommand
Protected WithEvents SqlDeleteCommand1 As
System.Data.SqlClient.SqlCommand
Protected WithEvents SqlSelectCommand2 As
System.Data.SqlClient.SqlCommand
Protected WithEvents SqlInsertCommand2 As
System.Data.SqlClient.SqlCommand
Protected WithEvents SqlUpdateCommand2 As
System.Data.SqlClient.SqlCommand
Protected WithEvents SqlDeleteCommand2 As
System.Data.SqlClient.SqlCommand
Protected WithEvents ContactMgmt As System.Data.SqlClient.SqlConnection
Protected WithEvents adptCalls As System.Data.SqlClient.SqlDataAdapter
Protected WithEvents adptContacts As
System.Data.SqlClient.SqlDataAdapter
Protected WithEvents dsCalls As figure5_22.DataSet1
Protected WithEvents dsContacts As figure5_22.DataSet2
Protected WithEvents grdCalls As System.Web.UI.WebControls.DataGrid
Protected WithEvents drpContacts As
System.Web.UI.WebControls.DropDownList

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
'Run the first time the page is displayed.
If Not IsPostBack Then
'fill the contacts data set.
adptContacts.Fill(dsContacts)
'for each row in the table...
Dim drowItem As DataSet2.ContactsRow
For Each drowItem In dsContacts.Contacts
'create a new list item
Dim lstnew As New ListItem()
lstnew.Text = drowItem.FirstName & " " & drowItem.LastName
lstnew.Value = drowItem.ContactID
'add the list item to the drop-down list.
drpContacts.Items.Add(lstnew)
Next
End If
End Sub

Private Sub drpContacts_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
drpContacts.SelectedIndexChanged

'When a contact is selected, display the contact's calls
adptCalls.SelectCommand.CommandText = "SELECT * FROM Calls" & _
"WHERE ContactID =" & drpContacts.SelectedItem.Value
'Clear the data set.
dsCalls.Clear()
adptCalls.Fill(dsCalls)
'Display the results in a data grid.
grdCalls.DataBind()
End Sub
End Class
 
J

John Saunders

student said:
Hi all, I'm having trouble with my datagrid, it is suppose to display a
row
from a table called "Calls" based on what is selected in the dropdownlist
which displays the first and last name from another table called
"Contacts".
The problem is only the dropdownlist is showing in the browser and nothing
from the datagrid shows.
Could someone please point out my error, I am new at this, and would
appreciate some help.

Are you sure that the DataSource and DataMember are set in the datagrid? Are
you sure that the Fill is returning rows?

John Saunders
 
S

Saravana

In the page_load you are not binding datagrid itself. so it wont come in the
browser. If you want to bring the datagrid in the browser when page loads,
bind it with datasource filtered using default value of dropdownlist
selection.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top