我有一个datalist,并且有一个超链接,在navigateurl中我想使用QueryString。 这是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();
}
这是我的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>
我希望我的QueryString有一个像这样的参数:
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("GalleryID","UserID","~/Profile/UserImages.aspx?ImgID={0}&ProfileID={1}") %>'>
但是这没有达到预期的效果。
答案 0 :(得分:1)
使用<%=
代替<%#
像 -
NavigateUrl='<%= Eval("GalleryID","UserID","~/Profile/UserImages.aspx?ImgID={0}&ProfileID={1}") %>'
答案 1 :(得分:1)
Eval
的语法为:
public static string Eval(
Object container,
string expression,
string format
)
[你可以顺便跳过容器,] 使用:
NavigateUrl='<%#CombinePath(
DataBinder.Eval(Container.DataItem,"GalleryID","~/Profile/UserImages.aspx?ImgID={0}").ToString(),
DataBinder.Eval(Container.DataItem,"UserID","&ProfileID={0}").ToString()) %>'
答案 2 :(得分:0)
你可以这样做
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%= "~/Profile/UserImages.aspx?ImgID=" + Eval("GalleryID") + "&ProfileID=" + Eval("UserID") %>'>