|
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:
<asp:DataList 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>
</asp:DataList>
------------------------------------------------------------------------------------
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.CloseConnect ion)
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 | |
Share:
|
looks like you have your return statement ahead of Execute reader in the class file.
put the return statement after the execution. --------------------------------------------------------------------------- Datareader code in catalog class file
............... Try 'open the connection connection.Open() 'Return an SQLDataReader Return command.ExecuteReader(CommandBehavior.CloseConnect ion) Catch e As Exception 'close the connection and throw the exception connection.Close() ' Throw e End Try
................... | | |
Actuall the line was broken up when the message posted. The following
text should all be on one line. I also use this text on other
datareaders and it works.
Return command.ExecuteReader(CommandBehavior.CloseConnect ion) | | |
On Wed, 28 Dec 2005 12:49:48 -0800, Laura K wrote: 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:
<asp:DataList 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> </asp:DataList> ------------------------------------------------------------------------------------ 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.CloseConnect ion) 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
Try to get the stuff to work from an array; data binding works with arrays
also. | | |
Can you give me some direction for that. Are there any tutorials out
there or can you give me some sample code.
Also I have been experimenting and have found that my stored proc is
not even being executed (I tested it by turning off execute
privileges). So the data is not even being passed to the procedure. | | |
Found my own error. I had commented out Throw e | | This discussion thread is closed Replies have been disabled for this discussion. Similar topics
reply
views
Thread by ani |
last post: by
|
1 post
views
Thread by .Net Sports |
last post: by
|
1 post
views
Thread by Laura K |
last post: by
|
3 posts
views
Thread by bbernieb |
last post: by
|
2 posts
views
Thread by Andrew Robinson |
last post: by
|
1 post
views
Thread by Aaron |
last post: by
|
15 posts
views
Thread by mosipenko |
last post: by
|
reply
views
Thread by AleXmanFree |
last post: by
| | | | | | | | | | | |