📄 default.aspx.cs
字号:
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 Default : System.Web.UI.Page
{
public SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnStr"]);
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
String sql = "SELECT * FROM PType where parentId=0";
SqlCommand command = new SqlCommand(sql, conn);
conn.Open();
SqlDataReader dr = command.ExecuteReader();
DataList1.DataSource = dr;
DataList1.DataKeyField = "category_ID";
DataList1.DataBind();
dr.Close();
conn.Close();
}
}
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.DataList1.ItemDataBound += new System.Web.UI.WebControls.DataListItemEventHandler(this.DataList1_ItemDataBound);
}
private void DataList1_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
Repeater myRepeater = (Repeater)e.Item.FindControl("Repeater1");
if (myRepeater != null)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnStr"]);
String sql = "select top 6 * from PType where parentId=" + DataList1.DataKeys[e.Item.ItemIndex].ToString();
SqlCommand command = new SqlCommand(sql, conn);
conn.Open();
SqlDataReader dr = command.ExecuteReader();
myRepeater.DataSource = dr;
myRepeater.DataBind();
dr.Close();
conn.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -