嗨,基本上我的 mapXtreme 工作区中有 2 个表。一个有城市的cityName 和车牌号。另一个有城市的区名和车牌号。在我的网页中,我有 2 个下拉列表和 1 个按钮。
我可以在第一个下拉列表中显示城市名称。我正在尝试的是在我从第一个列表中选择城市并单击按钮后显示所选城市的地区。我怎样才能做到这一点?
这是我尝试运行时浏览器上的代码和错误消息的更新版本
:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
/*******************************************/
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MapInfo.Data;
using MapInfo.WebControls;
using ApplicationStateManager;
public partial class myWebForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (StateManager.IsManualState())
{
// If the StateManager doesn't exist in the session put it else get it.
if (StateManager.GetStateManagerFromSession() == null)
{
//instanciate AppStateManager class
AppStateManager myStateManager = new AppStateManager();
//put state manager to session
StateManager.PutStateManagerInSession(myStateManager);
//put current map alias to state manager dictionary
myStateManager.ParamsDictionary[StateManager.ActiveMapAliasKey] = this.MapControl1.MapAlias;
}
// Now Restore State
StateManager.GetStateManagerFromSession().RestoreState();
}
string myQuery = "SELECT cityName FROM CITIES";
MIConnection myConnection = new MIConnection();
MICommand myCommand = new MICommand(myQuery,myConnection);
myConnection.Open();
MIDataReader myReader = myCommand.ExecuteReader();
DropDownList1.Items.Clear();
while (myReader.Read()) {
DropDownList1.Items.Add(new ListItem(
myReader["cityName"].ToString()));
}
myConnection.Close();
myReader.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = DropDownList1.Text;
string cityPlateNumber = "SELECT plateNo from CITIES where cityName = \' " + DropDownList1.Text + " \'";
string cityNo;
MIConnection connect_cityPlateNumber = new MIConnection();
MICommand command_cityPlateNumber = new MICommand(cityPlateNumber, connect_cityPlateNumber);
connect_cityPlateNumber.Open();
MIDataReader reader_cityPlateNumber = command_cityPlateNumber.ExecuteReader();
cityNo = reader_cityPlateNumber["plateNo"].ToString();
string myQuery2 = "SELECT IlceAdi from ILCELER WHERE plateNo = \' " + cityNo + " \'";
connect_cityPlateNumber.Close();
reader_cityPlateNumber.Close();
MIConnection connectIlce = new MIConnection();
MICommand commandIlce = new MICommand(myQuery2, connectIlce);
connectIlce.Open();
MIDataReader readerIlce = commandIlce.ExecuteReader();
DropDownList2.Items.Clear();
while (readerIlce.Read())
{
DropDownList2.Items.Add(new ListItem(
readerIlce["IlceAdi"].ToString()));
}
connectIlce.Close();
readerIlce.Close();
}
// At the time of unloading the page, save the state
private void Page_UnLoad(object sender, System.EventArgs e)
{
if (StateManager.IsManualState())
{
StateManager.GetStateManagerFromSession().SaveState();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
}
}