protected void btnAddLocation_Click1(object sender, EventArgs e) { var userId = Convert.ToInt32(Session[sessionNames.userID_Karbar]); if (IsValid) { List<Location> loclist = (List<Location>)ViewState["loclist"]; Location loc = new Location(); loc.Name = txtLocationName.Text; loc.Address = txtAddress.Text; bool found = false; if (grdLocationList.Rows.Count > 0) { foreach (GridViewRow row in grdLocationList.Rows) { if (row.Cells[0].Text == loc.Name || row.Cells[1].Text == loc.Address) { ClientScript.RegisterStartupScript(GetType(), "alert", "alert('این محل از قبل موجود است !');", true); found = true; } } if (!found) { LocationHandler locH = new LocationHandler(); locH.AddNewLocation(loc, userId); txtLocationName.Text = ""; txtAddress.Text = ""; BindGrid(); } } else { LocationHandler locH = new LocationHandler(); locH.AddNewLocation(loc, userId); txtLocationName.Text = ""; txtAddress.Text = ""; BindGrid(); } } }