you can use SelectedItem
property of the DropDownList
Control to achieve this.
1. get the SelectedItem
of the first DropDownList
.
2. get the SelectedItem
of the second DropDownList
.
3. compare both of the SelectedItem
values using Equals()
method.
4. if the items do not match , display an alert
box using javascript
as MessageBox
is not bydefault avaialble in Webforms (in webforms it is good to use javascript alert
) using following Syntax:
Response.Write(@"<script language='javascript'>alert('message here');</script>");
Complete Code: (Code Behind)
Try This:
protected void Button1_Click(object sender, EventArgs e)
{
if (!ddlcountry.SelectedItem.ToString().Equals(ddlcountry_Res.SelectedItem.ToString()))
{
Response.Write(@"<script language='javascript'>alert('Items do not match.');</script>");
}
}