Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.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# 如何查找在SelectedIndexChanged事件上触发的下拉列表的控件id_C#_Asp.net - Fatal编程技术网

C# 如何查找在SelectedIndexChanged事件上触发的下拉列表的控件id

C# 如何查找在SelectedIndexChanged事件上触发的下拉列表的控件id,c#,asp.net,C#,Asp.net,我有几个下拉列表,它们都会触发相同的OnSelectedIndexChanged事件。一旦OnSelectedIndexChanged事件触发,我想知道负责触发事件的下拉列表的id 有没有办法把这些信息拉成一个字符串 <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="updateView"> <asp:ListItem><

我有几个下拉列表,它们都会触发相同的OnSelectedIndexChanged事件。一旦OnSelectedIndexChanged事件触发,我想知道负责触发事件的下拉列表的id

有没有办法把这些信息拉成一个字符串

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="updateView">
   <asp:ListItem></asp:ListItem>
   <asp:ListItem>Not Started</asp:ListItem>
   <asp:ListItem>Submitted</asp:ListItem>
   <asp:ListItem>WIP</asp:ListItem>
   <asp:ListItem>Not Applicable</asp:ListItem>
   <asp:ListItem>Completed</asp:ListItem>
   <asp:ListItem>Rejected</asp:ListItem>
</asp:DropDownList>

<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" OnSelectedIndexChanged="updateView">
   <asp:ListItem></asp:ListItem>
   <asp:ListItem>Not Started</asp:ListItem>
   <asp:ListItem>Submitted</asp:ListItem>
   <asp:ListItem>WIP</asp:ListItem>
   <asp:ListItem>Not Applicable</asp:ListItem>
   <asp:ListItem>Completed</asp:ListItem>
   <asp:ListItem>Rejected</asp:ListItem>
</asp:DropDownList>

protected void updateView(object sender, EventArgs e)
{
    //string dd_id = id of dropdown that triggered this event;
}

没有开始
提交
在制品
不适用
完整的
拒绝
没有开始
提交
在制品
不适用
完整的
拒绝
受保护的void updateView(对象发送方、事件参数)
{
//字符串dd_id=触发此事件的下拉列表的id;
}

发送方是实际触发事件的控件。您可以尝试以下方法:

protected void updateView(object sender, EventArgs e)
{
    DropDownList ddl = sender as DropDownList;
    string dd_id = ddl.ID;
}

谢谢你的快速回复,这正是我想要的。工作完美。一旦系统允许,我会将此标记为答案。