Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用CommandArgument访问GridView的内部DropDownList.SelectedValue_C#_Asp.net_.net_Gridview - Fatal编程技术网

C# 使用CommandArgument访问GridView的内部DropDownList.SelectedValue

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"))

当DropDownList“eventnoteEditDrpDwnLst”的值设置为“Custom…”时,我想在GridView中将“Visible=true”设置为文本框“eventnoteAddTextBox”


...
...
代码隐藏

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;
    }