Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datalist

Status
Not open for further replies.

fmardani

Programmer
Jul 24, 2003
152
Hi,
The following code works fine in asp.net using vb.net but it gives the following error when the project is in c#. Do you know why?
Thanks
<SelectedItemTemplate>
&nbsp;»
<asp:HyperLink id=HyperLink2 runat="server" CssClass="DepartmentSelected" text='<%# DataBinder.Eval(Container.DataItem, "Name") %>' NavigateUrl='<%# "../default.aspx?DepartmentID=" &amp; DataBinder.Eval(Container.DataItem,"DepartmentID") &amp;"&amp;DepartmentIndex=" &amp; Container.ItemIndex %>'>
</asp:HyperLink>
</SelectedItemTemplate>


Error: Operator '&' cannot be applied to operands of type 'string' and 'object'
 
I think this is what you want:
Code:
<asp:HyperLink id=HyperLink2 runat="server" CssClass="DepartmentSelected" text='<%# DataBinder.Eval(Container.DataItem, "Name") %>' NavigateUrl='<%# "../default.aspx?DepartmentID=" + DataBinder.Eval(Container.DataItem,"DepartmentID") + "&amp;DepartmentIndex=" + Container.ItemIndex %>'>

You do want some of the "&amp;" in there because it's part of your url string ("default.aspx?departmentID=12&DepartmentIndex=13", for example)

But some of those &amp;s look like they used to be regular old &s, used for VB concatonation. They seem to have been converted to HTML somewhere along the line. So you need to keep the &amp;s that are HTML codes for &s in the URL, and change all of the ones that are supposed to be for concatonation to "+", which is what you need to use for C# concatonation. I think the code above is what you want, but hopefully, this description will be enough to sort it out if it wasn't
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top