Hi everyone,
I have got a DataList with two HyperLinks, they show the CompanyID and
Company name from the tCompany table in SQl Server. This page loads up
fine.
The DataBindings on Text Bindable Properties are
DataBinder.Eval(Container.DataItem,"CompanyID")
DataBinder.Eval(Container.DataItem, "Company")
However, I am trying to allow the user to click on a CompanyID link which
will let them view all the contacts for that specific CompanyID onto a
DataGrid. The contacts are held in a tContacts table which also contains
the CompanyId field. Instead of showing the specific contacs the whole
tContacts table is loaded onto the DataGrid.
In the 1st HyperLink (CompanyID) the Navigate URL Bindable properties are
Request.ServerVariables("script_name") & "?id=" &
DataBinder.Eval(Container.DataItem, "CompanyID")
Can anyone help and tell me why it is not working? Here's my code
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'connect to db
Dim connection As New SqlConnection(Global.DbString)
connection.open()
'retrieve the suppliers
Dim companyCommand As New SqlCommand("Select * from tCompany",
connection)
Dim companyReader As SqlDataReader = companyCommand.ExecuteReader
()
'bind the DataList to the SqlDataReader
lsttCompany.DataSource = companyReader
lsttCompany.DataBind()
'close the SqlReader and release the SqlCommand object
companyReader.Close()
companyCommand.Dispose()
'close the db connection
connection.Close()
Dim CompanyID As Integer = 0
connection.Open()
'If a supplier is selected...
If Not Request.Params("ID") Is Nothing Then
'...then gets its id
CompanyID = CInt(Request.Params("ID"))
'load their contact details
Dim contactsCommand As New SqlCommand("Select * from
tContacts where CompanyID=CompanyID", connection)
Dim contactsReader As SqlDataReader =
contactsCommand.ExecuteReader()
'bind the new SqlDataReader to the DataGrid
grdContacts.DataSource = contactsReader
grdContacts.DataBind()
'close the sqldatareader and release the sqlCommand object
contactsReader.Close()
contactsCommand.Dispose()
End If
'close the db connection
connection.Close()
End Sub
End Class
Thank you
Ajay