Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid Upda te Question...

Status
Not open for further replies.

bartee

MIS
Mar 20, 2005
147
US
I am using visual studio 2005 and have a question regarding an updateable gridview.

The gridview on my page has 4 columns, and only one is able to be updated. It's a textbox.

However, when updated, I want to validate the entry against a table in my database before processing the update. In other words, when the user clicks the update button, I want to check the entry to see if it's valid before posting back the update. If it's not, I want to display an alert message.

What's the best way to accomplish this?

Would the custom validator control be used for this type of situation (I have not used it to date)?

Any suggestions would be greatly appreciated. Thanks in advance.



 
Yes, a custom validator would probably be a good choice and here's a couple of articles on them that you should read:


As a side note, you've asked 40 questions in this forum so far yet have only responded to 19 of those and haven't marked any posts a helpful. If you want to get the best out of these forums, I suggest you read the FAQ in my signature, especially #15.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Thanks for the feeback regarding my question.

Also, you make a good point regarding your side note. I will follow-up on any future posts.

Thanks again.
 
There is one more problem I'm having with the custom validator control.

I have it set in the edit item template of my gridview.

I have the control set to validate textbox1.

However, I would like to compare it to the value of another textbox in the gridview for the row being edited.

I put the following in my server side validation function for the custom control but it is not working correctly.

Dim TextBoxa As New TextBox
TextBoxa = grid_showall.SelectedRow.FindControl"textbox2")

I would then use the text value of textbox2 and compare it with textbox1 (args.value) in the custom validator.

Again, any suggestions greatly appreciated.

Thanks.

 
Try..

Dim TextBoxA As TextBox = CType(grid_showall.SelectedRow.FindControl("textbox2"),TextBox)

???
 
Thanks for the reply. However, I still get the following error:

Object reference not set to an instance of an object.

Remember, the textbox I'm trying to reference is in the gridview -- which only displays when the grid is in update mode.

The code you suggested does seem to work for other textboxes on the page but not in the gridview.

Thanks again.
 
You have to check if the row is in update mode in the RowDataBound event:
Code:
If e.Row.RowState = DataControlRowState.Edit Then
   Dim TextBoxa As New TextBox
   TextBoxa =grid_showall.SelectedRow.FindControl"textbox2")
End If

Jim
 
problem I'm still having is that I need to find the value of the control during the function for the custom validator.

I need the most current value of the text box in the grid -- even if the user changes it after the grid is bound and before clicking update on the grid.

Example of the current function for the custom validator in the "edit item" template of the grid.

Sub ServerValidation(ByVal sender As Object, ByVal args As ServerValidateEventArgs)

Dim TextBoxA As TextBox = CType(grid_showall.SelectedRow.FindControl("TextBox2"), TextBox)

If TextBoxA.Text = "5" Then
args.IsValid = True
Else
args.IsValid = True
End If

End Sub


Hoping I'm making sense.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top