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 5 1876
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 thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: ani |
last post by:
Hi,
I have a datalist control and within the Itemplate I
have a radiobuttonlist control . I am binding data to the
datalist control in Page_load . Also I have sqldatareader
object that needs...
|
by: .Net Sports |
last post by:
I am resurrecting an old script from a previous programmer, and want to
migrate it over to asp.net from classic asp. Tho there are other
peripheral parts of the script (that really have no bearing...
|
by: Laura K |
last post by:
Can someone tell me where I went wrong. This is my code for binding data to
a datalist.
<script language="vb">
Sub Page_Load(Src As Object, e As EventArgs)
Dim Con As New...
|
by: bbernieb |
last post by:
Hi, All,
Is it possible to access a variable inside of a data binding, without the
variable being out of scope?
(Note: On the DataBinder line, I get an error message that says "Name 'i' is...
|
by: Andrew Robinson |
last post by:
Is there any way to accomplish two way data binding in a Details View with a
DataSet or DataTable as the DataSource.
All I want is to get an updated DataSet or DataTable back from the...
|
by: Aaron |
last post by:
Howdy,
I have a datalist(datalist1) that is getting data from an xml
file(query1.xml)
Here is the layout of the xml file.
How do I binding the xml file to display all the supporters/name...
|
by: mosipenko |
last post by:
I used to have a problem with DBNull, but now my issue is:
System.InvalidOperationException: Invalid attempt to read when no data
is present
Here's my code behind:
Private Sub...
|
by: AleXmanFree |
last post by:
Hi, I have this kind of problem,
In my asp.net page i use DataList and user control that is repeated in
DataList.
This user control has in it a checkbox , so everytime user clicks on
checkbox...
|
by: diff |
last post by:
I am having trouble preventing a bound source from updating using event-driven validation.
There is a very nice article on MSDN explaining this;...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |