我正在尝试包装模板并将DataItem传递给当前在LayoutTemplate中的包装器但是当我尝试在其中添加DataItem并且不知道为什么(我不是一个asp人)时它会中断然而在准备好后我看看这应该可以使用GridView,但不知道我将如何重写这样做。有人可以帮我解决这个问题吗?
C#
protected void rptListingAllMandatoryCourses_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
ListViewDataItem listItem = (ListViewDataItem)e.Item;
DataRowView dataItem = (DataRowView)listItem.DataItem;
}
}
如果你看到title =“”和description =“”我希望理想地将一些数据传递给那些像:(但是这个突破并且不起作用)我到目前为止得到它这么远但最后一点并且会如果有人可以提供帮助,那真是太棒了,因为今天早上我需要释放它。如果我们能继续使用ListView会很棒!
<%#DataBinder.Eval(Container.DataItem, "CatalogueTitle")%>
ASPX
<asp:ListView ID="rptListingAllMandatoryCourses" runat="server" OnItemDataBound="rptListingAllMandatoryCourses_ItemDataBound">
<LayoutTemplate>
<Catalogue title="" description="">
<div runat="server" ID="groupPlaceholder"></div>
</Catalogue>
</LayoutTemplate>
<GroupTemplate>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder" />
</GroupTemplate>
<ItemTemplate>
<Course>
<CourseTitle><a onclick="linkcourse("<%#DataBinder.Eval(Container.DataItem, "CourseID")%>");return false;" href="#" title="Launch <%# DataBinder.Eval(Container.DataItem, "CourseTitle")%>"><%# System.Web.HttpUtility.HtmlEncode((String)(DataBinder.Eval(Container.DataItem, "CourseTitle").ToString().Length > 25 ? DataBinder.Eval(Container.DataItem, "CourseTitle").ToString().Remove(22) + "..." : DataBinder.Eval(Container.DataItem, "CourseTitle")))%></a></CourseTitle>
<RatingsEnabled><%#DataBinder.Eval(Container.DataItem, "ratingsEnabled")%></RatingsEnabled>
<Rating><%#DataBinder.Eval(Container.DataItem, "rating")%></Rating>
<RatingCommentsEnabled><%#DataBinder.Eval(Container.DataItem, "ratingCommentsEnabled")%></RatingCommentsEnabled>
<Comment><%#DataBinder.Eval(Container.DataItem, "Comment")%></Comment>
</Course>
</ItemTemplate>
</asp:ListView>
答案 0 :(得分:0)
我希望您能为锚标记显示一些工具提示,如果是这样,请尝试一次。
ASPX
<asp:ListView ID="rptListingAllMandatoryCourses" runat="server" OnItemDataBound="rptListingAllMandatoryCourses_ItemDataBound">
<LayoutTemplate>
<Catalogue title="" description="">
<div runat="server" ID="groupPlaceholder"></div>
</Catalogue>
</LayoutTemplate>
<GroupTemplate>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder" />
</GroupTemplate>
<ItemTemplate>
<Course>
<<CourseTitle><a id="aCourse" runat="server" href="#" </a></CourseTitle>
<RatingsEnabled><%#DataBinder.Eval(Container.DataItem, "ratingsEnabled")%></RatingsEnabled>
<Rating><%#DataBinder.Eval(Container.DataItem, "rating")%></Rating>
<RatingCommentsEnabled><%#DataBinder.Eval(Container.DataItem, "ratingCommentsEnabled")%></RatingCommentsEnabled>
<Comment><%#DataBinder.Eval(Container.DataItem, "Comment")%></Comment>
</Course>
</ItemTemplate>
</asp:ListView>
后面的代码是
protected void rptListingAllMandatoryCourses_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
ListViewDataItem listItem = (ListViewDataItem)e.Item;
DataRowView dataItem = (DataRowView)listItem.DataItem;
HtmlGenericControl aCourse = (HtmlGenericControl)e.Item.FindControl("aCourse");
if (dataItem["CourseTitle"].ToString().Length > 25)
{
aCourse.InnerHtml = "Launch " + dataItem["CourseTitle"].ToString().Substring(0, 22) + "...";
aCourse.Attributes.Add("title", "Launch " + dataItem["CourseTitle"].ToString() + "...");
}
else
aCourse.InnerHtml = "Launch " + dataItem["CourseTitle"].ToString();
aCourse.Attributes.Add("onclick", "linkcourse(" + dataItem["CourseID"].ToString() + ");return false;");
}
}