Hi, I'm using the following code to get the DataKeyValue of the edited row in the ServerValidate function. This is working well when editing a record. However, when creating a new record, item.GetDataKeyValue("ID") throws an argument out of range exception. Is there a way that I can test whether a DataKeyValue exists before making this call? Thanks.
protected void URLGrid_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args) { CustomValidator val = (CustomValidator)source; GridDataItem item = (GridDataItem)val.NamingContainer; intwebsiteID = int.Parse(item.GetDataKeyValue("ID").ToString()); if(!Website.URLIsUnique(websiteID, args.Value.Trim())) { args.IsValid = false; } }