作者 主題: asp .net 城市區域對照使用Dropdownlist  (閱讀 4807 次)

0 會員 與 1 訪客 正在閱讀本文。

小徒兒

  • 區域板主
  • 鑽研的研究生
  • *****
  • 文章數: 622
    • 檢視個人資料
asp .net 城市區域對照使用Dropdownlist
« 於: 2005-06-05 06:44 »
environment: Server 2003

1.ensure the enviroment has setup

/visual studio .net tool/command line

安裝.net framwork

 1.1. aspnet_regiis -i
 1.2. aspnet_regiis -r
 1.3. aspnet_regiis -c

 1.4. /iis control
 1.5. start up the web page extension service allow


2. open a new project with C# and webapplicaton named: CityAreaDemo

3. download the access file

http://solosoho.com/mcsd/CityAreaDemo//getmdb.html
to save in the /interpub/wwwroot/CityAreaDemo folder

4. open the project and set up the coonection

/database connection/new connection

provider: JET 4.0 oledb
connection: the location of file

5. unlock the mdb'd mdl

5.1 select the /interpub/wwwroot/CityAreaDemo folder

give the edit right to web service USER

5.2 open the iis service control ????
give the edit right to web service USER

5.3 close all accesss application

5.4 close the connection on the vs.net

6.drag and drop 2 DropDownList control on Webform1

named droCity
named droArea

7.drag and drop the connection table on webform1, it will generate 2 dataadapter and 1 dataConnection:

named conn
named daCity
named daArea

7.2 right click daCity, make sure City and Area tables are checked, and generate dataset:

named ds

8. write the new connectionString to overcome the location problem,

8.1 set droAea and droCity controls' property:


            droCity      droArea
DataSource          ds                                ds
DataMember         城市                                      區域
DataTextField    城市名稱                     區域名稱
DataValueField    城市編號                     區域編號

8.1.2 change the sql command of daCity's to:
SELECT 城市編號, 區域名稱, 區域編號, 郵遞區號 FROM 區域 WHERE (城市編號 = ?)

8.1.3 change the droCity with the datamember with adding the parameters feather ???

8.2 when it is first load: fill the ds with daCity, and then bind the ds with droCity Control, call the function droCity_SelectedIndexChanged to use daArea fill in ds, and bind


--------------------------------------------------------------------------------
private void Page_Load(object sender, System.EventArgs e)
      {
         conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("CityArea.mdb"); //8.
         if (!Page.IsPostBack)
         {
            daCity.Fill(ds);
            droCity.DataBind();
 //8.2
            droCity_SelectedIndexChanged(null, null); 8.3
         }
      }




--------------------------------------------------------------------------------


private void droCity_SelectedIndexChanged(object sender, System.EventArgs e)
      { //8.3
         daArea.SelectCommand.Parameters["城市編號"].Value = droCity.SelectedItem.Value;
         daArea.Fill(ds);
         droArea.DataBind();
      }




9. press F5 to run, and try it

Done