当点击(DataList1)新闻类型的时候,下面的新闻内容(DataList2)发生相应的变化.代码如下:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="NewsType.aspx.cs" Inherits="NewsType" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<br />
<asp:DataList ID="DataList1" runat="server" Height="50px" RepeatDirection="Horizontal" Width="586px" DataKeyField="DF_NEW_TYPE_ID">
<ItemTemplate>
<a href='<%#"NewsType.aspx?typeid="+DataBinder.Eval(Container,"DataItem.DF_NEW_TYPE_ID") %>'>
<asp:Label ID="Label1" runat="server" Text='<%#DataBinder.Eval(Container,"DataItem.DF_NEW_TYPE_NAME") %>'></asp:Label>
</a>
</ItemTemplate>
</asp:DataList><br />
<asp:DataList ID="DataList2" runat="server">
<ItemTemplate>
<table>
<tr>
<td style="width: 100px">
<asp:Label ID="Label1" runat="server" Text='<%#DataBinder.Eval(Container,"DataItem.DF_NEW_TYPE_NAME") %>'></asp:Label></td>
<td style="width: 100px">
<a href='<%#"NewInfo.aspx?newid="+DataBinder.Eval(Container,"DataItem.DF_NEW_ID") %>'>
<asp:Label ID="Label8" runat="server" Text='<%#DataBinder.Eval(Container,"DataItem.DF_NEW_TITLE") %>'></asp:Label>
</a>
</td>
<td style="width: 100px">
<asp:Label ID="Label2" runat="server" Text='<%#DataBinder.Eval(Container,"DataItem.DF_NEW_SOURCE") %>'></asp:Label></td>
<td style="width: 100px">
<asp:Label ID="Label3" runat="server" Text='<%#DataBinder.Eval(Container,"DataItem.DF_NEW_DATE") %>'></asp:Label></td>
</tr>
</table>
</ItemTemplate>
<HeaderTemplate>
<table>
<tr>
<td style="width: 100px">
<asp:Label ID="Label4" runat="server" Text="新闻类型"></asp:Label></td>
<td style="width: 100px">
<asp:Label ID="Label5" runat="server" Text="新闻标题"></asp:Label></td>
<td style="width: 100px">
<asp:Label ID="Label6" runat="server" Text="发布时间"></asp:Label></td>
<td style="width: 100px">
<asp:Label ID="Label7" runat="server" Text="新闻来源"></asp:Label></td>
</tr>
</table>
</HeaderTemplate>
</asp:DataList></div>
</form>
</body>
</html>using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class NewsType : System.Web.UI.Page
{
public void SELECT_DF_NEW_TYPE()
{
string str = ConfigurationSettings.AppSettings["sql"].ToString();
SqlConnection con = new SqlConnection(str);
con.Open();
SqlCommand com = new SqlCommand("S_CS_SELECT_NEWS_TYPE", con);
com.CommandType = CommandType.StoredProcedure;
SqlDataReader ccc = com.ExecuteReader();
this.DataList1.DataSource = ccc;
this.DataList1.DataBind();
ccc.Close();
} public void SELECT_DF_NEWS() //根据新闻类型查找新闻
{
//int typeid = int.Parse(Request["typeid"].ToString());
string str = ConfigurationSettings.AppSettings["sql"].ToString();
SqlConnection con = new SqlConnection(str);
con.Open();
SqlCommand comm = new SqlCommand("S_CS_SELECT_NEWS_FROM_NEW_TYPE", con);
comm.CommandType = CommandType.StoredProcedure;
//comm.Parameters.Add("@DF_NEW_TYPE_ID",typeid);
SqlDataReader cccc = comm.ExecuteReader();
this.DataList2.DataSource = cccc;
this.DataList2.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
return;
}
SELECT_DF_NEW_TYPE();
SELECT_DF_NEWS(); }
}
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<br />
<asp:DataList ID="DataList1" runat="server" Height="50px" RepeatDirection="Horizontal" Width="586px" DataKeyField="DF_NEW_TYPE_ID">
<ItemTemplate>
<a href='<%#"NewsType.aspx?typeid="+DataBinder.Eval(Container,"DataItem.DF_NEW_TYPE_ID") %>'>
<asp:Label ID="Label1" runat="server" Text='<%#DataBinder.Eval(Container,"DataItem.DF_NEW_TYPE_NAME") %>'></asp:Label>
</a>
</ItemTemplate>
</asp:DataList><br />
<asp:DataList ID="DataList2" runat="server">
<ItemTemplate>
<table>
<tr>
<td style="width: 100px">
<asp:Label ID="Label1" runat="server" Text='<%#DataBinder.Eval(Container,"DataItem.DF_NEW_TYPE_NAME") %>'></asp:Label></td>
<td style="width: 100px">
<a href='<%#"NewInfo.aspx?newid="+DataBinder.Eval(Container,"DataItem.DF_NEW_ID") %>'>
<asp:Label ID="Label8" runat="server" Text='<%#DataBinder.Eval(Container,"DataItem.DF_NEW_TITLE") %>'></asp:Label>
</a>
</td>
<td style="width: 100px">
<asp:Label ID="Label2" runat="server" Text='<%#DataBinder.Eval(Container,"DataItem.DF_NEW_SOURCE") %>'></asp:Label></td>
<td style="width: 100px">
<asp:Label ID="Label3" runat="server" Text='<%#DataBinder.Eval(Container,"DataItem.DF_NEW_DATE") %>'></asp:Label></td>
</tr>
</table>
</ItemTemplate>
<HeaderTemplate>
<table>
<tr>
<td style="width: 100px">
<asp:Label ID="Label4" runat="server" Text="新闻类型"></asp:Label></td>
<td style="width: 100px">
<asp:Label ID="Label5" runat="server" Text="新闻标题"></asp:Label></td>
<td style="width: 100px">
<asp:Label ID="Label6" runat="server" Text="发布时间"></asp:Label></td>
<td style="width: 100px">
<asp:Label ID="Label7" runat="server" Text="新闻来源"></asp:Label></td>
</tr>
</table>
</HeaderTemplate>
</asp:DataList></div>
</form>
</body>
</html>using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class NewsType : System.Web.UI.Page
{
public void SELECT_DF_NEW_TYPE()
{
string str = ConfigurationSettings.AppSettings["sql"].ToString();
SqlConnection con = new SqlConnection(str);
con.Open();
SqlCommand com = new SqlCommand("S_CS_SELECT_NEWS_TYPE", con);
com.CommandType = CommandType.StoredProcedure;
SqlDataReader ccc = com.ExecuteReader();
this.DataList1.DataSource = ccc;
this.DataList1.DataBind();
ccc.Close();
} public void SELECT_DF_NEWS() //根据新闻类型查找新闻
{
//int typeid = int.Parse(Request["typeid"].ToString());
string str = ConfigurationSettings.AppSettings["sql"].ToString();
SqlConnection con = new SqlConnection(str);
con.Open();
SqlCommand comm = new SqlCommand("S_CS_SELECT_NEWS_FROM_NEW_TYPE", con);
comm.CommandType = CommandType.StoredProcedure;
//comm.Parameters.Add("@DF_NEW_TYPE_ID",typeid);
SqlDataReader cccc = comm.ExecuteReader();
this.DataList2.DataSource = cccc;
this.DataList2.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
return;
}
SELECT_DF_NEW_TYPE();
SELECT_DF_NEWS(); }
}
{
string str = ConfigurationSettings.AppSettings["sql"].ToString();
SqlConnection con = new SqlConnection(str);
SqlCommand com = new SqlCommand("S_CS_SELECT_NEWS_TYPE", con);
com.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataReader ccc = com.ExecuteReader();
this.DataList1.DataSource = ccc;
this.DataList1.DataBind();
ccc.Close();
con.Close();
} public void SELECT_DF_NEWS() //根据新闻类型查找新闻
{
int typeid = int.Parse(Request["typeid"].ToString());
string str = ConfigurationSettings.AppSettings["sql"].ToString();
SqlConnection con = new SqlConnection(str);
SqlCommand comm = new SqlCommand("S_CS_SELECT_NEWS_FROM_NEW_TYPE", con);
comm.CommandType = CommandType.StoredProcedure;
comm.Parameters.Add("@DF_NEW_TYPE_ID",typeid);
con.Open();
SqlDataReader cccc = comm.ExecuteReader();
this.DataList2.DataSource = cccc;
this.DataList2.DataBind();
con.Close();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SELECT_DF_NEW_TYPE();
} if (!string.IsNullOrEmpty(Request["typeid"]))
{
SELECT_DF_NEWS();
}
}