0
私はasp.netページを2つのドロップダウンリストの値をデータベースと同じテーブルから作成しています。 2番目のドロップダウンリストに、最初のドロップダウンリストの選択に基づいて同じアカウント名を共有する独自の値(Acountコード)を自動的に入力するようにしたいと思います。ここに私のサンプルコードでは、私がアカウント名の値を変更した場合、アカウントコードが自動的に変更されません。..従うようasp.netの選択されたテキストボックスに基づいてドロップダウンリストの値を自動的にフィルターする方法
<span class="label">
<asp:Label ID="Label2" runat="server" Text="Account Name"</asp:Label>
</span>
<asp:DropDownList ID="name" runat="server"></asp:DropDownList><br />
<span class="label">
<asp:Label ID="Label3" runat="server" Text="Account Code"></asp:Label>
</span>
<asp:DropDownList ID="code" runat="server"></asp:DropDownList>
と私のC#のコードがある...私の場合は
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string CS = ConfigurationManager.ConnectionStrings["connection"].ConnectionString;
using (SqlConnection conn = new SqlConnection(CS))
{
SqlCommand comm = new SqlCommand("SELECT AccountName, AccountCode FROM Account", conn);
conn.Open();
name.DataSource = comm.ExecuteReader();
name.DataTextField = "AccountName";
name.DataValueField = "AccountName";
name.DataBind();
conn.Close();
if(name.Text != null)
{
conn.Open();
SqlCommand com = new SqlCommand("SELECT AccountCode FROM Account WHERE AccountName= '" + name.Text +"'", conn);
code.DataSource = com.ExecuteReader();
code.DataTextField = "AccountCode ";
code.DataValueField = "AccountCode ";
code.DataBind();
}
}
}
}
です。どうしたらいいの?