473,804 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Gridview Problems with asp.net 2.0

I can't figure out why I am getting error updating, deleting and
inserting new rows. I am amble to get my dataview populated and also
detailview populated: Here's my code:
<%@ Page Language=VB CompilationMode =Auto Inherits=Crisis ResponseBase
%>
<script runat="server">

'Protected Overrides Sub OnLoad(ByVal e As System.EventArg s)
' Response.Write( Session.Session ID)
''DetailsView1. ChangeMode(Deta ilsViewMode.Rea dOnly)
'End Sub

Protected Sub DetailsView1_It emInserted(ByVa l sender As Object,
ByVal e As System.Web.UI.W ebControls.Deta ilsViewInserted EventArgs)

If (Not e.Exception Is Nothing) Then
ErrorMessageLab el.Text = e.Exception.ToS tring
'ErrorMessageLa bel.Text = "An error occured while entering
this record. Please verify you have entered data in the correct
format."
e.ExceptionHand led = True
End If
GridView1.DataB ind()
End Sub

Protected Sub DetailsView1_It emUpdated(ByVal sender As Object,
ByVal e As System.Web.UI.W ebControls.Deta ilsViewUpdatedE ventArgs)
If (Not e.Exception Is Nothing) Then
ErrorMessageLab el.Text = e.Exception.ToS tring
'ErrorMessageLa bel.Text = "An error occured while entering
this record. Please verify you have entered data in the correct
format."
e.ExceptionHand led = True
End If
GridView1.DataB ind()
End Sub

Protected Sub GridView1_Selec tedIndexChanged (ByVal sender As
Object, ByVal e As EventArgs)

DetailsView1.Ch angeMode(Detail sViewMode.ReadO nly)
End Sub

Protected Sub GridView1_PageI ndexChanged(ByV al sender As Object,
ByVal e As EventArgs)

DetailsView1.Ch angeMode(Detail sViewMode.ReadO nly)
End Sub

Protected Sub GridView1_Sorte d(ByVal sender As Object, ByVal e As
System.EventArg s)
DetailsView1.Ch angeMode(Detail sViewMode.ReadO nly)
End Sub

Protected Sub GridView1_RowDe leted(ByVal sender As Object, ByVal e
As GridViewDeleted EventArgs)

If (Not e.Exception Is Nothing) Then

'ErrorMessageLa bel.Text = "Failed to DELETE due to foreign
key contstraint on the table. You may only delete rows which have no
related records."
ErrorMessageLab el.Text = e.Exception.ToS tring
e.ExceptionHand led = True
End If
End Sub

Protected Sub DetailsView1_Da taBound(ByVal sender As Object, ByVal
e As EventArgs)
End Sub
</script>
<html>
<head id="Head1" runat="server">
<title>GridVi ew DetailsView Master-Details (Insert)</title>
</head>
<body>
<form id="MemberForms " runat="server">
<table>
<tr>
<td colspan="2">
<asp:Label ID="ErrorMessag eLabel"
EnableViewState ="false" runat="server" />
</td>
</tr>
<tr>
<td valign="top">
<asp:GridView ID="GridView1" AllowSorting="T rue"
AllowPaging="Tr ue" runat="server"
DataSourceID="S qlDataSourceMem bers" DataKeyNames="M emberID"
AutoGenerateCol umns="False" Width="500px" SelectedIndex=" 0"
OnSelectedIndex Changed="GridVi ew1_SelectedInd exChanged"
OnPageIndexChan ged="GridView1_ PageIndexChange d"
OnRowDeleted="G ridView1_RowDel eted" OnSorted="GridV iew1_Sorted">
<Columns>
<asp:CommandFie ld ShowSelectButto n="true"
ShowDeleteButto n="true" />
<asp:BoundFie ld DataField="Memb erID" HeaderText="Mem ber
ID" ReadOnly="True" SortExpression= "MemberID" />
<asp:BoundFie ld DataField="Last Name" HeaderText="Las t
Name" SortExpression= "LastName" />
<asp:BoundFie ld DataField="Firs tName" HeaderText="Fir st
Name" SortExpression= "FirstName" />
<asp:BoundFie ld DataField="Emai lAddress"
HeaderText="Ema il" SortExpression= "EmailAddre ss" />
</Columns>
</asp:GridView>
<asp:SqlDataSou rce ID="SqlDataSour ceMembers" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:CrisisRespon se %>"
SelectCommandTy pe="StoredProce dure"
DataSourceMode= "Dataset"
SelectCommand=" GetMembers"
DeleteCommand=" DeleteMember">

<DeleteParamete rs>
<asp:ControlPar ameter ControlID="Grid View1"
name="MemberID" PropertyName="S electedValue"
Type="String" />
</DeleteParameter s>

</asp:SqlDataSour ce>
<!--
<SelectParamete rs>
<asp:ControlPar ameter ControlID="Drop DownList1"
Name="state" PropertyName="S electedValue"
Type="String" />
</SelectParameter s>
-->

</td>
<td valign="top">
<asp:DetailsVie w AutoGenerateRow s="False"
DataKeyNames="M emberID" DataSourceID="S qlDataSourceMem berDetail"
HeaderText="Aut hor Details" ID="DetailsView 1"
runat="server" Width="275px" OnItemUpdated=" DetailsView1_It emUpdated"
OnItemInserted= "DetailsView1_I temInserted"
OnDataBound="De tailsView1_Data Bound">
<Fields>
<asp:BoundFie ld DataField="Memb erID"
HeaderText="Mem berID" ReadOnly="True" SortExpression= "MemberID" />
<asp:BoundFie ld DataField="Last Name"
HeaderText="Las tName" SortExpression= "LastName" />
<asp:BoundFie ld DataField="Firs tName"
HeaderText="Fir stName" SortExpression= "FirstName" />
<asp:BoundFie ld DataField="phon e" HeaderText="pho ne"
SortExpression= "phone" />
<asp:BoundFie ld DataField="Emai lAddress"
HeaderText="Ema ilAddress" SortExpression= "EmailAddre ss" />
<asp:BoundFie ld DataField="Comm ents"
HeaderText="Com ments" SortExpression= "Comments" />
<asp:CheckBoxFi eld DataField="IsAc tive"
HeaderText="IsA ctive" SortExpression= "IsActive" />
<asp:CommandFie ld ShowEditButton= "True"
ShowInsertButto n="True" />
</Fields>
</asp:DetailsView >
<asp:SqlDataSou rce ID="SqlDataSour ceMemberDetail"
runat="server" ConnectionStrin g="<%$
ConnectionStrin gs:CrisisRespon se%>"
SelectCommandTy pe="StoredProce dure"
DataSourceMode= "dataset"
SelectCommand=" GetMemberByMemb erID"
UpdateCommand=" UpdateMember"
InsertCommand=" InsertMember" >

<SelectParamete rs>
<asp:ControlPar ameter ControlID="Grid View1"
Name="MemberID" PropertyName="S electedValue"
Type="String" />
</SelectParameter s>
<UpdateParamete rs>
<asp:ControlPar ameter ControlID="Deta ilsView1"
Name="MemberID" PropertyName="S electedValue" Type="String" />
<asp:ControlPar ameter ControlID="Deta ilsView1"
Name="LastName" PropertyName="S electedValue" Type="String" />
<asp:ControlPar ameter ControlID="Deta ilsView1"
Name="FirstName " PropertyName="S electedValue" Type="String" />
<asp:ControlPar ameter ControlID="Deta ilsView1"
Name="EmailAddr ess" PropertyName="S electedValue" Type="String" />
<asp:ControlPar ameter ControlID="Deta ilsView1"
Name="Phone" PropertyName="S electedValue" Type="String" />
<asp:ControlPar ameter ControlID="Deta ilsView1"
Name="IsActive" PropertyName="S electedValue" Type="Boolean" />
<asp:ControlPar ameter ControlID="Deta ilsView1"
Name="Comments" PropertyName="S electedValue" Type="String" />
</UpdateParameter s>
<InsertParamete rs>
<asp:Paramete r Name="LastName" Type="Int32" />
<asp:Paramete r Name="FirstName " Type="String" />
<asp:Paramete r Name="LastName" Type="String" />
<asp:Paramete r Name="EmailAddr ess" Type="String" />
<asp:Paramete r Name="Phone" Type="String" />
<asp:Paramete r Name="IsActive" Type="Boolean" />
<asp:Paramete r Name="Comments" Type="String" />
</InsertParameter s>
</asp:SqlDataSour ce>
</td>
</tr>
</table>
<br />
</form>
</body>
</html>

My stored procedures are working just fine...

Nov 18 '06 #1
1 1892
It would be helpful to tell us which error you get.

--

Riki

<ka*******@gmai l.comwrote in message
news:11******** *************@m 7g2000cwm.googl egroups.com...
>I can't figure out why I am getting error updating, deleting and
inserting new rows. I am amble to get my dataview populated and also
detailview populated: Here's my code:
<%@ Page Language=VB CompilationMode =Auto Inherits=Crisis ResponseBase
%>
<script runat="server">

'Protected Overrides Sub OnLoad(ByVal e As System.EventArg s)
' Response.Write( Session.Session ID)
''DetailsView1. ChangeMode(Deta ilsViewMode.Rea dOnly)
'End Sub

Protected Sub DetailsView1_It emInserted(ByVa l sender As Object,
ByVal e As System.Web.UI.W ebControls.Deta ilsViewInserted EventArgs)

If (Not e.Exception Is Nothing) Then
ErrorMessageLab el.Text = e.Exception.ToS tring
'ErrorMessageLa bel.Text = "An error occured while entering
this record. Please verify you have entered data in the correct
format."
e.ExceptionHand led = True
End If
GridView1.DataB ind()
End Sub

Protected Sub DetailsView1_It emUpdated(ByVal sender As Object,
ByVal e As System.Web.UI.W ebControls.Deta ilsViewUpdatedE ventArgs)
If (Not e.Exception Is Nothing) Then
ErrorMessageLab el.Text = e.Exception.ToS tring
'ErrorMessageLa bel.Text = "An error occured while entering
this record. Please verify you have entered data in the correct
format."
e.ExceptionHand led = True
End If
GridView1.DataB ind()
End Sub

Protected Sub GridView1_Selec tedIndexChanged (ByVal sender As
Object, ByVal e As EventArgs)

DetailsView1.Ch angeMode(Detail sViewMode.ReadO nly)
End Sub

Protected Sub GridView1_PageI ndexChanged(ByV al sender As Object,
ByVal e As EventArgs)

DetailsView1.Ch angeMode(Detail sViewMode.ReadO nly)
End Sub

Protected Sub GridView1_Sorte d(ByVal sender As Object, ByVal e As
System.EventArg s)
DetailsView1.Ch angeMode(Detail sViewMode.ReadO nly)
End Sub

Protected Sub GridView1_RowDe leted(ByVal sender As Object, ByVal e
As GridViewDeleted EventArgs)

If (Not e.Exception Is Nothing) Then

'ErrorMessageLa bel.Text = "Failed to DELETE due to foreign
key contstraint on the table. You may only delete rows which have no
related records."
ErrorMessageLab el.Text = e.Exception.ToS tring
e.ExceptionHand led = True
End If
End Sub

Protected Sub DetailsView1_Da taBound(ByVal sender As Object, ByVal
e As EventArgs)
End Sub
</script>
<html>
<head id="Head1" runat="server">
<title>GridVi ew DetailsView Master-Details (Insert)</title>
</head>
<body>
<form id="MemberForms " runat="server">
<table>
<tr>
<td colspan="2">
<asp:Label ID="ErrorMessag eLabel"
EnableViewState ="false" runat="server" />
</td>
</tr>
<tr>
<td valign="top">
<asp:GridView ID="GridView1" AllowSorting="T rue"
AllowPaging="Tr ue" runat="server"
DataSourceID="S qlDataSourceMem bers" DataKeyNames="M emberID"
AutoGenerateCol umns="False" Width="500px" SelectedIndex=" 0"
OnSelectedIndex Changed="GridVi ew1_SelectedInd exChanged"
OnPageIndexChan ged="GridView1_ PageIndexChange d"
OnRowDeleted="G ridView1_RowDel eted" OnSorted="GridV iew1_Sorted">
<Columns>
<asp:CommandFie ld ShowSelectButto n="true"
ShowDeleteButto n="true" />
<asp:BoundFie ld DataField="Memb erID" HeaderText="Mem ber
ID" ReadOnly="True" SortExpression= "MemberID" />
<asp:BoundFie ld DataField="Last Name" HeaderText="Las t
Name" SortExpression= "LastName" />
<asp:BoundFie ld DataField="Firs tName" HeaderText="Fir st
Name" SortExpression= "FirstName" />
<asp:BoundFie ld DataField="Emai lAddress"
HeaderText="Ema il" SortExpression= "EmailAddre ss" />
</Columns>
</asp:GridView>
<asp:SqlDataSou rce ID="SqlDataSour ceMembers" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:CrisisRespon se %>"
SelectCommandTy pe="StoredProce dure"
DataSourceMode= "Dataset"
SelectCommand=" GetMembers"
DeleteCommand=" DeleteMember">

<DeleteParamete rs>
<asp:ControlPar ameter ControlID="Grid View1"
name="MemberID" PropertyName="S electedValue"
Type="String" />
</DeleteParameter s>

</asp:SqlDataSour ce>
<!--
<SelectParamete rs>
<asp:ControlPar ameter ControlID="Drop DownList1"
Name="state" PropertyName="S electedValue"
Type="String" />
</SelectParameter s>
-->

</td>
<td valign="top">
<asp:DetailsVie w AutoGenerateRow s="False"
DataKeyNames="M emberID" DataSourceID="S qlDataSourceMem berDetail"
HeaderText="Aut hor Details" ID="DetailsView 1"
runat="server" Width="275px" OnItemUpdated=" DetailsView1_It emUpdated"
OnItemInserted= "DetailsView1_I temInserted"
OnDataBound="De tailsView1_Data Bound">
<Fields>
<asp:BoundFie ld DataField="Memb erID"
HeaderText="Mem berID" ReadOnly="True" SortExpression= "MemberID" />
<asp:BoundFie ld DataField="Last Name"
HeaderText="Las tName" SortExpression= "LastName" />
<asp:BoundFie ld DataField="Firs tName"
HeaderText="Fir stName" SortExpression= "FirstName" />
<asp:BoundFie ld DataField="phon e" HeaderText="pho ne"
SortExpression= "phone" />
<asp:BoundFie ld DataField="Emai lAddress"
HeaderText="Ema ilAddress" SortExpression= "EmailAddre ss" />
<asp:BoundFie ld DataField="Comm ents"
HeaderText="Com ments" SortExpression= "Comments" />
<asp:CheckBoxFi eld DataField="IsAc tive"
HeaderText="IsA ctive" SortExpression= "IsActive" />
<asp:CommandFie ld ShowEditButton= "True"
ShowInsertButto n="True" />
</Fields>
</asp:DetailsView >
<asp:SqlDataSou rce ID="SqlDataSour ceMemberDetail"
runat="server" ConnectionStrin g="<%$
ConnectionStrin gs:CrisisRespon se%>"
SelectCommandTy pe="StoredProce dure"
DataSourceMode= "dataset"
SelectCommand=" GetMemberByMemb erID"
UpdateCommand=" UpdateMember"
InsertCommand=" InsertMember" >

<SelectParamete rs>
<asp:ControlPar ameter ControlID="Grid View1"
Name="MemberID" PropertyName="S electedValue"
Type="String" />
</SelectParameter s>
<UpdateParamete rs>
<asp:ControlPar ameter ControlID="Deta ilsView1"
Name="MemberID" PropertyName="S electedValue" Type="String" />
<asp:ControlPar ameter ControlID="Deta ilsView1"
Name="LastName" PropertyName="S electedValue" Type="String" />
<asp:ControlPar ameter ControlID="Deta ilsView1"
Name="FirstName " PropertyName="S electedValue" Type="String" />
<asp:ControlPar ameter ControlID="Deta ilsView1"
Name="EmailAddr ess" PropertyName="S electedValue" Type="String" />
<asp:ControlPar ameter ControlID="Deta ilsView1"
Name="Phone" PropertyName="S electedValue" Type="String" />
<asp:ControlPar ameter ControlID="Deta ilsView1"
Name="IsActive" PropertyName="S electedValue" Type="Boolean" />
<asp:ControlPar ameter ControlID="Deta ilsView1"
Name="Comments" PropertyName="S electedValue" Type="String" />
</UpdateParameter s>
<InsertParamete rs>
<asp:Paramete r Name="LastName" Type="Int32" />
<asp:Paramete r Name="FirstName " Type="String" />
<asp:Paramete r Name="LastName" Type="String" />
<asp:Paramete r Name="EmailAddr ess" Type="String" />
<asp:Paramete r Name="Phone" Type="String" />
<asp:Paramete r Name="IsActive" Type="Boolean" />
<asp:Paramete r Name="Comments" Type="String" />
</InsertParameter s>
</asp:SqlDataSour ce>
</td>
</tr>
</table>
<br />
</form>
</body>
</html>

My stored procedures are working just fine...

Nov 18 '06 #2

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

Similar topics

3
13758
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum. Everyone wants to do a java confirmation box when a user clicks the delete button. Fair enough, basic user design rules state that you should always confirm a delete action. There is also a consensus that the best way to do this is a template...
2
2162
by: tacmec | last post by:
ASP.NET 2.0 (C#) application. I have a web form with a GridView, which is populated dynamically. See the code below. First time to the page, IsPostBack is false. Therefore, DisplayItems() is called and the GridView is populated. No problems. When I click the select button in the GridView, I first go to Page_Load and IsPostBack = true. Therefore, DisplayItems() is not called again. No problems. Then the...
1
3252
by: Giovanni | last post by:
Dear Friends/Gurus, I have exhausted myself and have yet no solution to the following: I have an ASP.NET 2.0 Survey type application. On a page, I have placed a GridView which is bound to an SQLDataSource. The GridView contains 3 columns: QuestionNumber, QuestionText, and a TemplateField. Each row in the GridView represents a question in a table (Ex.: "18. Satisfaction Level").
2
3472
by: loga123 | last post by:
Hi All, I am using Link Button for DELETE on the gridview. When I click on DELETE link, I get the ArgumentOutOfRangeException. But...it deletes the record from table in the database. On Gridview_rowdatabound, I am dynamically building hyperlink control based on the values in the other fields. Here is my code for Gridview_rowdatabound. It does work sometimes though.
0
1234
by: JMax | last post by:
Hello! I have a GridView that has another GridView embedded in it. The embedded GridView has some complex editing features (requiring JavaScript duplicating drop down lists), so I have to use the OnUpdating event in the embedded GridView. The problem occurs when I am in the OnUpdating event. Right now, there are two rows where the GridView controls are embedded. When I update the upper embedded GridView’s data, the event fires, after...
3
4610
by: Jeff | last post by:
Hey asp.net 2.0 In the source I posted below, there is a GridView (look at the bottom of the script): <asp:GridView ID="gvwOnline" runat="server"> </asp:GridView> I'm trying to assign a datasource to this GridView in runtime. But I cannot
8
18095
by: Greg Lyles | last post by:
Hi all, I'm trying to develop an ASP.NET 2.0 website and am running into some real problems with what I thought would be a relatively simple thing to do. In a nutshell, I'm stuck on trying to display data in a "GridView" which is tied to an "ObjectDataSource". In turn, this ObjectDatasource gets it's data from a strongly-typed business object within my code.
1
2813
by: =?Utf-8?B?SGFycnkgS2Vjaw==?= | last post by:
I have a GridView that I dynamically add columns to in code. The way that my code is written, everything works properly if I use GridView.Columns.Add to simply add the columns to the end of the collection. However, if I use GridView.Columns.Insert to inject the columns in the middle of the existing columns, I see lots of exceptions when I page the GridView, because certain controls contained within the grid are mysteriously absent? Can...
6
1988
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a gridview control with a template column that has a textbox and when the control is bound to the datasource the textbox is filled ok. I then change what is in the textbox in the gridview control and in the gridview_RowDataBound event I have string DiscDescrip = Convert.ToString((e.Row.Cells.FindControl("txbxDiscgv") as TextBox ).Text); This returns what was initially loaded in the textbox but not what I had just changed it...
1
7262
by: Dave | last post by:
I'm having problems getting the GridView to reliably display a large amount of data (50,000+ rows). I am working my way through the excellent book “Real World ASP.NET Best Practices” by Farhan Muhammad. In some cases I’m trying to extend the examples. Currently, I have the following code to read data from a SQL Server 2005 database and display in a GridView:
0
9714
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
9594
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
10600
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...
0
10350
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10096
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9174
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...
0
6866
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3834
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.