Some .net datalist help
Kamon | Posted 10:48am 12. October 2005 Server Time |
When I press a button assosiacted with the edit command of a datalist my code is supposed to redirect to edit.aspx?RID=xxx.
I have the datakey set to the recordID and during the sub this code is run
Response.Redirect("EditDrawings.aspx?RID=" & lstDraw.DataKeys(e.Item.ItemIndex))
however most of the time I get this error. Any ideas as to why it will work sometimes and other times it wont? It almost seems to be a random issue. Certain records will redirect and the next time I press it nothing will happen. Ill post some code snippets below.
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index |
Kamon | Posted 10:53am 12. October 2005 Server Time |
dim ojcode as new MiscCode '<--- a class I created to house common vars functions and what not
------------
**At load this is run to populate the datalist**
Private Sub lnkDrawings()
'Get the data from the database and fill the Datalist
objCode.mySQL = "Select drawings.DrawingID, drawings.Category, drawings.DwgNo, drawings.Title, drawings.CurRev, drawings.TrnDate, drawings.TrnRev, drawings.IfcDate, drawings.IfcRev, drawings.PlotDate, drawings.TrnNo, drawings.Selected, drawings.PercCompl, drawings.Sort, drawings.Discipline, vendors.Vendor, dwgrev.Rev, dwgrev.RevDate From drawings, vendors Inner Join dwgrev ON drawings.JobNo = dwgrev.JobNo AND dwgrev.VendorID = vendors.VendorID Where drawings.JobNo =" & lstJobs.SelectedItem.Text
objCode.MyCommand = New MySqlCommand(objCode.mySQL, objCode.myConn)
Try
objCode.myConn.Open()
lstDraw.DataSource = objCode.MyCommand.ExecuteReader
lstDraw.DataBind()
lstDraw.DataKeyField = "drawingid"
objCode.myConn.Close()
Catch ex As Exception
Response.Write(objCode.Message(objCode.CleanText(ex.Message)))
Finally
If objCode.myConn.State = ConnectionState.Open Then objCode.myConn.Close()
objCode.mySQL = Nothing
objCode.MyCommand = Nothing
End Try
End Sub
Kamon | Posted 10:54am 12. October 2005 Server Time |
****the item template for my list**
<ItemTemplate>
<tr>
<td><asp:LinkButton ID="LEdit1" text="Edit" CommandName="edit" Runat="server" /></td>
<td><%# Container.dataitem("dwgno")%></td>
<td><%# Container.dataitem("Title")%></td>
<td><%# Container.dataitem("vendor")%></td>
<td><%# Container.dataitem("rev")%></td>
<td><%# Container.dataitem("revDate")%></td>
<td><%# Container.dataitem("perccompl")%></td>
<td><%# Container.dataitem("Category")%></td>
<td><%# Container.dataitem("CurRev")%></td>
<td><%# Container.dataitem("PlotDate")%></td>
<td><%# Container.dataitem("trnrev")%></td>
<td><%# Container.dataitem("trndate")%></td>
<td><%# Container.dataitem("trnno")%></td>
<td><%# Container.dataitem("ifcrev")%></td>
<td><%# Container.dataitem("ifcdate")%></td>
<td><%# Container.dataitem("sort")%></td>
<td><%# Container.dataitem("discipline")%></td>
<td><%# Container.dataitem("selected")%></td>
<td><asp:LinkButton ID="LEdit2" text="Edit" CommandName="edit" Runat="server" /></td>
</tr>
</ItemTemplate>
-----------
**Redirect Code**
Private Sub Edit_Drawings(ByVal s As Object, ByVal e As DataListCommandEventArgs) Handles lstDraw.EditCommand
Response.Redirect("EditDrawings.aspx?RID=" & lstDraw.DataKeys(e.Item.ItemIndex))
End Sub
Informant | Posted 2:20pm 12. October 2005 Server Time |
Well if the item can not be found within the datalists datakeys you will get this error.
Kamon | Posted 6:13pm 12. October 2005 Server Time |
Yes, but why would it be found sometimes and then not found others?
Reply to Post Some .net datalist help
|
|
|