Subject: datalist not displaying.. help me please
Posted By: sarah lee Post Date: 8/30/2006 8:25:23 AM
i have 2 pages
page1.aspx

--> i have a datalist with an image control and a hyperlink.
i m trying to display
item picture-->in image control
ID          ---> in hyperlink

my aim is that
ID-->onclick-->navigate to page2.aspx(page2.aspx contains details of the item)

when the ID get passed to page2.aspx, i want to display the details of that particular item

i have set the datsource and datamember in the datalist properties and have the follwng code.

HTML

<body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
            <asp:datalist id="DataList1" style="Z-INDEX: 101; LEFT: 104px; POSITION: absolute; TOP: 128px"
                runat="server" RepeatDirection="Horizontal" CellSpacing="3" CellPadding="3" RepeatColumns="3"
                Width="488px" BorderColor="White" BorderStyle="Ridge" BackColor="White" BorderWidth="1px"
                Height="247px" DataSource="<%# DataSet11 %>" DataMember="Items">
                <SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#9471DE"></SelectedItemStyle>
                <HeaderTemplate>
                    CHOOSE YOUR PRODUCT
                </HeaderTemplate>
                <FooterStyle ForeColor="Black" BackColor="#C6C3C6"></FooterStyle>
                <SeparatorStyle BorderColor="#400040"></SeparatorStyle>
                <ItemStyle HorizontalAlign="Center" Height="2px" ForeColor="Black" BorderColor="#400040" Width="200px"
                    BackColor="#DEDFDE"></ItemStyle>
                <ItemTemplate>
                    <P>
                        <asp:Image id=Image1 runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataItem,"Image")%>'>
                        </asp:Image>
                    <P>
                        <asp:HyperLink id=HyperLink1 Runat="server" text= '<%# DataBinder.Eval(Container.DataItem,"[ID]".tostring()) %>' NavigateUrl='<%# "page2.aspx?id="  & server.UrlEncode(Container.DataItem("[ID]"))%>'/>
                        </asp:HyperLink></P>
                    <P>&nbsp;</P>
                </ItemTemplate>
                <HeaderStyle Font-Bold="True" ForeColor="#E7E7FF" BorderColor="Maroon" BackColor="#4A3C8C"></HeaderStyle>
            </asp:datalist></form>
    </body>

IN PAGE-LOAD

Dim da As New SqlDataAdapter("select [ ID],Image  from Items", con)
            Dim dataset11 As New DataSet
            da.Fill(dataset11, "Items")
            DataList1.DataSource = dataset11.Tables(0)
            DataList1.DataBind()

" BUT I AM GETTING THE HEADER ONLY"

can anyone help me in this context please

thanks

Reply By: dparsons Reply Date: 8/30/2006 8:34:36 AM
Why are you defining your datasource and datamember inside the control itself?  This should be handled automatically when you call .DataSource and .DataBind() in your code.  

Does your SQL query actually return a resultset?

"The one language all programmers understand is profanity."
Reply By: sarah lee Reply Date: 8/30/2006 9:06:30 AM
now i have set the datasource in code behind only, not in the datalist properties
but still i am getting the header only.

select [ ID],Image  from Items
i am getting the result set for this query.

but
SELECT     *
FROM         dbo.Items WHERE  ([ID] = 11469)
this is the select stmt in the page2.aspx, where i am trying to display the informations based on the ID, which i am passing frm page1.aspx

ON EXECUTING THIS I AM GETTING AN EROR
"SYNTAX ERROR IN CONVERTING nvarchar value 146-7-8 to colum of data ype int"

ACTUALLY I HAVE A RECORD WITH ID 146-7-8
ALL THE OTHER RECORDS HAVE THEIR ID IN NUMBERS ONLY.

I AM CONFUSED, I THINK THERE IS SOME PROBLEM IN TABLE STRUCTURE?
WAT IS UR SUGGESTION?

Reply By: dparsons Reply Date: 8/30/2006 9:45:16 AM
Somewhere along the way you are trying to cast that value to INT which is, obviously, not allowed. You have to figure out if this error is occuring in SQL or somewhere on your asp page.

"The one language all programmers understand is profanity."
Reply By: sarah lee Reply Date: 8/30/2006 2:10:33 PM
i got the images with their id in hyperlink

now on clicking the hyperlink below the image, i got that value, passed to page2.aspx
page2.aspx is displayed.
but the detailed inf is not there
in the address, i can get the ID get passed
in page2.aspx i have 3 labels and an image control
in labels, i want to display ID,Unitprice, and Descritpion based on ID
inimage control, i want to display the image of that ID(all are in the table)

WHY IS THEN THE INFORMATIONS NOT DISPLAYED, EVEN IF THE ID GET PASSED??
CAN U PLEASE HELP ME

PAGE2.ASPX(CODE BEHIND)

Dim da As New SqlDataAdapter("select * from Items where [ID]= ' " & Request("id") & "'", con)
Dim Dataset21 As New DataSet
da.Fill(Dataset21, "Items")

Dim dc As DataColumn
Dim dr As DataRow
For Each dr In Dataset21.Tables(0).Rows

lblDesc.Text = dr.Item("Description")
lblID.Text = dr.Item("[ID]")
lblUnitprice.Text = dr.Item("UnitPrice")

Next

can u please say why is this?

thanks


Reply By: dparsons Reply Date: 8/30/2006 6:13:06 PM
if you are sure that your query is returning data to you, then I do not know why.  What I do know is that your for loop is unnecessary;

You are only concerned with 3 columns from one row, so the for only exectues one time anyway so:

lblDesc.Text = dataset21.Tables(0).Rows(0).item("description")
etc etc

Outside of that, void of any errors or such, you should have data in your dataset.

"The one language all programmers understand is profanity."
Reply By: peace95 Reply Date: 8/31/2006 2:17:10 AM
Just looking at the inormation you sent there seems to be a conflict in using the reserved word "ID", as in ID=form name on the form tag.   The contents of the ID would be the form name that causes the error in that IIS is trying to convert the nvarchar field to an integer.  As another member suggested, check your table structure and rename tha field and verify that the primary key you are passing is the same data type as the primary key in the receiving table (Items).

Hope this helps.
Reply By: dparsons Reply Date: 8/31/2006 6:32:37 AM
The keyword ID is reserved in TSQL, however when you enclose it in braces [] it is ignored as a reserved word and it should not cause a conflict.

As far as the HTML goes, if the query string is ./file.aspx?id=nn doing a Request will pull the value of id from the query string.

"The one language all programmers understand is profanity."
Reply By: dparsons Reply Date: 8/31/2006 6:44:25 AM
Wait, this might be your problem.  When referencing your column, ID, in SQL you have to reference it with braces so [ID], however, when it is actually pulled from the database the column name will be just ID without the braces.

Try referencing the ID column without the braces.

hth.

"The one language all programmers understand is profanity."
Reply By: sarah lee Reply Date: 8/31/2006 7:41:29 AM
lblDesc.Text = Dataset21.Tables(0).Rows(0).Item("Description")

IT SAYS  "THERE IS NO ROW AT POSITION 0"

but i do have  6 records in my dataset
why is this?
can u plese tel

Reply By: dparsons Reply Date: 8/31/2006 7:48:44 AM
That error means that there is no data in the table.  For the time being do this (so you can figure out where the problem is.

dim tbl as new datatable
dim iTbl as integer
For each tbl in dataset21.Tables
 for each dr in tbl.rows
    response.write(iTbl)
    lblDesc.Text = dr.Item("Description")
    lblID.Text = dr.Item("ID")
    lblUnitprice.Text = dr.Item("UnitPrice")
 next
 i += 1
next

(Instead of writing the value of iTbl out to the screen you can just step through the code) In any case, whatever the value of iTbl is (when it is wrote to the screen) is the table your data is residing in (it should be 0 but the error you are getting says otherwise).  

If there is any data in any of the tables in the dataset it will be retrieved here.

"The one language all programmers understand is profanity."

Go to topic 48895

Return to index page 188
Return to index page 187
Return to index page 186
Return to index page 185
Return to index page 184
Return to index page 183
Return to index page 182
Return to index page 181
Return to index page 180
Return to index page 179