2009/01/22
| |
using System;
using System.Data;
using System.Configuration;
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
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SqlConnection con = DB.createConnection();
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from province",con);
            SqlDataReader sdr = cmd.ExecuteReader();
            ddlProvince.DataSource = sdr;
            ddlProvince.DataTextField = "proName";
            ddlProvince.DataValueField = "proID";
            ddlProvince.DataBind();
            sdr.Close();
            SqlCommand cmdCity = new SqlCommand("select * from city where proID=" + ddlProvince.SelectedValue,con);
            sdr = cmdCity.ExecuteReader();
            ddlCity.DataSource = sdr;
            ddlCity.DataTextField = "cityName";
            ddlCity.DataValueField = "cityID";
            ddlCity.DataBind();
            sdr.Close();
            con.Close();

        }

    }
    protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
    {
        string proID =ddlProvince.SelectedValue;
        SqlConnection con = DB.createConnection();
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from city where proID=" + proID, con);
        SqlDataReader sdr = cmd.ExecuteReader();
        ddlCity.DataSource = sdr;
        ddlCity.DataTextField = "cityName";
        ddlCity.DataValueField = "cityID";
        ddlCity.DataBind();
        sdr.Close();
        con.Close();

    }
}
Tags:
不指定 2009/01/22 12:03, wxxslt, 网站建设 » C#.NET, 评论(0), 阅读(2782)
发表评论
表情
emotemotemotemot
emotemotemotemot
emotemotemotemot
emotemotemotemot
emotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]
               

 
Theme by Marshal. Powered by Bo-Blog 2.1.1 ReleaseCode detection by Bug.Center.Team