Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Detailsview based on datalist

Posted on 2009-07-11
11
Medium Priority
?
777 Views
Last Modified: 2013-11-27
Hi all, I have a Datalist and inside that datalist I have a detailsview.  I am trying to set a field in the detailsview based on where I am at in the datalist.  Here is the code for a short version of what I have: (see the code section)

If I don't have the where statement in there it runs fine, except it displays the same data for all of the datalist.  I am getting this error when running

Conversion failed when converting the nvarchar value 'ItemId' to data type int.

That is why I was trying to convert in my SQL, either I need to change my SQL or something in my datakeyfield, not really sure.  ItemId is an int of course, so I am gathering that the datakeyfield is automatically an nvarchar.....  I actually need to put two items in the datakeyfield, but it will only allow one for a datalist, is this correct? unlike in a gridview where you can add multiples.

Thanks,
Randy

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:DataList ID="DataList2" runat="server" BackColor="White" 
        BorderColor="#FFCCFF" BorderStyle="Solid" BorderWidth="2px" CellPadding="4" 
         datasourceid="SqlDataSource2" ForeColor="Black" 
        GridLines="Vertical" RepeatColumns="4" RepeatDirection="Horizontal" 
        DataKeyField= "ItemId" onitemcommand="DataList2_ItemCommand" Height="727px" 
                Width="1026px" >
..... then this is for one of the fields inside the datalist
 <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                        <ContentTemplate>
                            <asp:DetailsView ID="DetailsView2" runat="server" AutoGenerateRows="False" 
                                DataSourceID="SqlDataSource4" Height="50px" Width="125px">
                                <Fields>
                                    <asp:BoundField DataField="Amount" HeaderText="Amount" 
                                        SortExpression="Amount" />
                                </Fields>
                            </asp:DetailsView>
                            
                            <asp:SqlDataSource ID="SqlDataSource4" runat="server" 
                                ConnectionString="<%$ ConnectionStrings:SQL2008_xxxxx%>" 
                                SelectCommand="SELECT DISTINCT [Amount] FROM [Bids] where ItemId = (convert (int, @ItemId))">
                                
                                  <SelectParameters>
                                         <asp:ControlParameter ControlID="DataList2" Name="ItemId" PropertyName="DataKeyField"
                                             Type="String" />
                                  </SelectParameters>
                             </asp:SqlDataSource>
                             
                        </ContentTemplate>
                    </asp:UpdatePanel>

Open in new window

0
Comment
Question by:ratkinso666
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24832838
>>Conversion failed when converting the nvarchar value 'ItemId' to data type int.<<
And that would be because ItemId contains non-numeric data.
0
 

Author Comment

by:ratkinso666
ID: 24836979
But ItemId is an int identity field...
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24843493
Can you see the contradiction here:

"Conversion failed when converting the nvarchar value 'ItemId' to data type int."

And:
"But ItemId is an int identity field..."

If you can, then you have to come to the conclusion that one of those statements is incorrect.  Perhaps you are querying the wrong table.

If you cannot see the contradiction, then I am afraid I cannot help you any further.
0
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 

Author Comment

by:ratkinso666
ID: 24844018
I understand what you are saying, I don't know how ItemId is becoming an nvarchar unless it is because I am listing it as a datakeyfield and that assumes an nvarchar??  In the database it is a type int and there are NO non numeric values in there.  It is set as an IsIdentity and that automatically moves the value up by 1, each time you add a line to the database.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24845738
Then as I previously stated I am afraid I cannot help you any further.
0
 

Author Comment

by:ratkinso666
ID: 24850056
OK, not really sure why you would answer that you can't help with this problem, instead of just not answering, sounds like you are saying that I am too stupid to help, in my years of using experts exhange never really had anyone tell me that , but hopefully there is someone else who is more familiar with this and can help with this problem?  

Thanks,
Randy
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24851704
>>OK, not really sure why you would answer that you can't help with this problem, instead of just not answering<<
It is common courtesy here as well as mentioned in the EE Guidelines, to indicate that you can no longer help someone, when it is beyond your expertise or knowledge, rather than totally abandoning the thread without a word.

>>sounds like you are saying that I am too stupid to help<<
No, I did not say that.  That is your interpretation.

>>in my years of using experts exhange never really had anyone tell me that <<
Feel free to post a message in Community Support by clicking on the Request Attention, if you believe any of my comments were in any way inapproipriate.

Thanks,
Anthony
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24851715
P.S. If you are not comfortable wit contacting CS, let me know and I will be happy to ask a Moderator to review the thread.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24851734
A Moderator can also contact other members who may be able to help you more than I was able to do.
0
 

Author Comment

by:ratkinso666
ID: 24855564
OK, I guess I didn't realize that this was such a difficult question.  I thought for sure there was a simple explanation for the problem, like that the datakeyfield is automatically assumed to be a varchar, no matter what it is in the database.
0
 

Accepted Solution

by:
ratkinso666 earned 0 total points
ID: 24946766
Guess no one has an answer to this one, so will close it out
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question