Friday 15 February 2013

asp.net - When exactly is a value returned from Eval() converted to a string? -


I thought Eval ("JobTitle") returns the value String , but this does not look like, because given by Eval ("JobTitle") GetSelectedJobTitle () has object And not string , which means that "objects can not be converted from string".

& lt; Editing item template & gt; & Lt; Asp: DropDownList ID = "EditJob" runat = "server" selectIndex = '& lt;% # GetSelectedJobTitle (Eval ("JobTitle"))% & gt; Data source = '& lt;% # header% & gt;' & Gt; & Lt; / ASP: DropDownList & gt; & Lt; / EditItemTemplate & gt; Public int GetSelectedJobTitle (String title) {...} Public string [] Title {...}

a) Then the conversion (from object )

b) return from Eval ("JobTitle") ) and if Eval does not convert , what way?

thanx


Edit:


I think that In our example, GetSelectedJobTitle () is said before the evaluation of Asp.Net (and it converts to a string) inside of & lt;% #%> is the expression inside?

Eval return "object" If you know that you will get a string, .

  & lt; EditItemTemplate & gt; & Lt; Asp: DropDownList ID = "EditJob" runat = "server" selectIndex = '& lt;% # GetSelectedJobTitle (string) Eval ("JobTitle"))% & gt; Data source = '& lt;% # header% & gt;' & Gt; & Lt; / ASP: DropDownList & gt; & Lt; / EditItemTemplate & gt;  

The conversion occurs during the databind event.

EDIT: Answer better comments here.

Our big difference is that statement:

Your:

  <% # getSelectedJobTitle (Eval ("JobTitle"))% & Gt;  

I also give error 2 logic '1': can not be converted from 'object' to 'string' p: \ WebSite1 \ Default.aspx 19

My:

  & lt;% # getSelectedJobTitle ((string) Eval ("JobTitle"))% & gt;  

compiled!


No comments:

Post a Comment