我想在GridView_RowCommand中查找DropDown元素,但它表示GridViewCommandEventArgs不包含「行」的定義。我需要在這個事件中這樣做,因爲我正在評估一個GridView命令。見沒有下面的代碼如何訪問RowCommand事件中的行
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Add")
{
DropDownList Myddl = null;
ClientClass client = new ClientClass();
Myddl = e.Row.FindControl("ddlClients") as DropDownList;
if (Myddl != null)
{
updated = client.InsertUpdateClient(ClientID,
int.Parse(e.CommandArgument.ToString()), departmentID);
}
else
{
Labels.Text = "There was an error updating this client";
}
}
}
對不起,我有點新本..它在哪兒找到這裏滴下來?我的下拉是在ItemTemplate – edcod81
哦,我看到像這樣的GridView行=(GridView)(((DropDownList)e.CommandSource).NamingContainer); Myddl = row.FindControl(「ddlClients」)爲DropDownList; – edcod81
@ edcod81 - 不!它不會投!您必須使用LinkButton或Button或ImageButton。您使用了哪種按鈕類型? – adatapost