C# 使用CommandArgument访问GridView的内部DropDownList.SelectedValue
当DropDownList“eventnoteEditDrpDwnLst”的值设置为“Custom…”时,我想在GridView中将“Visible=true”设置为文本框“eventnoteAddTextBox”C# 使用CommandArgument访问GridView的内部DropDownList.SelectedValue,c#,asp.net,.net,gridview,C#,Asp.net,.net,Gridview,当DropDownList“eventnoteEditDrpDwnLst”的值设置为“Custom…”时,我想在GridView中将“Visible=true”设置为文本框“eventnoteAddTextBox” ... ... 代码隐藏 protected void grid_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("AddCustomEventNote"))
...
...
代码隐藏
protected void grid_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("AddCustomEventNote"))
{
DropDownList eventnoteAddDrpDwnLst = (DropDownList)e.CommandSource;
if (eventnoteAddDrpDwnLst.SelectedValue == "Custom...")
Response.Write("<script>alert('It works!');</script>");
//grid.FooterRow.FindControl("eventnoteAddTextBox").Visible = true;
}
}
protectedvoid grid\u row命令(对象发送方,GridViewCommandEventArgs e)
{
if(e.CommandName.Equals(“AddCustomEventNote”))
{
DropDownList eventnoteAddrPDWnlst=(DropDownList)e.CommandSource;
如果(eventnoteAddDrpDwnLst.SelectedValue==“自定义…”)
响应。写入(“警报('It works!');”;
//grid.FooterRow.FindControl(“eventnoteAddTextBox”).Visible=true;
}
}
这不起作用。这应该可以
protected void grid_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("AddCustomEventNote"))
{
DropDownList eventnoteAddDrpDwnLst = (DropDownList)grid.FooterRow.FindControl("eventnoteAddDrpDwnLst");
string value = eventnoteAddDrpDwnLst.SelectedValue;
}
}
实际上,
应该有自动回发和一个单独的调用函数。它可以被
和
覆盖,以使动作顺畅
<asp:DropDownList ID="eventnoteAddDrpDwnLst" runat="server" DataTextField="eventnote" DataValueField="eventnote" AutoPostBack="true" OnSelectedIndexChanged="eventnoteAddDrpDwnLst_SelectedIndexChanged" />
它真的有效DropDownList没有CommandArgument我也不知道该把什么作为“CommandArgument”放进去。它应该是空的吗?!它应该为空,因为您不需要静态值,所以您需要在下拉列表中选择的值。如果它是一个按钮或某个可以有一个静态值作为发送方的东西,而不是一个下拉列表,那么
CommandArgument
就有意义了(除非除了所选项中的值之外,您还需要一些额外的值)。它似乎根本不起作用。看,我编辑了一些以便更清楚。对不起,我没有注意到控件在页脚行。我更新了我的答案。试试看。不,还是不行。我终于找到了解决办法。无论如何,谢谢你。
<asp:DropDownList ID="eventnoteAddDrpDwnLst" runat="server" DataTextField="eventnote" DataValueField="eventnote" AutoPostBack="true" OnSelectedIndexChanged="eventnoteAddDrpDwnLst_SelectedIndexChanged" />
protected void eventnoteAddDrpDwnLst_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList eventnoteAddDrpDwnLst = (DropDownList)grid.FooterRow.FindControl("eventnoteAddDrpDwnLst");
if (eventnoteAddDrpDwnLst.SelectedValue == "Custom...")
grid.FooterRow.FindControl("eventnoteAddTextBox").Visible = true;
else
grid.FooterRow.FindControl("eventnoteAddTextBox").Visible = false;
}