Gridview Problems with asp.net 2.0

  • Thread starter Thread starter kashif456
  • Start date Start date
K

kashif456

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=CrisisResponseBase
%>
<script runat="server">

'Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
' Response.Write(Session.SessionID)
''DetailsView1.ChangeMode(DetailsViewMode.ReadOnly)
'End Sub

Protected Sub DetailsView1_ItemInserted(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs)

If (Not e.Exception Is Nothing) Then
ErrorMessageLabel.Text = e.Exception.ToString
'ErrorMessageLabel.Text = "An error occured while entering
this record. Please verify you have entered data in the correct
format."
e.ExceptionHandled = True
End If
GridView1.DataBind()
End Sub

Protected Sub DetailsView1_ItemUpdated(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs)
If (Not e.Exception Is Nothing) Then
ErrorMessageLabel.Text = e.Exception.ToString
'ErrorMessageLabel.Text = "An error occured while entering
this record. Please verify you have entered data in the correct
format."
e.ExceptionHandled = True
End If
GridView1.DataBind()
End Sub

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As
Object, ByVal e As EventArgs)

DetailsView1.ChangeMode(DetailsViewMode.ReadOnly)
End Sub

Protected Sub GridView1_PageIndexChanged(ByVal sender As Object,
ByVal e As EventArgs)

DetailsView1.ChangeMode(DetailsViewMode.ReadOnly)
End Sub

Protected Sub GridView1_Sorted(ByVal sender As Object, ByVal e As
System.EventArgs)
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly)
End Sub

Protected Sub GridView1_RowDeleted(ByVal sender As Object, ByVal e
As GridViewDeletedEventArgs)

If (Not e.Exception Is Nothing) Then

'ErrorMessageLabel.Text = "Failed to DELETE due to foreign
key contstraint on the table. You may only delete rows which have no
related records."
ErrorMessageLabel.Text = e.Exception.ToString
e.ExceptionHandled = True
End If
End Sub

Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal
e As EventArgs)
End Sub


</script>
<html>
<head id="Head1" runat="server">
<title>GridView DetailsView Master-Details (Insert)</title>
</head>
<body>
<form id="MemberForms" runat="server">
<table>
<tr>
<td colspan="2">
<asp:Label ID="ErrorMessageLabel"
EnableViewState="false" runat="server" />
</td>
</tr>
<tr>
<td valign="top">
<asp:GridView ID="GridView1" AllowSorting="True"
AllowPaging="True" runat="server"
DataSourceID="SqlDataSourceMembers" DataKeyNames="MemberID"
AutoGenerateColumns="False" Width="500px" SelectedIndex="0"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
OnPageIndexChanged="GridView1_PageIndexChanged"
OnRowDeleted="GridView1_RowDeleted" OnSorted="GridView1_Sorted">
<Columns>
<asp:CommandField ShowSelectButton="true"
ShowDeleteButton="true" />
<asp:BoundField DataField="MemberID" HeaderText="Member
ID" ReadOnly="True" SortExpression="MemberID" />
<asp:BoundField DataField="LastName" HeaderText="Last
Name" SortExpression="LastName" />
<asp:BoundField DataField="FirstName" HeaderText="First
Name" SortExpression="FirstName" />
<asp:BoundField DataField="EmailAddress"
HeaderText="Email" SortExpression="EmailAddress" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSourceMembers" runat="server"
ConnectionString="<%$ ConnectionStrings:CrisisResponse %>"
SelectCommandType="StoredProcedure"
DataSourceMode="Dataset"
SelectCommand="GetMembers"
DeleteCommand="DeleteMember">

<DeleteParameters>
<asp:ControlParameter ControlID="GridView1"
name="MemberID" PropertyName="SelectedValue"
Type="String" />
</DeleteParameters>

</asp:SqlDataSource>
<!--
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1"
Name="state" PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
-->

</td>
<td valign="top">
<asp:DetailsView AutoGenerateRows="False"
DataKeyNames="MemberID" DataSourceID="SqlDataSourceMemberDetail"
HeaderText="Author Details" ID="DetailsView1"
runat="server" Width="275px" OnItemUpdated="DetailsView1_ItemUpdated"
OnItemInserted="DetailsView1_ItemInserted"
OnDataBound="DetailsView1_DataBound">
<Fields>
<asp:BoundField DataField="MemberID"
HeaderText="MemberID" ReadOnly="True" SortExpression="MemberID" />
<asp:BoundField DataField="LastName"
HeaderText="LastName" SortExpression="LastName" />
<asp:BoundField DataField="FirstName"
HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="phone" HeaderText="phone"
SortExpression="phone" />
<asp:BoundField DataField="EmailAddress"
HeaderText="EmailAddress" SortExpression="EmailAddress" />
<asp:BoundField DataField="Comments"
HeaderText="Comments" SortExpression="Comments" />
<asp:CheckBoxField DataField="IsActive"
HeaderText="IsActive" SortExpression="IsActive" />
<asp:CommandField ShowEditButton="True"
ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSourceMemberDetail"
runat="server" ConnectionString="<%$
ConnectionStrings:CrisisResponse%>"
SelectCommandType="StoredProcedure"
DataSourceMode="dataset"
SelectCommand="GetMemberByMemberID"
UpdateCommand="UpdateMember"
InsertCommand="InsertMember" >

<SelectParameters>
<asp:ControlParameter ControlID="GridView1"
Name="MemberID" PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:ControlParameter ControlID="DetailsView1"
Name="MemberID" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="DetailsView1"
Name="LastName" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="DetailsView1"
Name="FirstName" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="DetailsView1"
Name="EmailAddress" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="DetailsView1"
Name="Phone" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="DetailsView1"
Name="IsActive" PropertyName="SelectedValue" Type="Boolean" />
<asp:ControlParameter ControlID="DetailsView1"
Name="Comments" PropertyName="SelectedValue" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="LastName" Type="Int32" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="EmailAddress" Type="String" />
<asp:Parameter Name="Phone" Type="String" />
<asp:Parameter Name="IsActive" Type="Boolean" />
<asp:Parameter Name="Comments" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</td>
</tr>
</table>
<br />
</form>
</body>
</html>

My stored procedures are working just fine...
 
Back
Top