gpt4 book ai didi

c# - 单击按钮时如何检查下拉索引是否已更改?

转载 作者:太空宇宙 更新时间:2023-11-03 14:54:06 24 4
gpt4 key购买 nike

我有一个提交按钮,在提交按钮上单击我想检查我的下拉列表的选定索引是否已更改。如果是,它应该调用一个函数。

我不知道如何在 asp.net C# 中执行此操作,需要帮​​助。

<asp:DropDownList ID="ddlIncidentStatus" runat="server" 
Enabled="false"
Display="Dynamic"
AppendDataBoundItems="True"
AutoPostBack="true"
CssClass="form-control">
<asp:ListItem Value="0">- Select Incident Status -</asp:ListItem>
</asp:DropDownList>

protected void btnSave_Click(object sender, System.EventArgs e)
{
if ((SaveToMemory() > 0))
{
//here i want to check if ddlIncidentStatus has change the value or not
Response.Redirect(("IncidentReport_New.aspx?OHSIncidentID=" +
Encryption.EncryptParameter(_incident.OHSIncidentID.ToString())));
}
}
}

最佳答案

例子.aspx

<%@ Page Title="Home Page" Language="C#" AutoEventWireup="true"   
CodeBehind="Default.aspx.cs" Inherits="DropDownListExample._Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<p>Select a City of Your Choice</p>
<div>
<asp:DropDownList ID="DropDownList1" runat="server" >
<asp:ListItem Value="">Please Select</asp:ListItem>
<asp:ListItem>New Delhi </asp:ListItem>
<asp:ListItem>Greater Noida</asp:ListItem>
<asp:ListItem>NewYork</asp:ListItem>
<asp:ListItem>Paris</asp:ListItem>
<asp:ListItem>London</asp:ListItem>
</asp:DropDownList>
</div>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />
<br />
<br />
<asp:Label ID="Label1" runat="server" EnableViewState="False"></asp:Label>
</form>
</body>
</html>

示例.aspx.cs

protected void Button1_Click(object sender, EventArgs e)  
{
if (DropDownList1.SelectedValue == "")
{
Label1.Text = "Please Select a City";
}
else
Label1.Text = "Your Choice is: " + DropDownList1.SelectedValue;
}

关于c# - 单击按钮时如何检查下拉索引是否已更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50493292/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com