編集と更新を有効にしてグリッドビューを使用し、 を使用しUpdateCommand
てSqlDataSource
データを更新しています。しかし、レコードを更新しようとするたびに例外が発生します
関数またはプロシージャに指定された引数が多すぎます
コード:
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class Manager_UnApprovedActivites : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
string Appproval = ((CheckBox)GridView1.Rows[e.RowIndex].Cells[9].Controls[0]).Text;
SqlDataSource1.UpdateParameters["id"].DefaultValue = id.ToString();
SqlDataSource1.UpdateParameters["approval"].DefaultValue = Appproval.ToString();
SqlDataSource1.Update();
}
}
ASP.net:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UnApprovedActivites.aspx.cs" Inherits="Manager_UnApprovedActivites" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="AcitivityId" DataSourceID="SqlDataSource1"
Height="273px" Width="976px" AutoGenerateEditButton ="True">
<Columns>
<asp:BoundField DataField="AcitivityId" HeaderText="AcitivityId" InsertVisible="False" ReadOnly="True" SortExpression="AcitivityId" />
<asp:BoundField DataField="ActiviityName" HeaderText="ActiviityName" SortExpression="ActiviityName" />
<asp:BoundField DataField="ActivityLocation" HeaderText="ActivityLocation" SortExpression="ActivityLocation" />
<asp:BoundField DataField="ActivityStartDate" HeaderText="ActivityStartDate" SortExpression="ActivityStartDate" />
<asp:BoundField DataField="ActivityDueDate" HeaderText="ActivityDueDate" SortExpression="ActivityDueDate" />
<asp:BoundField DataField="ActivityDescription" HeaderText="ActivityDescription" SortExpression="ActivityDescription" />
<asp:BoundField DataField="ActvityTypeId" HeaderText="ActvityTypeId" SortExpression="ActvityTypeId" />
<asp:BoundField DataField="BarchId" HeaderText="BarchId" SortExpression="BarchId" />
<asp:CheckBoxField DataField="Approval(Authority)" HeaderText="Approval(Authority)" SortExpression="Approval(Authority)" />
<asp:CheckBoxField DataField="ApprovalManager" HeaderText="ApprovalManager" SortExpression="ApprovalManager" />
<asp:BoundField DataField="DateAdded" HeaderText="DateAdded" SortExpression="DateAdded" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:WCA DatabaseConnectionString2 %>"
SelectCommand="SELECT * FROM [Activities]"
UpdateCommand="ApproveActivity"
UpdateCommandType="StoredProcedure">
<UpdateParameters>
<asp:Parameter Name="id" Type="Int64" />
<asp:Parameter Name="approval" Type="Boolean" />
</UpdateParameters>
</asp:SqlDataSource>
</form>
</body>
</html>