473,408 Members | 1,747 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Multirow edit on Datagrid

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
Nov 22 '05 #1
5 2529
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.

Nov 22 '05 #2
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_I tem(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.IPo stBackEventHandler.Rai
sePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
+33
System.Web.UI.Page.ProcessRequestMain() +1277


------------------------------------------------------------------------
--------
Version Information: Microsoft .NET Framework Version:1.1.4322.573;
ASP.NET Version:1.1.4322.573

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 22 '05 #3
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.

Nov 22 '05 #4
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.DataSetInd ex)

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.

Nov 22 '05 #5

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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Tamir Khason | last post by:
How to prevent the selected cell from being editable (visual) at DataGrid? Once click on cell (even readonly) there are cursor inside it and select text appears. How to prevent it Thankx
0
by: San Diego Guy | last post by:
Hi all! I have Datagrid. Within that datagrid I have a drop down list that I set up some values in (a "collection") I set up an edit command column on the datagrid and wrote simple code to get...
2
by: Sky | last post by:
Hello: Another question about trying to wring functionality from a DataGrid... Have a DB table of "Contacts" -- 14 or more fields per record Show in datagrid -- but only 5 columns (First,Last,...
0
by: Steve Kallal | last post by:
I have a DataGrid with an EditCommandColumn column set to a type of PushButton. I want to set set CssClass on these buttons and cannot without using code-behind code on the ItemDataBound event. The...
3
by: Leo | last post by:
I have a datagrid with the first column as a Edit,Update,Cancel button column. The other 5 columns are template columns. When I click the Edit button in IE6 the row correctly displays the...
3
by: Tim::.. | last post by:
Can someone please tell me how I go about preselecting an item in a drop drown list when I click the Edit Command in a datagrid? I have tried the following but it doesn't work for me! I would...
3
by: Schultz | last post by:
is there an easy to follow, source code in one document, article that explains how to create an edit all DataGrid control? and, I have a DataGrid setup where the client enters information for...
1
by: David Sagenaut | last post by:
Can I set a whole datagrid in edit mode, like a table? I can edit the data in the datagrid. After done, I can click the save button to save the data into a datasousce. I don't want to used the...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
8
by: =?Utf-8?B?bWlrZWc=?= | last post by:
Hi, I am building a small Help Desk application for my company and need to be able to edit "open" help desk issues. I use a simple datagrid to display each issue (6 per page) , with an Edit...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.