62,254
社区成员
发帖
与我相关
我的任务
分享<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Area_Class.ascx.cs" Inherits="Inc_Area_Class" %>
<asp:DropDownList ID="Area_ID" runat="server">
</asp:DropDownList>public partial class Inc_Area_Class : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
string StrSQL = "SELECT * FROM Area_Class ORDER BY Num ASC";
SqlConnection DbConn = new DataBase().Open();
SqlCommand thisCommand = DbConn.CreateCommand();
thisCommand.CommandText = StrSQL;
SqlDataReader thisReader = thisCommand.ExecuteReader();
Area_ID.Items.Add(new ListItem("请选择", ""));
while (thisReader.Read())
{
Area_ID.Items.Add(new ListItem(thisReader["ClassName"].ToString(), thisReader["ID"].ToString()));
}
thisReader.Close();
DbConn.Close();
}
}Area_ID.DataBind();<asp:DropDownList ID="Area_ID" runat="server">
</asp:DropDownList>
public partial class Area_Class : System.Web.UI.UserControl
{
public string Text
{
get { return Area_ID.SelectedItem.Text; }
}
public string Value
{
get { return Area_ID.SelectedValue; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string StrSQL = "SELECT * FROM Area_Class ORDER BY Num ASC";
SqlConnection DbConn = new DataBase().Open();
SqlCommand thisCommand = DbConn.CreateCommand();
thisCommand.CommandText = StrSQL;
SqlDataReader thisReader = thisCommand.ExecuteReader();
while (thisReader.Read())
{
Area_ID.Items.Add(new ListItem(thisReader["ClassName"].ToString(), thisReader["ID"].ToString()));
}
thisReader.Close();
DbConn.Close();
}
}
}