Detailsview based on datalist

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.


<asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <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">
                            <asp:DetailsView ID="DetailsView2" runat="server" AutoGenerateRows="False" 
                                DataSourceID="SqlDataSource4" Height="50px" Width="125px">
                                    <asp:BoundField DataField="Amount" HeaderText="Amount" 
                                        SortExpression="Amount" />
                            <asp:SqlDataSource ID="SqlDataSource4" runat="server" 
                                ConnectionString="<%$ ConnectionStrings:SQL2008_xxxxx%>" 
                                SelectCommand="SELECT DISTINCT [Amount] FROM [Bids] where ItemId = (convert (int, @ItemId))">
                                         <asp:ControlParameter ControlID="DataList2" Name="ItemId" PropertyName="DataKeyField"
                                             Type="String" />

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Anthony PerkinsCommented:
>>Conversion failed when converting the nvarchar value 'ItemId' to data type int.<<
And that would be because ItemId contains non-numeric data.
ratkinso666Author Commented:
But ItemId is an int identity field...
Anthony PerkinsCommented:
Can you see the contradiction here:

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

"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.
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

ratkinso666Author Commented:
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.
Anthony PerkinsCommented:
Then as I previously stated I am afraid I cannot help you any further.
ratkinso666Author Commented:
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?  

Anthony PerkinsCommented:
>>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.

Anthony PerkinsCommented:
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.
Anthony PerkinsCommented:
A Moderator can also contact other members who may be able to help you more than I was able to do.
ratkinso666Author Commented:
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.
ratkinso666Author Commented:
Guess no one has an answer to this one, so will close it out

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.