Lorna70
asked on
FormView - Multiple DataKeyNames - how do I retrieve one of the values?
Hi
I need to get the value of one of CostID from my DataKeyNames in a FormView. I have tried:
DataKey key = fvCostJob.DataKey["CostID" ];
string costID = key.Value.ToString();
My code is:
<asp:FormView ID="fvCostJob" runat="server" CellPadding="4"
DataKeyNames="CostID,LoadI D" DataSourceID="SqlDataSourc e1" ForeColor="#333333">
The line that's causing the problem is:
DataKey key = fvCostJob.DataKey["CostID" ];
Intellisense tells me "cannot implicitly convert type 'Object' to ...DataKey"
I need to get the value of one of CostID from my DataKeyNames in a FormView. I have tried:
DataKey key = fvCostJob.DataKey["CostID"
string costID = key.Value.ToString();
My code is:
<asp:FormView ID="fvCostJob" runat="server" CellPadding="4"
DataKeyNames="CostID,LoadI
The line that's causing the problem is:
DataKey key = fvCostJob.DataKey["CostID"
Intellisense tells me "cannot implicitly convert type 'Object' to ...DataKey"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
string xxx = fvCostJob.DataKey["CostID" ];
Nice of you to ignore my post! Given that I put exactly the same thing earlier (ok, i assumed CostID was an int so did the cast, but the principle was the same)
With all the respect...
carl_tawn you are right to a point. If you see question it says:
DataKey key = fvCostJob.DataKey["CostID" ];
string costID = key.Value.ToString();
Read carefully and answer straight to the point. If you compare our answers you will see:
1) you did not mention that DataKey key =.... is not needed
2) costID is a string not an integer.
my answer was staight to the point
peace
carl_tawn you are right to a point. If you see question it says:
DataKey key = fvCostJob.DataKey["CostID"
string costID = key.Value.ToString();
Read carefully and answer straight to the point. If you compare our answers you will see:
1) you did not mention that DataKey key =.... is not needed
2) costID is a string not an integer.
my answer was staight to the point
peace
Actually I think you'll find that I explained that the DataKey collection doesn't actually return a DataKey object, which is a little more detailed that "IS NOT NECESSARY".
ASKER
Sorry Carl but I was in a hurry so just gave points to the best answer. I think you've helped me before so next time I'll make sure I allocate points to you :-) Thanks.
The question was "I need to get the value of one of CostID from my DataKeyNames in a FormView" and two lines of code attached:
DataKey key = fvCostJob.DataKey["CostID" ];
string costID = key.Value.ToString();
clean and clear i gave the solution..
"The DataKey collection doesn't return a DataKey object it returns the actual value of the key" it is not clear that is not needed.
DataKey key = fvCostJob.DataKey["CostID"
string costID = key.Value.ToString();
clean and clear i gave the solution..
"The DataKey collection doesn't return a DataKey object it returns the actual value of the key" it is not clear that is not needed.
ASKER
Now now boys lol! You have both been really helpful and as I said, I'll assign points to Carl the next time he helps. Think no more should be said now :-)
No worries Lorna70. Thanks for the points. :)
carl_tawn i apologise if i disrespect you in any way...
carl_tawn i apologise if i disrespect you in any way...
Open in new window