DataBinder.Eval question

D

dm_dal

I have a control on my webform that I am binding to a dataset. The issue
is, the field value in the dataset is encrypted and I am trying to decrypt
it during the binding process:

Example:

<asp:Lable ID="myLable Text='<%#
myComponent.Decrypt(DataBinder.Eval(myDataSet,
"Tables[MyTable].DefaultView.[0].MyField")) '></asp:Label>

This fails with the message : Compiler Error Message: CS1502: The best
overloaded method match for MyComponent.Decrypt(string)' has some invalid
arguments.

From what I've read, the DataBinder.Eval() does return a string value?

I can tell the decryption component works, because if I use the following in
my code behind:

myLable.Text = MyComponent.Decrypt(myDataSet.MyTable[0].MyField)

The decryption works and the data is displayed as desired.

Is it possible to do what I'm attempting? or, Should I simply give up and
use the code behind method?

I'd like to get this working, because I have other controls that I would
like to do some formatting on before I display on the web form.

David
 
M

Milan Negovan

Hi there,


DataBinder.Eval returns an object. Apparently your MyComponent.Decrypt
method takes a string which is why the compiler is complaining. I think
something like this should work:

myComponent.Decrypt((string)DataBinder.Eval(myDataSet,
"Tables[MyTable].DefaultView.[0].MyField"))
 
D

dm_dal

You're right, I was looking at the wrong overloaded method.

object DataBinder.Eval(object, string);
vs.
string DataBinder.Eval(object, string, string)

It appears as though I could use
myComponent.Decrypt(DataBinder.Eval(myDataSet,"Tables[MyTable].DefaultView[0
].MyField","{0}")). By adding the optional "StringFormat" arguement, it
would natively return a string.

I'll try both options out.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top