Row/Cell of Datagrid - Still need help! (Please?)

  • Thread starter Thread starter coleenholley
  • Start date Start date
C

coleenholley

I've been trying since last Friday to get an answer on how to get a SPECIFIC row.cell value from a datagrid. I've had plenty of suggestions, but nothing works to get the value from a SPECIFIC Row and cell. Right now I have this code

Sub Item_Bound(ByVal sender As Object, ByVal e As DataGridItemEventArgs
lbl_test.Text = lbl_test.Text & " " & e.Item.ItemInde
Session("wa_tot_gal") = e.Item.Cells(7).Tex
Response.Write(Session("wa_tot_gal")
End Su

it returns
1¢ Amount (NRS 373.030)000000000000000120

this information is from every row (including the header) I need the specific information for the value 12 returned to me so I can use that value as a session variable that needs to populate another web page table. I can NOT get it to return the SPECIFIC Row data! Please, can someone help me? Thanks much, Coleen
 
Dim ROW as Int32=1

Dim COL as Int32=1

MessageBox.Show(dgPeople.Item(ROW ,COL).ToString())


OHM
 
Hi Coleen,

I tested that code I did send you.

And that is not the code I see now.

Did it not work?

Cor
 
Thanks OHM, however it does not work. I tried:

Response.Write(dtg_worksheet1.Item(ROW, COL).ToString())

I can't use a messagebox in the ASPX VB code-behind, so I tired a Response.write - I get an error "Item is not a member of System.Web.UI.WebControls.DataGrid" - so I tried:

Response.Write(dtg_worksheet1.Items(ROW).ToString) - which gives me a compliation error "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index" Any other suggestions?
 
Hi Cor - Thanks, but no, it didn't. I can get the column, or the cell, but I NEED the specific row and cell value. What I really don't undertand, is why does it work perfectly in an ASP.Net table and yet there is no function for a datagrid to return the value of a specific Row().Cell()? Even if you don't know exactly how many rows are going to be returned, you should be able to get a specific Row/Cell value from a datagrid! I've read everything in the Help files I can find, tried all the suggestions and CAN'T get the specific Row/cell value I need. Any help is GREATLY appreciated. Thanks :-)
 
thr ROW and COL are just my variables, replace them with actual variables or
a number and try it. The messagebox was just a suggestion
 
Sorry, on my last post, I didn't put that I tried that..

Response.Write(dtg_worksheet1.Item(16, 7).ToString()) - I get an error (Blue Squigleys) that "Item is not a member of System Web.UI.WebControls.Datagrid. I tried using Items instead of Item, but still get an error "Too many arguments to Public.OVerloads ReadOnly Default propert Item(Index as Integer) as System Web.Ui.WebControls.DataGrid" Any suggestion on why I am getting these errors? Do I need to Import another System Namespace? Thanks for your help. COleen
 
Sorry Cor, I did not get your post from my other thread until just now. I tried your code and get this error:

Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index


This is the code I tried:

Dim a As String = dtg_worksheet1.Items(16).Cells(7).Text
Session("wa_tot_gal") = a
Response.Write(Session("wa_tot_gal"))


I've been remming one suggestion, trying another, and trying the help file suggestion of:
Dim X As String
X = e.Item.Cells(7).Text.IndexOf(16).ToString
Response.Write(X) - This returns me -1-1-1-1-1-1-1-1-1....

Thanks for all of your help :-)
 
Are you sure you tested this code and it did not work, I did test it on a
webform datagrid and it did give me back the information from the row and
the cell from the datagrid.

When clicked
Dim a As String = grd.Items(e.Item.ItemIndex).Cells(3).Text

or as you ask

Dim a as string = grd.Items(15).Cells(6).Text

And i got a row (Items) and a Cell value, I real do not understan why this
is not working with you.

Cor

Hi Cor - Thanks, but no, it didn't. I can get the column, or the cell,
but I NEED the specific row and cell value. What I really don't undertand,
is why does it work perfectly in an ASP.Net table and yet there is no
function for a datagrid to return the value of a specific Row().Cell()?
Even if you don't know exactly how many rows are going to be returned, you
should be able to get a specific Row/Cell value from a datagrid! I've read
everything in the Help files I can find, tried all the suggestions and CAN'T
get the specific Row/cell value I need. Any help is GREATLY appreciated.
Thanks :-)
 
Hi Colleen,

The 16th row is 15 because it starts on 0
The 7th cel is 6 because it starts on 0,

That was also in my sample.

Cor
Index was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index
 
Umm, are you saying that once the datagrid is populated, you click the row/cell and get the value? The trouble with that is that our users are not going to be clicking on this cell. I need the value to be passed automatically, without any intervention from the user.

The datagrid is read only, and is not always even going to be viewed. In other words, the user may choose not to view this page, but I must do a redirect to pass the session variable whether the user views the page or not, and the user is not going to know that the particular value needs to be clicked - it all needs to take place behind the scenes...

Thanks I will try it again, and see if I get values when the cell is clicked, then maybe I can devise a way to pass the value without clicking... I really do appreciate all of your help :-)
 
Yes, I know that the datagrid is 0 based - I have started at 0 counted over 7 columns and counted down 16 rows. I created an Excel Spreadsheet to space out the data so I could tell which row/cell the data I need would land in..

I just ran the program again with this exact code
Dim a As String = dtg_worksheet1.Items(16).Cells(7).Text - and I get this message

Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

The program builds ok with no errors, but won't complie becasue of that message..

I don't know why it doesn't work for me, either. The only explanation I can think of is that we do not connect to an SQL database using the Imports System Data.SqlClient Namespace. We connect to a Mainframe using an RPC written in Cobol the we write a class module (in VB.Net) to connect to. We do the same type of DataBind though, so I don't understand...
 
You can try this after the grid is data bound:
lbl_test.Text = ItemGrid.Items(12).Cells(7).Text

Or, you can use the Item_DataBound event:

Protected Sub ItemGrid_DataBound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs) _
Handles ItemGrid.ItemDataBound
If e.Item.ItemIndex = 12 Then
Session("wa_tot_gal") = e.Item.Cells(7).text
End If
End Sub


However, may I ask why you are doing this? it seems odd to bind the grid to
a datasource, then pull data out of that datagrid instead of getting the
data right from the source.

(Look at the DataTable's .Select() method, or the DataView's .RowFilter
property, etc...)

coleenholley said:
I've been trying since last Friday to get an answer on how to get a
SPECIFIC row.cell value from a datagrid. I've had plenty of suggestions,
but nothing works to get the value from a SPECIFIC Row and cell. Right now
I have this code:
Sub Item_Bound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
lbl_test.Text = lbl_test.Text & " " & e.Item.ItemIndex
Session("wa_tot_gal") = e.Item.Cells(7).Text
Response.Write(Session("wa_tot_gal"))
End Sub

it returns:
1¢ Amount (NRS 373.030)000000000000000120

this information is from every row (including the header) I need the
specific information for the value 12 returned to me so I can use that value
as a session variable that needs to populate another web page table. I can
NOT get it to return the SPECIFIC Row data! Please, can someone help me?
Thanks much, Coleen.Community Website: http://www.dotnetjunkies.com/newsgroups/
 
Thanks Phil - Actually I haven't tried putting the code in the class module instead of the VB code-behind! We connect to a DB2 database that resides on a mainframe - we have class module written in VB.Net that gets the data from and RPC to COBOL -it's complicated. I haven't tried getting the data before the datagrid is complied, I thought I could do this like you do an ASP.Net table - but obviously not :-( Let me try this in the class module using the Select method like you suggest. Sometimes you need to think outside the box...Thanks!
 
Hi Coleen

When you can count 17 rows and 8 collumns than this code should work in my
opinion.

But if you message again, than I will check it again tomorrow.

Late here

Cor
 
Thanks so much Cor :-)

Just out of curiosity - what country are you in? It's 2:42 p.m. on the West Coast of the U.S. I REALLY appreciate all the help I am getting. Like I said, I think the problem is in the way we connect to the datatable. I'm currently trying to write this in the Class Module that we us to call the data from the RPC, per Phil's suggestion. I never thought of that...

I'll post back to this thread to let you know what the result is. I'm going to keep trying - there has to be a way to get this to work...

Thanks again - have a good evening :-)

Coleen
 
Hi Coleen,


What Phil was writing was my thought a long time before when you started
this project, I told it again in my message before the last one, not this,
but I got more and more the idea that you had user actions involved with
this project.

If you want to know how to build a datatable from a flat file than ask, I
have so many samples for that.

And I am Dutch

Cor
 
I dont know why you are getting the problem that you are, but you *can*
definately access the cells with the code I gave you, I do it all the time
and in fact I created that little snippet from inside one of my working
programs, hence the *'dgPeople'* identifier for the grid in the example.

Something is seriously wrong with what you are doing and its probably going
to be really simple to determine like you have two grids and your accessing
the wrong one or something.


OHM
 
Hi OHM, Cor and Phil :-)

Sorry I did not respond last night, but my hard drive crashed! As if I needed that! Well, to let you all know, I AM using a web datagrid. The connection is done through an RPC to a COBOL program which gets the data from a DB2 database on a Mainframe. I suspect that this is the reason I am having so much trouble with all of the examples I have been given. The page I am accessing only has one datagrid on it dtg_worksheet1 - I've tried all the code you've all sent, unfortunately, nothing seems to work for me. I have since moved to the Class module that calls the RPC, and written a function to store the value for the session variable and pass that value to the .aspx page. I haven't been able to test it yet, since my hard drive crashed. I am currently using someone else's computer that does not have the same software configuration that I did, and I can't run the debugger in VS.Net to test if my code from yesterday (before my system crashed) works. Got to tell you all how much I appreciate your help. I'll post back or start a new post (since there is so much out there for Feb4) later today once my system is up and running again. The good news is that we were able to save my data, so I won't have lost all my code...

Thanks again - Coleen
 
Back
Top