473,396 Members | 2,140 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

I need help with datagrid

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
Nov 19 '05 #1
2 1155
"student" <mr********@yahoo.com> wrote in message
news:ht*****************@newssvr17.news.prodigy.co m...
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
Nov 19 '05 #2
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.

--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"student" <mr********@yahoo.com> wrote in message
news:ht*****************@newssvr17.news.prodigy.co m...
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

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Junkguy | last post by:
I need some help programmatically causing a row in a DataGrid to "flush" its contents to its bound data (in Visual Studio 6 using Windows Forms with C#). My issue is I want to send an update to...
0
by: MrNobody | last post by:
I am desperately in need of some help to get a summary row for my DataGrid. A summary row is just a row always on the bottom which has totals for certain columns. I have been able to find...
1
by: ericm1155 | last post by:
I am trying to display some information from a database in a form that displays one record per line. When the user clicks anywhere on a line, that record is highlighted and selected, and my program...
5
by: Luis E Valencia | last post by:
I need a link on a datagrid, the link must have fields of the database Like this acciones.aspx?iddireccion=1&idindicador=4 Thanks
1
by: Jennyfer J Barco | last post by:
Hello again I have a datagrid and I'm showing many records. I need 2 things: I need that everytime they scroll down, the header stays lock so the user can see it all the time. I need to scroll...
1
by: Anna | last post by:
I have a simple DataGrid that displays a list of characteristics and allows you to edit a description for each characteristic. The query that feeds this involves a join, as the characteristics and...
10
by: Terry Olsen | last post by:
I've got a datagrid set up to display data. I've also got an Edit,Update,Cancel column set up to allow editing of data. I've got a DropDownList (ID="ddl3")in the EditItemTemplate for a certain...
21
by: coleenholley | last post by:
I've been trying since last Friday to get an answer on how to get a SPECIFIC row.cell value from a datagrid. I've had plenty of suggestions, but nothing works to get the value from a SPECIFIC Row...
3
by: Larry Woods | last post by:
I have a datagrid that is carrying all fields of a record...except one. Now I want to update the underlying database via a dataadapter. The update is working but the field that is "left out" is...
0
by: Familjen Karlsson | last post by:
Hi I have downloaded some code and tried it and nothing happens with the datagrid. Explain what is wrong and what I have to do please. I have tried to Import the namespace Hamster and it didn't...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.