Nurali says:
protected void Save(object sender, EventArgs e)
{
string selected = "";
int selectedCount = 1;
string selectedValues = Request.Form[dropFruits.UniqueID];
foreach (string item in selectedValues.Split(‘,’))
{
selected = string.Join(",",selectedValues);
selectedCount++;
}
}
Change the above code with the below code.
protected void Save(object sender, EventArgs e)
{
string selected = "";
int selectedCount = 0;
string selectedValues = Request.Form[dropFruits.UniqueID];
if (!string.IsNullOrEmpty(selectedValues))
{
foreach (string item in selectedValues.Split(','))
{
selected = string.Join(",", selectedValues);
selectedCount++;
}
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You must select fruit')", true);
}
}