Hi:
I am trying to validate my data before the update using GridView with GridView1.AutoGenerateEditButton = true.
I almost tried all the Method names for GridView1 class but nothing is working for me yet. Where would be the best spot for my validations?
ty
You can validate your data from RowUpdating event(you can put your logic here):
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e){if (e.NewValues["col1"]==null){e.Cancel = true;return;}if (e.NewValues["col1"].ToString() == "old text"){e.NewValues["col1"] = "new text";}}You can read this:http://www.dotnetbips.com/articles/cb3e270c-db65-46e8-aa77-24736c36632c.aspx
Hi:
Here is my problem. I update one row at a time which has 12 columns. I loop through each column and get its value to see if the value is a numaric value. But Somehow when I loop through all the values for my cells are "" .
<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"DataKeyNames="email,edu_id"
DataSourceID="SqlDataSource5">
<Columns>
<asp:TemplateFieldShowHeader="False">
<asp:TemplateFieldHeaderText="Name and Location of College/University"SortExpression="edu_name"><EditItemTemplate>
<asp:TextBoxID="TextBox1"runat="server"Text='<%# Bind("edu_name") %>'></asp:TextBox>
<asp:RequiredFieldValidatorID="RequiredFieldValidator16"runat="server"ControlToValidate="TextBox1"
ErrorMessage="College Name Required"ValidationGroup="GridView1">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidatorID="RegularExpressionValidator26"runat="server"
ControlToValidate="TextBox1"ErrorMessage="Invalid College Name(only alphabets, numbers and .,/#- can be used)"
ValidationExpression="^[a-zA-Z0-9/./ //,#-/,]+"ValidationGroup="GridView1">*</asp:RegularExpressionValidator>
</EditItemTemplate>
<ItemTemplate>
I am doing this on my Delete botton Event in VB.
Here is my code:
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvView.RowUpdating
Dim value As String
Dim i_Cells As Integer
Try
With GridView1
For i_Cells = 0 To 11
value = .Rows(0).Cells(i_Cells).Text
Convert.ToDecimal(value)
Next
End With
Catch eException As Exception
clsMsg.UserMsgBox("All values must be numeric.", Me)
Exit Sub
End Try
End Sub
No comments:
Post a Comment