473,795 Members | 3,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.IndexOut OfRangeExceptio n: 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.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
binddata()
Else
ReverseBind()

End If


End Sub
Sub binddata()
SqlSelectComman d1.Parameters(" @missionid").Va lue
= 21905
SqlSelectComman d1.Parameters(" @ssn").Value = "%"
SqlDataAdapter1 .Fill(Dataset11 )
DataGrid1.DataB ind()
_LastEditedPage = DataGrid1.Curre ntPageIndex
End Sub
Public Sub ReverseBind()
Dim gridrow As DataGridItem
Dim datarow As Dataset1.og_get CrewAssignedSor tRow
For Each gridrow In DataGrid1.Items

Next
datarow = Dataset11.og_ge tCrewAssignedSo rt
(gridrow.DataSe tIndex)
datarow.crewcod e() = CType(gridrow.F indControl
("txtCode"), TextBox).Text
datarow.crewqua l() = CType(gridrow.F indControl
("txtcrewQual") , TextBox).Text
datarow.crewdut y() = CType(gridrow.F indControl
("txtcrewDuty") , TextBox).Text
datarow.persont ype() = CType(gridrow.F indControl
("txtFunded" ), TextBox).Text
datarow.crewSor t() = CType(gridrow.F indControl
("txtsort"), TextBox).Text
Dataset11.og_ge tCrewAssignedSo rt
(gridrow.DataSe tIndex).ItemArr ay = datarow.ItemArr ay

End Sub

Protected Overrides Sub LoadViewState(B yVal
savedstate As Object)

MyBase.LoadView State(savedstat e)
If (Not Me.ViewState("D ata") Is Nothing) Then
Dataset11 = CType(Me.ViewSt ate("Data"),
Dataset1)

End If
If (Not Me.ViewState("L astEditedPage") Is
Nothing) Then
_LastEditedPage = CType(Me.ViewSt ate
("LastEditedPag e"), Integer)
End If

End Sub

Protected Overrides Function saveViewState() As Object
Me.ViewState("D ata") = Dataset11
Me.ViewState("L astEditedPage") = _LastEditedPage
Return (MyBase.SaveVie wState())
End Function
Private Sub DataGrid1_ItemD ataBound(ByVal sender As
Object, ByVal e As
System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles
DataGrid1.ItemD ataBound
If (e.Item.ItemTyp e = ListItemType.It em Or
e.Item.ItemType = ListItemType.Al ternatingItem) Then
Dim datarow As
Dataset1.og_get CrewAssignedSor tRow
datarow = CType(CType(e.I tem.DataItem,
DataRowView).Ro w, Dataset1.og_get CrewAssignedSor tRow)
CType(e.Item.Fi ndControl("txtc ode"),
TextBox).Text = datarow.crewcod e
CType(e.Item.Fi ndControl("txtc rewQual"),
TextBox).Text = datarow.crewqua l
CType(e.Item.Fi ndControl("txtc rewDuty"),
TextBox).Text = datarow.crewdut y
CType(e.Item.Fi ndControl("txtF unded"),
TextBox).Text = datarow.persont ype
CType(e.Item.Fi ndControl("txtS ort"),
TextBox).Text = datarow.crewSor t

End If

End Sub

Private Sub Save_Click(ByVa l sender As System.Object,
ByVal e As System.EventArg s) Handles Save.Click

DataGrid1.Allow Paging = False
DataGrid1.DataS ource =
_Dataset11.og_g etCrewAssignedS ort
ReverseBind()
updateData()

End Sub
Sub updateData()

Dim gridrow As DataGridItem
Dim datarow As Dataset1.og_get CrewAssignedSor tRow
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_get CrewAssignedSor t
(gridrow.DataSe tIndex)

txtcq = gridrow.FindCon trol("txtcrewqu al")
strcq = txtcq.Text
txtcd = gridrow.FindCon trol("txtcrewdu ty")
strcd = txtcd.Text
txtptype = gridrow.FindCon trol("txtFunded ")
strptype = txtptype.Text
txtccode = gridrow.FindCon trol("txtcode")
strccode = txtccode.Text
txtcsort = gridrow.FindCon trol("txtsort")
intcsort = CType(txtcsort. Text, Integer)

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

SqlConnection1. Open()
SqlUpdateComman d1.ExecuteNonQu ery()
SqlConnection1. Close()

Next
End Sub
End Class
Nov 22 '05 #1
5 2544
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.IndexOut OfRangeExceptio n: 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:
[IndexOutOfRange Exception: There is no row at position 0.]
System.Data.Dat aRowCollection. get_Item(Int32 index) +63
MultiRowEdit.og _getCrewAssigne dSortDataTable. get_Item(Int32 index) in
\\somewebserver \Dataset1.vb:16 69
MultiRowEdit.Cr ew_Dtails.updat eData() in
\\somewebserver \Crew_Dtails.as px.vb:186
MultiRowEdit.Cr ew_Dtails.Save_ Click(Object sender, EventArgs e) in
\\somewebserver \Crew_Dtails.as px.vb:164
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108

System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.Rai
sePostBackEvent (String eventArgument) +57
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData)
+33
System.Web.UI.P age.ProcessRequ estMain() +1277


------------------------------------------------------------------------
--------
Version Information: Microsoft .NET Framework Version:1.1.432 2.573;
ASP.NET Version:1.1.432 2.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_get CrewAssignedSor t(gridrow.DataS etIndex)

Is og_getCrewAssig nedSort a table in the typed dataset? Please make sure
og_getCrewAssig nedSort 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
6605
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
1225
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 me in to edit mode: sub dgEdit(ByVal s As Object, ByVal e As DataGridCommandEventArgs) dgStatus.EditItemIndex = e.Item.ItemIndex bindData() 'This is just a sub I wrote to re-bind the data
2
2339
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, Fax, Phone, Category). Put an Edit column at the end... Now what?! If you go into Edit mode -- you can only edit 5 cells -- not all the rest of the Record's fields...not enough!
0
1468
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 project lead does not want me to do this with code as he thinks it is too complex. But I cannot find a property in Design View or HTML View that works. Otherwise the edit buttons do not match the appearance of other buttons on the screen. Here is...
3
1636
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 controls defined in the <EditItemTemplate> however when I right click and do a view source I cannot find any of the input textboxes in the source. I have used the ItemDatabound event to try to attach javascript to the textboxes and in debug mode while...
3
4379
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 be really grateful for any assistance! Thanks
3
1512
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 each row by clicking Edit-Update for each row. Each row has several columns, is there anyway to move the Edit function to edit each column individually for each row in the DataGrid?
1
1342
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 build-in edit function in the datagrid in which you only can edit one line at a time. I want to edit whole datagrid and save it just once. Thanks in advance. David
9
2729
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 code: <script runat="server"> Dim sqlConn As New SqlConnection(".....") Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) If Not (Page.IsPostBack) Then FillDataGrid()
8
1984
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 button. There are a lot of fields across, and my Network Admins would like a way of editing/updating each issue seperately in a a vertical form. I need a way of clicking on the edit button ,bringing up a form with the record, editng the fields, and...
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10438
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10164
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7540
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.