Current location: Hot Scripts Forums » Programming Languages » ASP.NET » Problem getting data from DataGrid on update


Problem getting data from DataGrid on update

Reply
  #1 (permalink)  
Old 10-30-03, 07:54 PM
petersza petersza is offline
Newbie Coder
 
Join Date: Oct 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Problem getting data from DataGrid on update

I have set up a DataGrid with an EditCommandColumn. When the user clicks the update button, the associated event procedure runs. Of course, one of the things that needs to be done in that procedure is to get the data that is to be updated from the current row of the grid. I am miserably confused about how to do this after reading several books, searching google, and so on. I can get the ID, which is an integer, like this:

Public Sub dgTrailers_Update(ByVal Sender As Object, ByVal e as DataGridCommandEventArgs)
Dim ID as Integer = e.Item.Cells(0).Text
End Sub

This works without any errors. But this doesn't work for the other columns, one of which is also an integer (!) and the other a string. Here's one attempt to get the data in the second column (Integer):

Public Sub dgTrailers_Update(ByVal Sender As Object, ByVal e as DataGridCommandEventArgs)
Dim TrailerYear as Integer = e.Item.Cells(1).Text
End Sub

I get this error: Input string was not in a correct format.

Here's another attempt to get the same data:

Public Sub dgTrailers_Update(ByVal Sender As Object, ByVal e as DataGridCommandEventArgs)
Dim TrailerYear as Integer = CType(e.Item.Cells(1).Controls(0), TextBox).Text
End Sub

I get this error: Specified cast is not valid.

Now, here's a similar attempt to get the String value in the third column, which gives me the same "Specified cast is not valid" error.

Public Sub dgTrailers_Update(ByVal Sender As Object, ByVal e as DataGridCommandEventArgs)
Dim TrailerMake as String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
End Sub


I'd like to know:

1. Specifically, what am I doing wrong in this case?
2. In general, what is the proper syntax for retrieving data for the different data types? Can anyone provide a comprehensive explanation of this, or point me to somewhere that explains it clearly so that the day that I need to grab some other kind of data from the grid, I will be able to?

Thank you!

Peter
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-17-03, 11:48 PM
Pvialoux Pvialoux is offline
New Member
 
Join Date: Nov 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
I have been having a similar problem.
However, on reviewing e.item.cells(2).controls(0) in quickwatch, I discovered that it was NOT a textbox!
I checked e.item.cells(2).controls(1) and this was a textbox.
I have not created any other controls that I am aware of in this cell. But, when I tested the code with the controls(1) reference it worked.
I'm still working on the "Why"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 12-19-03, 07:37 AM
devnoronha devnoronha is offline
New Member
 
Join Date: Dec 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
here's what i think is wrong . the cells collection starts from iterating from 0 , not 1 . My guess is that the databound column is the first one , not the second . so, instead of
Dim TrailerYear as Integer = CType(e.Item.Cells(1).Controls(0), TextBox).Text
try
Dim TrailerYear as Integer = CType(e.Item.Cells(0).Controls(0), TextBox).Text

see if that works and tell me .
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 05-07-04, 03:48 PM
Rbytez Rbytez is offline
New Member
 
Join Date: May 2004
Location: Chile
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Smile Re :Problem getting data from DataGrid on update

This are the errors was i found in your code..

Public Sub dgTrailers_Update(ByVal Sender As Object, ByVal e as DataGridCommandEventArgs)
Dim ID as Integer = e.Item.Cells(0).Text
End Sub

This works without any errors. But this doesn't work for the other columns, one of which is also an integer (!) and the other a string. Here's one attempt to get the data in the second column (Integer):

THIS WORK , BECUASE THE FIRST COLUMN IS "READ ONLY", I GUESS.
IN THE OTHER COLUMS YOU HAVE USE THE Val() FUNCTION FOR THE COLUMNS WHICH ARE INTEGER, FOR EXAMPLE :


Public Sub dgTrailers_Update(ByVal Sender As Object, ByVal e as DataGridCommandEventArgs)
Dim TrailerYear as Integer = VAL(e.Item.Cells(1).Text)
End Sub

Public Sub dgTrailers_Update(ByVal Sender As Object, ByVal e as DataGridCommandEventArgs)
Dim TrailerYear as Integer = VAL(CType(e.Item.Cells(1).Controls(0), TextBox).Text)
End Sub

HERE, I DONT KNOW WHY NOT WORK, WHICH IS THE NUMBER OF THE EDITCOLUMN?, MAYBE YOU HAVE WRONG INDEX, CHECK IT

Public Sub dgTrailers_Update(ByVal Sender As Object, ByVal e as DataGridCommandEventArgs)
Dim TrailerMake as String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
End Sub

GREETINGS FROM CHILE
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 09-17-04, 02:40 PM
alexsaves alexsaves is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Ctype?

I'm not sure that's the solution.. will think about this

----------------------
ASP Grid control - http://www.aspgrids.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 10-20-04, 12:37 AM
thuenb thuenb is offline
Newbie Coder
 
Join Date: Oct 2004
Location: MI
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Try this Debugging step...

add the following into your code before the error line to see if you can figure out the type of control it thinks you are actually trying to work with...

Then you can change the values around until you get the correct control...
Code:
response.write(e.Item.Cells(2).Controls(0).GetType.ToString)
Hope this helps...
__________________
Best Regards,
Brian Thuen
http://www.AdvisedSolutions.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Add data to datagrid? petersza ASP.NET 2 04-11-04 11:13 PM
How to Extract Intra Day Stock Price Data from Java Chart??? (only source of data!!) omkarsnisal Everything Java 0 10-29-03 03:25 AM
type mismatch and update loop - HELP! seala ASP 1 09-22-03 06:27 PM
How to download data from datagrid to Excel? engheegoh ASP 0 09-14-03 11:44 PM
Print data by date perleo PHP 2 08-09-03 10:35 AM


All times are GMT -5. The time now is 12:37 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.