2012-01-17 15 views
0

私は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(); 
      } 
     } 
    } 
} 

答えて

1

二つの問題がここにあります。ここ

は私のaspxコードです。

まず、いくつかの根本的な基本が間違っています。

SQLDataSourceとObjectDataSourceは必要ありません。

GridviewがSqldataSource(DataSourceID = "SQLDataSource1")を指していたので、オブジェクトデータソースは実際には役に立たない。

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"> 
<asp:ObjectDataSource> </asp:Content> 

をそして背後にあるコードから全体DeleteMethodを削除します。

あなたは、ASPXから、次のコードを削除することができます。

このチュートリアルを読んだら、私たちをあなたにリンクさせると、彼らは2つの別々のセクションであり、一緒にはできないことがわかります。

第2に、ユーザーに削除を確認させる必要があります。これを行うには

、次のように合わせてブロックを変更します。

<Columns> 
<asp:TemplateField> 
    <ItemTemplate> 
     <asp:LinkButton ID="LinkButton1" Runat="server" 
     OnClientClick="return confirm('Are you sure you want to delete this record?');" 
     CommandName="Delete">Delete Item 
     </asp:LinkButton> 
    </ItemTemplate> 
</asp:TemplateField> 
<asp:CommandField 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> 
+0

はあなたの助けをありがとう!私はまた、コードの混乱についてお詫び申し上げます。私はsqldatasouceからobjectdatasourceに移行していました。 –

関連する問題