|
-
May 15th, 2008, 02:50 PM
#1
Thread Starter
PowerPoster
[RESOLVED] There is so a row a position 0
My code:
Code:
Sub PopulateGrid()
Me.gvDocList.Visible = False
GetDataForGrid(ds)
If ds.Tables.Count = 0 Then Exit Sub
If ds.Tables(0).Rows.Count = 0 Then Exit Sub
Me.gvDocList.Visible = True
Try
Me.gvDocList.DataSource = ds
Me.gvDocList.DataBind()
Catch ex As Exception
Response.Write("Exception in PopulateGrid(): " + ex.Message)
End Try
End Sub
The exception I am getting:
Exception in PopulateGrid(): There is no row at position 0.
What the debugger says after I get the exception:
? ds.Tables(0).Rows(0).Item(0).ToString
"10304"
Isn't that a row at position zero??? I must be tired...I should've gotten that free iced coffee at DD today
-
May 15th, 2008, 02:57 PM
#2
Re: There is so a row a position 0
at what line you are getting this exception.......what value of ex.tostring
-
May 15th, 2008, 03:01 PM
#3
Frenzied Member
Re: There is so a row a position 0
where is the code for GetDataForGrid(ds)
-
May 15th, 2008, 03:13 PM
#4
Frenzied Member
Re: There is so a row a position 0
Also check to see if your page is running through the code twice... sometimes I get buttons that bug out and do that.. in that case I just delete the button and replace it with another.
-
May 15th, 2008, 03:27 PM
#5
Thread Starter
PowerPoster
Re: There is so a row a position 0
 Originally Posted by riteshjain1982
at what line you are getting this exception.......what value of ex.tostring
I am calling the exception handler when this line executes: Me.gvDocList.DataBind()
-
May 15th, 2008, 03:31 PM
#6
Re: There is so a row a position 0
check if you have any itemdatabound event for dgDOCList ?
-
May 15th, 2008, 03:33 PM
#7
Thread Starter
PowerPoster
Re: There is so a row a position 0
 Originally Posted by Besoup
where is the code for GetDataForGrid(ds)
Code:
Sub GetDataForGrid()
Dim connString As String = _
ConfigurationManager.ConnectionStrings("ConnectMe").ConnectionString
Dim conn As New SqlConnection(connString)
Dim command As New SqlCommand()
command.CommandType = CommandType.StoredProcedure
command.Connection = conn
command.CommandText = "up_DocList"
command.Parameters.Add(New SqlParameter("@cstmr_addr_ik", Data.SqlDbType.Int))
command.Parameters("@cstmr_addr_ik").Value = sCustomerAddrIk
Dim adapter As New SqlDataAdapter(command)
Try
adapter.Fill(ds)
Catch ex As Exception
Response.Write("GetDataForGrid Exception " + ex.Message)
conn.Close()
Exit Sub
Finally
conn.Close()
End Try
End Sub
ds is defined global in the class:
Code:
Dim ds As New DataSet
I should tell you that this was working perfectly when I defined the SqlDataSource in my designer and set the gridview property to use it also in the designer. I was just running a simple stored proc that took one parameter. Now I am making it more sophisticated in that I have to build the WHERE clause in the stored procedure according to what I pass in for criteria. So I moved the logic to the code-behind. But before even adding the logic for the WHERE clause, I thought I'd check to make sure it still works as it was. Good thing, since it doesn't...
And everything seems to be executing just once... no odd behavior noticed.
Thanks for your help Besoup and riteshjain1982.
-
May 15th, 2008, 03:39 PM
#8
Re: There is so a row a position 0
did u checked for ItemDataBound event of dgDOCList ?
-
May 16th, 2008, 05:36 AM
#9
Thread Starter
PowerPoster
Re: There is so a row a position 0
 Originally Posted by riteshjain1982
did u checked for ItemDataBound event of dgDOCList ?
No, I hadn't checked this. You and I were cross-threading...
Anyway, it is a gridview not a datagrid but you are absolutely right! In the gridview's RowDataBound event I am doing additional processing to format the last column of my grid. I make another call to the database. I don't have an exception handler here . So my exception was bubbling up and the wrong procedure was getting blamed.
I should've seen the symptoms of this. On my page, the grid's first row was getting generated except for the last column and then I exceptioned (did I say I was tired yesterday?!)
Thank you so much!
Marlene
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|