Reputation: 21
I have a datalist and there is a hyperlink in that, in navigateurl I want use of QueryString. This is the DataSource of an asp:DataList:
public void GalleryListDS()
{
int UserID = Convert.ToInt32(ViewState["UserID"]);
var n = from gi in DataContext.Context.GalleryImages
join g in DataContext.Context.Galleries
on gi.GalleryID equals g.GalleryID
where g.UserID == UserID && gi.IsAlbumImage == true
select new
{
UserID=g.UserID,
GalleryID = g.GalleryID,
ImageDescription = gi.ImageDescription,
GalleryName=g.GalleryName,
ImageFileName = gi.ImageFileName
};
dlGalleryList.DataSource = n;
dlGalleryList.DataBind();
}
And this is my DataList:
<asp:DataList ID="dlGalleryList" runat="server" RepeatColumns="3">
<ItemTemplate>
<div class="gallery">
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("GalleryID","~/Profile/UserImages.aspx?ImgID={0}") %>'>
'<%# Eval("GalleryName")%>'
</asp:HyperLink>
</div>
</ItemTemplate>
</asp:DataList>
I want my QueryString to have a Parameter like so:
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("GalleryID","UserID","~/Profile/UserImages.aspx?ImgID={0}&ProfileID={1}") %>'>
but this does not achieve the desired result.
Upvotes: 0
Views: 3982
Reputation: 10565
Eval
has the syntax:
public static string Eval(
Object container,
string expression,
string format
)
[ You can skip the Container by the way, ] Use :
NavigateUrl='<%#CombinePath(
DataBinder.Eval(Container.DataItem,"GalleryID","~/Profile/UserImages.aspx?ImgID={0}").ToString(),
DataBinder.Eval(Container.DataItem,"UserID","&ProfileID={0}").ToString()) %>'
Upvotes: 1
Reputation: 4081
You can do in this way
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%= "~/Profile/UserImages.aspx?ImgID=" + Eval("GalleryID") + "&ProfileID=" + Eval("UserID") %>'>
Upvotes: 0
Reputation: 10030
use <%=
instead of <%#
like-
NavigateUrl='<%= Eval("GalleryID","UserID","~/Profile/UserImages.aspx?ImgID={0}&ProfileID={1}") %>'
Upvotes: 1