Wednesday, March 21, 2012

Please help itemcommand event for a datagrid checking wether the field is blank or not

Please help, I have a problem validating the date field.

When ever if the date field is blank i want to raise the Jscript, But it does'nt work.

Only with date i have the problem rest all fields work excellent, if they are blank it does show the javascript message.

Following code is used under the itemcommand of the datagrid.

txtid = e.Item.FindControl("eventid_add")
txtdate = e.Item.FindControl("eventdt_add")
txtref = e.Item.FindControl("eventref_add")

If txtid.Text <> "" And txtdate.Text <> "" And txtref.Text <> "" Then
'do this
Else
'javascript popup
Dim AlertScript As String
AlertScript = "<script language='javascript'>" & _
"alert('Event Date and Reference No. are required!')" & _
"</script>"
Page.RegisterStartupScript("AlertScript", AlertScript)
End If

Thank you very much for the information.Try doing this on the OnItemDataBound event. During OnItemCreated the data is not bound to the datagrid yet, so it is not accessible.

And if it still doesn't work, try to access the data in the datasource(still during OnItemDataBound), not the datagrid; (my example is C#, but you should get the picture)


if (DataBinder.Eval(e.Item.DataItem, "eventdt_add" == DbNull.Value) {
//do your thing
}

0 comments:

Post a Comment