L
Laura K
I am having difficulty binding data to my datalist. The data list does
not show. I have gone round and round for two days. I could really
use some help looking through this code and seeing where the error is.
It is usually something simple but I just can not find it!!!
Any suggestion?
--------------------------------------------------------------------------
My HTML code is:
<aspataList id="DataList1" runat="server">
<HeaderTemplate>
This is the header
</HeaderTemplate>
<FooterTemplate>
This is the footer
</FooterTemplate>
<ItemTemplate>
<img src='../images/items/thumbes/<%#
DataBinder.Eval(Container.DataItem, "strImagePath") %>'>
This is a test
</ItemTemplate>
</aspataList>
------------------------------------------------------------------------------------
Code behind
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim BrandID As String = Request.QueryString("BrandID")
Dim CategoryID As String = Request.QueryString("CategoryID")
Dim strSubCategory As String =
Request.QueryString("StrSubCategory")
If Not CategoryID Is Nothing Then
DataList1.DataSource =
Catalog.GetSubCatProductsFromBrands(CategoryID, strSubCategory)
DataList1.DataBind()
Label.Text = "Category"
ElseIf Not BrandID Is Nothing Then
DataList1.DataSource =
Catalog.GetSubCatProductsFromBrands(strSubCategory, BrandID)
DataList1.DataBind()
Label.Text = "brands"
End If
End Sub
---------------------------------------------------------------------------
Datareader code in catalog class file
Public Shared Function GetSubCatProductsFromBrands(ByVal BrandID As
String, ByVal StrSubCategory As String) As SqlDataReader
'create the connection string
Dim connection As New SqlConnection(connectionString)
'Create and initialize the command Object
Dim command As New
SqlCommand("New_getSubCatProductsFromBrands", connection)
command.CommandType = CommandType.StoredProcedure
'Add an input parameter and suply a valiue for it
command.Parameters.Add("@brandID", SqlDbType.NVarChar, 5)
command.Parameters("@brandID").Value = BrandID
command.Parameters.Add("@StrSubCategory", SqlDbType.NVarChar,
50)
command.Parameters("@StrSubCategory").Value = StrSubCategory
Try
'open the connection
connection.Open()
'Return an SQLDataReader
Return
command.ExecuteReader(CommandBehavior.CloseConnection)
Catch e As Exception
'close the connection and throw the exception
connection.Close()
' Throw e
End Try
End Function
------------------------------------------------------------------
Stored proc is
( @BrandID NvarChar (5),
@StrSubCategory NvarChar (50)
)
As
Select intProductID, StrProductCode, StrProductName, curPrice,
strImagePath
from tblProducts
Where strBrandCode = @BrandID
and StrSubCategory = @strSubCategory
Return
HELP!!
TIA
Laura K
not show. I have gone round and round for two days. I could really
use some help looking through this code and seeing where the error is.
It is usually something simple but I just can not find it!!!
Any suggestion?
--------------------------------------------------------------------------
My HTML code is:
<aspataList id="DataList1" runat="server">
<HeaderTemplate>
This is the header
</HeaderTemplate>
<FooterTemplate>
This is the footer
</FooterTemplate>
<ItemTemplate>
<img src='../images/items/thumbes/<%#
DataBinder.Eval(Container.DataItem, "strImagePath") %>'>
This is a test
</ItemTemplate>
</aspataList>
------------------------------------------------------------------------------------
Code behind
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim BrandID As String = Request.QueryString("BrandID")
Dim CategoryID As String = Request.QueryString("CategoryID")
Dim strSubCategory As String =
Request.QueryString("StrSubCategory")
If Not CategoryID Is Nothing Then
DataList1.DataSource =
Catalog.GetSubCatProductsFromBrands(CategoryID, strSubCategory)
DataList1.DataBind()
Label.Text = "Category"
ElseIf Not BrandID Is Nothing Then
DataList1.DataSource =
Catalog.GetSubCatProductsFromBrands(strSubCategory, BrandID)
DataList1.DataBind()
Label.Text = "brands"
End If
End Sub
---------------------------------------------------------------------------
Datareader code in catalog class file
Public Shared Function GetSubCatProductsFromBrands(ByVal BrandID As
String, ByVal StrSubCategory As String) As SqlDataReader
'create the connection string
Dim connection As New SqlConnection(connectionString)
'Create and initialize the command Object
Dim command As New
SqlCommand("New_getSubCatProductsFromBrands", connection)
command.CommandType = CommandType.StoredProcedure
'Add an input parameter and suply a valiue for it
command.Parameters.Add("@brandID", SqlDbType.NVarChar, 5)
command.Parameters("@brandID").Value = BrandID
command.Parameters.Add("@StrSubCategory", SqlDbType.NVarChar,
50)
command.Parameters("@StrSubCategory").Value = StrSubCategory
Try
'open the connection
connection.Open()
'Return an SQLDataReader
Return
command.ExecuteReader(CommandBehavior.CloseConnection)
Catch e As Exception
'close the connection and throw the exception
connection.Close()
' Throw e
End Try
End Function
------------------------------------------------------------------
Stored proc is
( @BrandID NvarChar (5),
@StrSubCategory NvarChar (50)
)
As
Select intProductID, StrProductCode, StrProductName, curPrice,
strImagePath
from tblProducts
Where strBrandCode = @BrandID
and StrSubCategory = @strSubCategory
Return
HELP!!
TIA
Laura K