Wednesday, March 21, 2012

Passing a GUID to another page

I would like to figure out the solution to this problem.

Compilation Error

Description:An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message:BC30311: Value of type 'System.Guid' cannot be converted to 'String'.

Source Error:

Line 348: <asp:TemplateField SortExpression="avatar">Line 349:<ItemTemplate>Line 350:<asp:Image ID="Image1" runat="server" ImageUrl='<%# "AvatarImagefetch.ashx?UserName=" & CStr(new Guid(Eval("UserID").ToString()))) %>'/>Line 351:</ItemTemplate>Line 352:

Now I have tried several variations to this theme.

Basically I want to convert "USERID" which is a GUID to a String before passing it to another page.

This is part of a Gridview.

Try this for ImageUrl (I am assuming you are using VB.NET from CStr)

<%# String.Concat("AvatarImagefetch.ashx?Username=", Eval("UserID"))%>
You don't need to cast Eval("UserID") as a Guid, you can leave it is an object because if it is a Guid you will just end up turning it back into a string.

Hi Kevin,

Thanks for the tip, I was reaserching this prior to your reply and found the following to work:

<

ItemTemplate>

<

asp:ImageID="Image1"runat="server"ImageUrl='<%# "AvatarImagefetch.ashx?MemberId=" & DataBinder.Eval(Container.DataItem,"UserId").ToString %>'/>

</

ItemTemplate>

I think you need the .ToString for it to be passed as a String.


I used String.Concat, and Concat can accept object and will automatically convert them to a string.

That is excellent tip, thanks once again Kevin.

0 comments:

Post a Comment