私はGridViewにSQLデータソースを介して入力された「削除」オプションを表示しています。私は、ユーザーが情報の行を削除することを確認するよう求められる方法を実装しようとしています。私はhttp://msdn.microsoft.com/en-us/library/ms972940.aspxからのガイドに従っています。クライアント削除の確認
私が現在持っている問題は、ObjectDataSourceを追加したときにクラスを選択し、目的のメソッドを選択すると表示されません(図37)。
追加情報 - 私は元々、SQLDataSourceを介してデータを取り込むためにGridViewを作成しましたが、今はObjectDataSourceに移行してDeleteMethodを追加しようとしています。私はこの部分で立ち往生しており、ユーザーに続行を依頼するポップアップウィンドウはまだありません。私は現在のチャレンジを克服した後、私はそれに取り組んでいきます。
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContentAdmin" runat="server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContentAdmin" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="CourseSection_ID" DataSourceID="SqlDataSource1"
ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="CourseSection_ID" HeaderText="CourseSection_ID"
InsertVisible="False" ReadOnly="True" SortExpression="CourseSection_ID" />
<asp:BoundField DataField="section" HeaderText="section"
SortExpression="section" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MGT598DBConnectionString1 %>"
SelectCommand="SELECT * FROM [Course_Section]"
DeleteCommand="DELETE FROM [Course_Section] WHERE [CourseSection_ID] = @CourseSection_ID"
InsertCommand="INSERT INTO [Course_Section] ([section]) VALUES (@section)"
UpdateCommand="UPDATE [Course_Section] SET [section] = @section WHERE [CourseSection_ID] = @CourseSection_ID">
<DeleteParameters>
<asp:Parameter Name="CourseSection_ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="section" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="section" Type="String" />
<asp:Parameter Name="CourseSection_ID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server">
</asp:ObjectDataSource> </asp:Content>
ファイルの後ろに私のコード:
namespace MGT598GraduateProject.View
{
public partial class ViewCourse_Section : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//http://msdn.microsoft.com/en-us/library/ms972940.aspx
}
public static void DeleteMethod(int CourseSection_ID)
{
// deletes a specified Order Details record
// from the Northwind Products table
string sql = "DELETE FROM [Order Details] WHERE OrderID = " + "@OrderID";
using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["MGT598DBConnectionString1"].ConnectionString))
{
SqlCommand myCommand = new SqlCommand(sql, myConnection);
myCommand.Parameters.Add(new SqlParameter("@CourseSection_ID", CourseSection_ID));
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
}
}
}
}
はあなたの助けをありがとう!私はまた、コードの混乱についてお詫び申し上げます。私はsqldatasouceからobjectdatasourceに移行していました。 –