我对回传/DDL 不太熟悉。是的,我使用过 autopostback = true!
下面,我正在尝试更改选定的索引...以在budgetDDL1 上触发但是,无论我尝试什么都不会!
我正在将数据库中的数据绑定到 ddl ...
我已经尝试将 ddl 绑定/添加到 post backs 内部/外部的表并启用/禁用视图状态等。这些都不起作用.. 必须有一个简单的答案?!
我需要以什么顺序为索引更改方法创建/绑定下拉列表以触发解释也很有用!
DropDownList budgetDDL1 = new DropDownList();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string QueryString = "SELECT [BudgetCode], [Department], CONCAT([BudgetCode],' - ', [Department]) AS 'textvalue' FROM [tblBudget]";
using (SqlConnection myConnection = new SqlConnection(ConnectionString))
{
using (SqlCommand cmd = new SqlCommand(QueryString, myConnection))
{
myConnection.Open();
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
DataTable dt = new DataTable();
dt.Load(dr);
budgetDDL1.SelectedIndex = 0;
budgetDDL1.DataSource = dt;
budgetDDL1.DataTextField = "textvalue";
budgetDDL1.DataValueField = "BudgetCode";
budgetDDL1.AutoPostBack = true;
budgetDDL1.SelectedIndexChanged += budgetDDL1_SelectedIndexChanged;
budgetDDL1.DataBind();
}
}
}
table1.Controls.Add(budgetDDL1);
}
protected void budgetDDL1_SelectedIndexChanged(object sender, EventArgs e)
{ *I have a breakpoint here which doesn't fire*
string msg = budgetDDL1.SelectedItem.Text;
ScriptManager.RegisterClientScriptBlock(sender as System.Web.UI.Control, this.GetType(), "alert", "alert('" + msg + "')", true);
}
view:
<body>
<form runat="server">
<table>
<tr>
<td id="table1" runat="server">
</td>
</tr>
</table>
</form>
</body>
慕无忌1623718
相关分类