Multirow edit on Datagrid

D

Derek

I am using a code snippet from
http://www.dotnetjohn.com/articles/articleid83.aspx
to see if i can use it to update data. Here is the
problem/error i am getting.
System.IndexOutOfRangeException: There is no row at
position 0.

Any help would be greatly appreciated. Here is the code

Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
binddata()
Else
ReverseBind()

End If




End Sub
Sub binddata()
SqlSelectCommand1.Parameters("@missionid").Value
= 21905
SqlSelectCommand1.Parameters("@Ssn").Value = "%"
SqlDataAdapter1.Fill(Dataset11)
DataGrid1.DataBind()
_LastEditedPage = DataGrid1.CurrentPageIndex


End Sub
Public Sub ReverseBind()
Dim gridrow As DataGridItem
Dim datarow As Dataset1.og_getCrewAssignedSortRow
For Each gridrow In DataGrid1.Items

Next
datarow = Dataset11.og_getCrewAssignedSort
(gridrow.DataSetIndex)
datarow.crewcode() = CType(gridrow.FindControl
("txtCode"), TextBox).Text
datarow.crewqual() = CType(gridrow.FindControl
("txtcrewQual"), TextBox).Text
datarow.crewduty() = CType(gridrow.FindControl
("txtcrewDuty"), TextBox).Text
datarow.persontype() = CType(gridrow.FindControl
("txtFunded"), TextBox).Text
datarow.crewSort() = CType(gridrow.FindControl
("txtsort"), TextBox).Text
Dataset11.og_getCrewAssignedSort
(gridrow.DataSetIndex).ItemArray = datarow.ItemArray



End Sub

Protected Overrides Sub LoadViewState(ByVal
savedstate As Object)

MyBase.LoadViewState(savedstate)
If (Not Me.ViewState("Data") Is Nothing) Then
Dataset11 = CType(Me.ViewState("Data"),
Dataset1)

End If
If (Not Me.ViewState("LastEditedPage") Is
Nothing) Then
_LastEditedPage = CType(Me.ViewState
("LastEditedPage"), Integer)
End If

End Sub

Protected Overrides Function saveViewState() As Object
Me.ViewState("Data") = Dataset11
Me.ViewState("LastEditedPage") = _LastEditedPage
Return (MyBase.SaveViewState())
End Function
Private Sub DataGrid1_ItemDataBound(ByVal sender As
Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
If (e.Item.ItemType = ListItemType.Item Or
e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim datarow As
Dataset1.og_getCrewAssignedSortRow
datarow = CType(CType(e.Item.DataItem,
DataRowView).Row, Dataset1.og_getCrewAssignedSortRow)
CType(e.Item.FindControl("txtcode"),
TextBox).Text = datarow.crewcode
CType(e.Item.FindControl("txtcrewQual"),
TextBox).Text = datarow.crewqual
CType(e.Item.FindControl("txtcrewDuty"),
TextBox).Text = datarow.crewduty
CType(e.Item.FindControl("txtFunded"),
TextBox).Text = datarow.persontype
CType(e.Item.FindControl("txtSort"),
TextBox).Text = datarow.crewSort

End If

End Sub

Private Sub Save_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Save.Click

DataGrid1.AllowPaging = False
DataGrid1.DataSource =
_Dataset11.og_getCrewAssignedSort
ReverseBind()


updateData()

End Sub


Sub updateData()

Dim gridrow As DataGridItem
Dim datarow As Dataset1.og_getCrewAssignedSortRow
Dim txtcq As TextBox
Dim strcq As String
Dim txtcd As TextBox
Dim strcd As String
Dim txtptype As TextBox
Dim strptype As String
Dim txtccode As TextBox
Dim strccode As String
Dim txtcsort As TextBox
Dim intcsort As Integer

For Each gridrow In DataGrid1.Items

datarow = _dataset.og_getCrewAssignedSort
(gridrow.DataSetIndex)

txtcq = gridrow.FindControl("txtcrewqual")
strcq = txtcq.Text
txtcd = gridrow.FindControl("txtcrewduty")
strcd = txtcd.Text
txtptype = gridrow.FindControl("txtFunded")
strptype = txtptype.Text
txtccode = gridrow.FindControl("txtcode")
strccode = txtccode.Text
txtcsort = gridrow.FindControl("txtsort")
intcsort = CType(txtcsort.Text, Integer)

SqlUpdateCommand1.Parameters("@cq").Value =
strcq
SqlUpdateCommand1.Parameters("@cd").Value =
strcd
SqlUpdateCommand1.Parameters("@ptype").Value
= strptype
SqlUpdateCommand1.Parameters("@ccode").Value
= strccode
SqlUpdateCommand1.Parameters("@csort").Value
= intcsort
SqlUpdateCommand1.Parameters("@sid").Value =
1593

SqlConnection1.Open()
SqlUpdateCommand1.ExecuteNonQuery()
SqlConnection1.Close()

Next
End Sub
End Class
 
T

Tian Min Huang

Hi Derek,

Thanks for your post. I think more information is needed before moving
forward:

In which line of line does the exception throw? What's the call stack of
the exception?

I tested the sample from
http://www.dotnetjohn.com/articles/articleid83.aspx and it works properly,
does it work as expected on your side?

I look forward to your response. Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
D

Derek Mendez

Hey Tim,

Thanks for the follow up. Here is the stack trace:

There is no row at position 0.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: There is no row at
position 0.

Source Error:

An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.

Stack Trace:


[IndexOutOfRangeException: There is no row at position 0.]
System.Data.DataRowCollection.get_Item(Int32 index) +63
MultiRowEdit.og_getCrewAssignedSortDataTable.get_Item(Int32 index) in
\\somewebserver\Dataset1.vb:1669
MultiRowEdit.Crew_Dtails.updateData() in
\\somewebserver\Crew_Dtails.aspx.vb:186
MultiRowEdit.Crew_Dtails.Save_Click(Object sender, EventArgs e) in
\\somewebserver\Crew_Dtails.aspx.vb:164
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.Rai
sePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+33
System.Web.UI.Page.ProcessRequestMain() +1277
 
T

Tian Min Huang

Hi Derek,

Thanks for your information. I am checking this issue and will update you
with my findings.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
T

Tian Min Huang

Hi Derek,

I reviewed the call stack carefully, it seems that the exception was thrown
from the following line in updateData():
datarow = _dataset.og_getCrewAssignedSort(gridrow.DataSetIndex)

Is og_getCrewAssignedSort a table in the typed dataset? Please make sure
og_getCrewAssignedSort is initialized properly and is not empty.

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
D

Derek Mendez

TM,

Thanks for your postings. You were right, the dataset wasn't being
initialized correctly. I was calling 2 datasets w/in one sub, and had
them reversed. So basically, I was calling the empty dataset, and
trying to update it, what a goof. Thanks for putting me on the right
track.

v/r

Derek Mendez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top