Hi,
How can I validate an empty gridview ?
When I click on the save button of a form, there are a couple of validation, like text boxes that may not be empty and ohter things. (works fine)
but how can I do a validation to see if there are records inside the gridview.
Thanx,
Birgit
Hi
You can checkif GridView1.Rows.count> 0 then
' Do somthing if grid is not empty
Else
' Do somthing if grid is empty
End if
Hope this will help You
If you just want to know if records exist within your GridView, you can check the GridView.Rows.Count property within the GridView.DataBound event. Or, if you are using some sort of DataSourceControl like a SqlDataSource or an ObjectDataSource, then you can use its corresponding Selected event and check the AffectedRows property.
Thanks for the replies,
but I want to do the check before I go into my code.
So when I click on my button Save, he must first check whether all the necessary fields are filled in, if not, he doesn't go in my code. Just like u do with required field validators...
Is it possible to do the validation on a gridview with a required field validator ?
thanx !
If you create your own EditItemTemplates, you can add your own RequiredFieldValidators to your TextBoxes or other controls.
Yep that's right, but I'm already having that FieldValidators in my editItemTemplates...
I must have an extra validator when I click on my Save button of my whole form...
So I've to check if there are textboxes filled in and also I'v to check if I've added some records to my gridview.
(Maybe this helps for explanation: in the beginning my gridview is empty, I'm working with an offline datatable, when I click on save, I first save a couple of textboxes in one table, then I get the ID of that saves row back, and that ID I use for saving my gridview (offline datatable) to the database)
greetz.
It sounds like you'll have to add a CustomValidator of some sort.
Maybe that is possible, but do you know how ?
Thanx !
If I understand what you're trying to do, in the ServerValidate event handler for your CustomValidator you'll have to loop through all of the rows in your GridView checking to see if any TextBoxes have information within them. If not, set the IsValid property of the ServerValidateEventArgs class to false to set the error. Outside of that, the implementation is up to you.
if (GridView1.Rows.Count != 0)
{
// Wiite the code if gridview is not empty
}
else
{
// Wiite the code if gridview is empty
}
Is it possible to connect *view to dummy table with records like "Not selected" or similar if there is no real data to show. And how.
About "If you create your own EditItemTemplates, you can add your own RequiredFieldValidators to your TextBoxes or other controls." What this means and how do you that.
Regards
Leif
No comments:
Post a Comment