我有一個DataGrid控件(不是GridView),它有4列。其中一列是DropDownList。我想要做的是從我的dgTicket_ItemDataBound(.....)進程訪問DropDownList控件,但我沒有成功。如何在我的DataGrid中訪問我的下拉列表控件?
我研究並嘗試了幾種不同的方式,但沒有成功。
這是我有:
protected void dgPrintTicket_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
string SQL1 = @"SELECT Machine_Id FROM SFD00006 WHERE WC_Id = '" + wc + "'";
DropDownList ddl = (DropDownList)e.Item.Cells[2].FindControl("ddlMachId");
string val = ((DropDownList)dgPrintTicket.SelectedItem.Cells[2].FindControl("ddlMachId")).Text;
if (ddl != null)
{
ddl.DataSource = Lib.getArrayList(SQL1);
ddl.SelectedValue = val;
ddl.DataBind();
}
}
我要訪問DropDownList的,並與所有的機器代碼,我從我的select語句得到,但我的DDL不斷回來爲空填充它。
任何幫助將不勝感激。
謝謝大家。
山姆
只是想附和,這是非常不安全的代碼,因爲它很容易讓SQL注入。 http://en.wikipedia.org/wiki/SQL_injection –