请直接告知:将在Add.aspx录入新闻标题后,如何将其发布到新闻主页Default.aspx的前页面上去???使能在该主页浏览该条新闻。
在《ASP.NET编程宝典》一书附带的DVD上的案例18.3上,经过多方实践,还真不能或者说没有找到将新录入的新闻发布到主页Default.aspx页面的相关功能,请参见该案例中的newsList.aspx上的前台和后台代码,看看是否将其新录入的新闻发布到主页的功能??并另请赐教,别敷衍了事哟。老师。
%@ Page Language="C#" MasterPageFile="MasterPage.master" AutoEventWireup="true" CodeFile="newsList.aspx.cs" Inherits="newsList" Title="分类显示新闻" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table style="height: 580px; width :778px; font-size :9pt" align="center" cellspacing="0" background ="Images/新闻发布系统二级页.jpg">
<tr style =" width :778px;height: 38px">
<td colspan="2" style=" height: 38px; font-size :9pt">
<asp:Label ID="labTitle" runat="server" Text="" Width="363px"></asp:Label></td>
</tr>
<tr style =" width :778px;height: 38px">
<td colspan="2" style=" height: 19px; font-size :9pt" valign =middle>
<asp:Image ID="imageTitle" runat="server" Height="19px" ImageUrl="Images/二级页时政要闻.jpg" Width="486px" />
</td>
</tr>
<tr style =" width :778px;height: 504px">
<td align="center" style="width: 178px; height: 154px" valign =top >
<asp:Image ID="imageLag" runat="server" Height="79px"
ImageUrl="~/NewsIssue/Images/时政要闻图片.jpg" Width="86px" />
</td>
<td style="width :600px; height: 350px; font-size :9pt" valign =top >
<asp:DataList ID="dlNews" runat="server" OnItemCommand="dlNews_ItemCommand">
<ItemTemplate>
<table border="0" cellspacing="0" style="width: 100%; height:100%; padding-left: 0px; margin-left: 0px; margin-top: 0px; padding-top: 0px; font-size :9pt ">
<tr>
<td align="left" style="width: 90px; height: 21px;border-bottom: 1px dashed #000000;">
『
<%# DataBinder.Eval(Container.DataItem,"type")%>
』</td>
<td align="left" style="height: 21px;border-bottom: 1px dashed #000000;">
<asp:LinkButton ID="lbtnTitle" runat="server" CommandName="select"><%# DataBinder.Eval(Container.DataItem,"title") %></asp:LinkButton></td>
</tr>
</table>
</ItemTemplate>
<HeaderStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
Font-Underline="False" ForeColor="Blue" HorizontalAlign="Center" />
</asp:DataList>
<table style="width: 500px" cellpadding="0" cellspacing="0" align =left >
<tr>
<td style="width: 500px; text-align: left; font-size: 9pt; height: 15px;" >
<asp:Label ID="labCP" runat="server" Text="当前页码为:"></asp:Label>
[
<asp:Label ID="labPage" runat="server" Text="1"></asp:Label>
]
<asp:Label ID="labTP" runat="server" Text="总页码为:"></asp:Label>
[
<asp:Label ID="labBackPage" runat="server"></asp:Label>
]<asp:LinkButton ID="lnkbtnOne" runat="server" Font-Underline="False" ForeColor="Red"
OnClick="lnkbtnOne_Click">第一页</asp:LinkButton>
<asp:LinkButton ID="lnkbtnUp" runat="server" Font-Underline="False" ForeColor="Red"
OnClick="lnkbtnUp_Click">上一页</asp:LinkButton>
<asp:LinkButton ID="lnkbtnNext" runat="server" Font-Underline="False" ForeColor="Red"
OnClick="lnkbtnNext_Click">下一页</asp:LinkButton>
<asp:LinkButton ID="lnkbtnBack" runat="server" Font-Underline="False" ForeColor="Red"
OnClick="lnkbtnBack_Click" Width="48px">最后一页</asp:LinkButton> </td>
</tr>
</table>
</td>
</tr>
</table>
</asp:Content>
public partial class newsList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
bind();
}
string strStyle;
protected void bind()
{
int n = Convert.ToInt32(Request.QueryString["id"]);
switch (n)
{
case 1: strStyle = "时政要闻";
this.labTitle.Text = "新闻网络中心->时政要闻";
this.imageLag.ImageUrl = "~/Images/图片时政要闻.jpg";
this.imageTitle.ImageUrl = "~/Images/二级页时政要闻.jpg";
break;
case 2: strStyle = "经济动向";
this.labTitle.Text = "新闻网络中心->经济动向";
this.imageLag.ImageUrl = "~/Images/经济动向图片.jpg";
this.imageTitle.ImageUrl = "~/Images/二级页经济动向.jpg";
break;
case 3: strStyle = "世界军事";
this.labTitle.Text = "新闻网络中心->世界军事";
this.imageLag.ImageUrl = "~/Images/世界军事图片.jpg";
this.imageTitle.ImageUrl = "~/Images/二级页世界军事.jpg";
break;
case 4: strStyle = "科学教育";
this.labTitle.Text = "新闻网络中心->科学教育";
this.imageLag.ImageUrl = "~/Images/图片科学教育.jpg";
this.imageTitle.ImageUrl = "~/Images/二级页科学教育.jpg";
break;
case 5: strStyle = "法制道德";
this.labTitle.Text = "新闻网络中心->法制道德";
this.imageLag.ImageUrl = "~/Images/法制道德图片.jpg";
this.imageTitle.ImageUrl = "~/Images/二级页法制道德.jpg";
break;
case 6: strStyle = "社会现象";
this.labTitle.Text = "新闻网络中心->社会现象";
this.imageLag.ImageUrl = "~/Images/社会现象图片.jpg";
this.imageTitle.ImageUrl = "~/Images/二级页社会现象.jpg";
break;
case 7: strStyle = "体育世界";
this.labTitle.Text = "新闻网络中心->体育世界";
this.imageLag.ImageUrl = "~/Images/体育世界图片.jpg";
this.imageTitle.ImageUrl = "~/Images/二级页体育世界.jpg";
break;
case 8: strStyle = "时尚娱乐";
this.labTitle.Text = "新闻网络中心->时尚娱乐";
this.imageLag.ImageUrl = "~/Images/时尚娱乐图片.jpg";
this.imageTitle.ImageUrl = "~/Images/二级页时尚娱乐.jpg";
break;
}
//取得当前页的页码
int curpage = Convert.ToInt32(this.labPage.Text);
//使用PagedDataSource类实现DataList控件的分页功能
PagedDataSource ps = new PagedDataSource();
//获取数据集
tb_News news = new tb_News();
news.Style = strStyle;
List<tb_News> newsList = NewsService.Instance.SelectNews(news);
ps.DataSource = newsList;
//是否可以分页
ps.AllowPaging = true;
//显示的数量
ps.PageSize =16;
//取得当前页的页码
ps.CurrentPageIndex = curpage - 1;
this.lnkbtnUp.Enabled = true;
this.lnkbtnNext.Enabled = true;
this.lnkbtnBack.Enabled = true;
this.lnkbtnOne.Enabled = true;
if (curpage == 1)
{
//不显示第一页按钮
this.lnkbtnOne.Enabled = false;
//不显示上一页按钮
this.lnkbtnUp.Enabled = false;
}
if (curpage == ps.PageCount)
{
//不显示下一页
this.lnkbtnNext.Enabled = false;
//不显示最后一页
this.lnkbtnBack.Enabled = false;
}
//显示分页数量
this.labBackPage.Text = Convert.ToString(ps.PageCount);
//绑定DataList控件
this.dlNews.DataSource = ps;
this.dlNews.DataKeyField = "id";
this.dlNews.DataBind();
}
//第一页
protected void lnkbtnOne_Click(object sender, EventArgs e)
{
this.labPage.Text = "1";
this.bind();
}
//上一页
protected void lnkbtnUp_Click(object sender, EventArgs e)
{
this.labPage.Text = Convert.ToString(Convert.ToInt32(this.labPage.Text) - 1);
this.bind();
}
//下一页
protected void lnkbtnNext_Click(object sender, EventArgs e)
{
this.labPage.Text = Convert.ToString(Convert.ToInt32(this.labPage.Text) + 1);
this.bind();
}
//最后一页
protected void lnkbtnBack_Click(object sender, EventArgs e)
{
this.labPage.Text = this.labBackPage.Text;
this.bind();
}
protected void dlNews_ItemCommand(object source, DataListCommandEventArgs e)
{
int id = Convert.ToInt32(dlNews.DataKeys[e.Item.ItemIndex].ToString());
Response.Write("<script language=javascript>window.open('showNews.aspx?id=" + id + "','','width=520,height=260')</script>");
}