我在Asp.net C#应用程序的aspx文件中创建了li标签,如下面的代码行
<li id="MenuHome">
<asp:LinkButton ID="liHome" CssClass="dropdown-toggle" runat="server" CausesValidation="false" OnClick="Redirect"
CommandArgument="~/Home/Home" Text="Home"></asp:LinkButton>
<asp:repeater ID="lnkWebPages" runat="server" OnItemDataBound="lnkWebPages_ItemDataBound">
<headertemplate>
<div class="sub-menu"><ul>
</headertemplate>
<itemtemplate>
<li>
<a href='<%# "~/Default.aspx?PageId=" + Eval("PageId") %>'>'><%#Eval("PageName") %></a>
</li>
</itemtemplate>
<footertemplate>
</ul></div>
</footertemplate>
</asp:repeater>
</li>
我在数据库中的ForumPages表中创建了Web页面,如
现在我希望当我们点击主页链接按钮时,网页列表应该显示在下拉列表中,它应该被重定向到Default.aspx,页面ID为querystring中的参数,如下所示
<ul>
<li><a href="Default.aspx?Pid=1">abc</a></li>
<li><a href="Default.aspx?Pid=2">def</a></li>
...
</ul>
此外,我在Business Layer中创建了一个函数,它将从数据库中的表中获取页面详细信息。
public ForumPages FetchForumPagesIsPublicTrue()
{
ForumPages Item = new ForumPages();
DbProviderFactory myFactory = DbProviderFactories.GetFactory(AppConfiguration.ConnectionStringSettings().ProviderName);
DbConnection myConnection = myFactory.CreateConnection();
myConnection.ConnectionString = AppConfiguration.ConnectionStringSettings().ConnectionString;
try
{
DbCommand myCommand = myConnection.CreateCommand();
myCommand.Connection = myConnection;
myCommand.CommandText = "ForumPagesFetchIsPublicTrue";
myCommand.CommandType = CommandType.StoredProcedure;
myConnection.Open();
using (IDataReader dataReader = myCommand.ExecuteReader())
{
while (dataReader.Read())
{
Item = GetDataFromReaderForumPages1(dataReader);
}
}
myConnection.Close();
}
catch
{
myConnection.Close();
}
finally
{
myConnection.Close();
}
return Item;
}
public class ForumPages
{
public Guid PageId { set; get; }
public string PageName { set; get; }
public string PageDescription { set; get; }
public bool IsPublished { set; get; }
public bool IsPublic { set; get; }
public int DisplayOrder { set; get; }
public DateTime CreatedOn { set; get; }
public Guid CreatedBy { set; get; }
public DateTime UpdatedOn { set; get; }
public Guid UpdatedBy { set; get; }
public int Page { get; set; }
public int PageSize { get; set; }
public string SearchHint { get; set; }
public int TotalPages { get; set; }
public int TotalRecords { get; set; }
}
任何人都可以告诉我如何在转发器控件中动态获取所有这些网页,以及如何在转发器控件中绑定这些数据,并在aspx.cs文件中的page_load()事件上创建带有查询字符串的链接。请帮忙!!!
答案 0 :(得分:0)
假设您有一个页面集合并将其分配给listview项目源,您可以编写listview模板,如下所示。虽然我没有测试过代码,但它应该给你一个开始的想法..
<xsl:variable name="left">
<xsl:if test="not($leftA)">
<xsl:value-of select="$leftB"/>
</xsl:if>
**<xsl:value-of select="$leftA"/>**
</xsl:variable>