2011-12-23 21 views
0

こんにちは私は以下のASP.Netコードを少し持っています。送信ボタンの作成方法を把握しようとしています。ASP.NETで[送信]ボタンを使用して挿入できない?

<asp:Button ID="makepost" runat="server" Text="Post My Tip/Story" 
       ValidationGroup="createpost" /> 

が正しく機能しています。私はAccessDataSource1.Insertを()を追加しようとすると、私はこれを言っエラーを取得:

CS1061: 'ASP.main_aspx' does not contain a definition for 'AccessDataSource1' and no extension method 'AccessDataSource1' accepting a first argument of type 'ASP.main_aspx' could be found (are you missing a using directive or an assembly reference?)

私はこの仕事をするために入力する必要がありますか?私のコードはすべて以下の通りです。

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Main.aspx.cs" Inherits="Main" %> 

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> 
    <asp:LoginView ID="LoginView1" runat="server"> 

    <LoggedInTemplate> 
     <asp:LoginStatus ID="LoginStatus1" runat="server" /> 
    <div style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #FFFFFF"> 
    <p style="font-size: 20px">Welcome Back!<br /> 
    Begin Sharing and Reading Space Tips Below! 
    </p> 



    <p>&nbsp;Current Posts: 
     <asp:GridView ID="GridView1" runat="server" DataSourceID="AccessDataSource1" 
      AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" 
      BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" 
      CellPadding="3" CellSpacing="2" DataKeyNames="ID"> 
      <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" /> 
      <Columns> 
       <asp:BoundField DataField="User" HeaderText="User" SortExpression="User" /> 
       <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" /> 
       <asp:BoundField DataField="Timeof" HeaderText="Timeof" 
        SortExpression="Timeof" /> 
       <asp:BoundField DataField="Post" HeaderText="Post" SortExpression="Post" /> 
       <asp:CommandField ButtonType="Button" ShowDeleteButton="True" /> 
       <asp:CommandField ButtonType="Button" ShowEditButton="True" /> 
      </Columns> 
      <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" /> 
      <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" /> 
      <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" /> 
      <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" /> 
     </asp:GridView> 

     <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
      DataFile="~/App_Data/Posts.mdb" 
      SelectCommand="SELECT * FROM [UserPost] ORDER BY [Timeof]" 
      DeleteCommand="DELETE FROM [UserPost] WHERE [ID] = ?" 
      InsertCommand="INSERT INTO [UserPost] ([ID], [User], [Title], [Timeof], [Post]) VALUES (?, ?, ?, ?, ?)" 
      UpdateCommand="UPDATE [UserPost] SET [User] = ?, [Title] = ?, [Timeof] = ?, [Post] = ? WHERE [ID] = ?"> 
      <DeleteParameters> 
       <asp:Parameter Name="ID" Type="Int32" /> 
      </DeleteParameters> 
      <UpdateParameters> 
       <asp:Parameter Name="User" Type="String" /> 
       <asp:Parameter Name="Title" Type="String" /> 
       <asp:Parameter Name="Timeof" Type="DateTime" /> 
       <asp:Parameter Name="Post" Type="String" /> 
       <asp:Parameter Name="ID" Type="Int32" /> 
      </UpdateParameters> 
      <InsertParameters> 
       <asp:ControlParameter Name="ID" Type="Int32" ControlID="TextBox5" PropertyName="Text" /> 
       <asp:ControlParameter Name="User" Type="String" ControlID="TextBox1" PropertyName="Text" /> 
       <asp:ControlParameter Name="Title" Type="String" ControlID="TextBox2" PropertyName="Text" /> 
       <asp:ControlParameter Name="Timeof" Type="DateTime" ControlID="TextBox3" PropertyName="Text" ConvertEmptyStringToNull="true"/> 
       <asp:ControlParameter Name="Post" Type="String" ControlID="TextBox4" PropertyName="Text" /> 
      </InsertParameters> 
     </asp:AccessDataSource> 

    </p> 

     <table><tr><td> <asp:Label ID="Label5" runat="server" Text="ID: "></asp:Label></td><td> 
      <asp:TextBox ID="TextBox5" runat="server" ValidationGroup="createpost"></asp:TextBox></td></tr> 
     <tr><td> <asp:Label ID="Label1" runat="server" Text="User: "></asp:Label></td><td> 
      <asp:TextBox ID="TextBox1" runat="server" ValidationGroup="createpost"></asp:TextBox></td></tr> 
     <tr><td><asp:Label ID="Label2" runat="server" Text="Title: "></asp:Label></td><td><asp:TextBox ID="TextBox2" 
       runat="server" ValidationGroup="createpost"></asp:TextBox></td></tr> 
     <tr><td><asp:Label ID="Label3" runat="server" Text="Date: "></asp:Label></td><td> <asp:TextBox ID="TextBox3" 
       runat="server"></asp:TextBox></td></tr> 
     <tr><td valign="top"><asp:Label ID="Label4" runat="server" Text="Story: "></asp:Label></td><td valign="top"> 
      <asp:TextBox ID="TextBox4" runat="server" Height="129px" Width="474px" TextMode="MultiLine"></asp:TextBox></td></tr> 
     </table> 
      <asp:Button ID="makepost" runat="server" Text="Post My Tip/Story" 
       ValidationGroup="createpost" /><br /> 

    </div> 

    </LoggedInTemplate><AnonymousTemplate> 

     <asp:Login ID="Login1" runat="server" ForeColor="White"> 
     </asp:Login><br /><div style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; color:#FFFFFF">Please Register to be begin viewing and sharing your 
     <br />Star Wars Old Republic Tips and Stories!</div> 
    </AnonymousTemplate> 
    </asp:LoginView> 
</asp:Content> 

答えて

2

あなたAccessDataSourceがLoginView内にある、あなたがコントロールを見つける必要があります。 C#で、この後、

AccessDataSource AccessDataSource1 = (AccessDataSource)LoginView1.FindControl("AccessDataSource1"); 
+0

彼はvb.netのlolでこれをやっていると仮定しています。 – MethodMan

+0

彼の.aspxヘッダーによると、言語はC#です。 – MethodMan

+0

私はC#を使用していませんVB – allencoded

-1

この行。次をご覧ください:

<asp:AccessDataSource ID="AccessDataSource1" runat="server" 

AccessDataSource1が表示されますか。おそらく、間違ったDatasourceを指していますか?それとも、違う名前をつけたのですか?

+0

だろうエラーに応じない権利名 – allencoded

+0

でなければなりませんAccessDataSource1は..を確認するために、あなたのコード内の単語の検索を行う。..それ以外の場合は、なぜエラー状態AccessDataSource1はありませんか..? ?\ – MethodMan

+0

"AccessDataSource1が表示されますか?"はい、私はそれを参照してください:それはコントロールの識別子です。エラーは他のものです。 – CedX

0
'ASP.main_aspx' does not contain a definition for 'AccessDataSource1' 

あなたのAccessDataSourceコントロールが間違った場所にあると思います。あなたはそれをLoginViewに入れました。エラーメッセージは、ランタイムがページのルートでコントロールを見つけることができないことを示しています。だから、LoginViewの外にAccessDataSourceを配置してみてください。

Dim AccessDataSource1 As AccessDataSource = DirectCast(LoginView1.FindControl("AccessDataSource1"), AccessDataSource) 

よろしく:

+0

メソッド名が予想されるようになりましたか? – allencoded

+0

私はあなたの質問を理解していません(私の英語はあまり良くありません)。明確にすることはできますか?また、Piyeyの答えを見てください:それは良い提案です。 – CedX

+0

あなたが提案した(DataSourceをLoginViewの外に移動する)私はエラーが発生します:メソッド名予想。 – allencoded

関連する問題