PC Review


Reply
Thread Tools Rate Thread

Data not binding to datalist

 
 
Laura K
Guest
Posts: n/a
 
      28th Dec 2005
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

 
Reply With Quote
 
 
 
 
Jon Paal
Guest
Posts: n/a
 
      28th Dec 2005
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.CloseConnection)
> Catch e As Exception
> 'close the connection and throw the exception
> connection.Close()
> ' Throw e
> End Try
>

...................


 
Reply With Quote
 
 
 
 
Laura K
Guest
Posts: n/a
 
      28th Dec 2005
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.CloseConnection)

 
Reply With Quote
 
intrader
Guest
Posts: n/a
 
      28th Dec 2005
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:
>
> <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

Try to get the stuff to work from an array; data binding works with arrays
also.

 
Reply With Quote
 
Laura K
Guest
Posts: n/a
 
      29th Dec 2005
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.

 
Reply With Quote
 
Laura K
Guest
Posts: n/a
 
      29th Dec 2005
Found my own error. I had commented out Throw e

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
100K item data binding: Is asynchronous data binding possible? R Reyes Microsoft C# .NET 14 5th Feb 2008 10:47 PM
binding XML data to the datalist control buran Microsoft ASP .NET 0 28th Apr 2005 07:58 AM
Problem binding data to datalist Laura K Microsoft ASP .NET 1 26th Mar 2005 03:30 AM
Datalist - How do I make a specific item in a datalist not able to =?Utf-8?B?R3JhZW1l?= Microsoft Dot NET 0 10th Feb 2005 05:29 AM
Setting up a datalist control - Item_DataBound for a datalist in a datalist Nevyn Twyll Microsoft ASP .NET 8 9th Sep 2004 11:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:54 PM.