2013-04-26 76 views
0

這裏是我的標記:插入從ObjectDataSource控件與業務層對象(無形式)

<div class="postit"> 
    <ul> 
     <li> 
      <asp:Label ID="lblPostBaslik" runat="server" Text="Baslik :" CssClass="postit-label"></asp:Label> 
      <asp:TextBox ID="txtBaslik" runat="server" CssClass="postit-txtbox" ></asp:TextBox> 
     </li> 
     <li> 
      <asp:Label ID="lblPostEtiket" runat="server" Text="Etiket :" CssClass="postit-label"></asp:Label> 
      <asp:TextBox ID="txtEtiket" runat="server" CssClass="postit-txtbox" ></asp:TextBox> 
      <li class="aciklama"> 
       <asp:Label ID="lblAciklama" runat="server" Text="Açiklama :" CssClass="postit-label"></asp:Label> 
       <asp:TextBox ID="txtAciklama" runat="server" CssClass="postit-txtbox-aciklama" TextMode="MultiLine" ></asp:TextBox> 
      </li> 
      <div class="postitbuttons" id="postitbuttons"> 
       <asp:Button ID="btnKaydet" runat="server" Text="Kaydet" CssClass="submit button large" onclick="btnKaydet_Click" /> 
       <asp:Button ID="btnVazgec" runat="server" Text="Vazgeç" CssClass="submit button large"/> 
       <%--<asp:LinkButton ID="btnKaydet" runat="server" CssClass="submit button large" CommandName="Insert">Kaydet</asp:LinkButton> 
       <asp:LinkButton ID="btnKapat" runat="server" CssClass="submit button large" CommandName="Cancel">Vazgeç</asp:LinkButton>--%> 
      </div> 
     </li> 
    </ul> 
</div> 
<asp:ObjectDataSource ID="ods_postit" runat="server" DataObjectTypeName="Post" TypeName="yonet" InsertMethod="PostEkle" > 
    <InsertParameters> 
     <asp:ControlParameter ControlID="txtBaslik" PropertyName="Text" Name="Post_Baslik" Type="String" /> 
     <asp:ControlParameter ControlID="txtEtiket" PropertyName="Text" Name="Post_Etiket" Type="String" /> 
     <asp:ControlParameter ControlID="txtEtiket" PropertyName="Text" Name="Post_Icerik" Type="String" /> 
    </InsertParameters> 
</asp:ObjectDataSource> 

當我點擊btnKaydet,我得到以下錯誤:

"ObjectDataSource 'ods_postit' has no values to insert. Check that the 'values' dictionary contains values."

什麼問題?它可以是這樣的:

<asp:ObjectDataSource ID="ods_postit" runat="server" DataObjectTypeName="Post" TypeName="yonet" InsertMethod="PostEkle" > 

我試圖斷點,但它不會觸發databaseworks.cs和yonet.cs。

廣東話我用這個OOP代碼?我不想使用表單(formview等)。

這裏是代碼隱藏和其它類:

protected void btnKaydet_Click(object sender, EventArgs e) 
{ 
    ods_postit.Insert(); 
} 

Post.cs

public class Post 
{ 
    //Post Private Özellikleri 
    private int _post_id; 
    private Guid _post_user_id; 
    private string _post_baslik; 
    private string _post_etiket; 
    private string _post_icerik; 
    //Post Public Özellikleri 
    public int Post_ID 
    { 
     get { return _post_id; } 
     set { _post_id = value; } 
    } 
    public Guid Post_User_ID 
    { 
     get { return _post_user_id; } 
     set { _post_user_id = value; } 
    } 
    public string Post_Baslik 
    { 
     get { return _post_baslik; } 
     set { _post_baslik = value; } 
    } 
    public string Post_Etiket 
    { 
     get { return _post_etiket; } 
     set { _post_etiket = value; } 
    } 
    public string Post_Icerik 
    { 
     get { return _post_icerik; } 
     set { _post_icerik = value; } 
    } 
} 

databaseworks.cs

public static void PostEkle(Post post) 
{ 
    using (SqlConnection baglanti = new SqlConnection(dbconnect())) 
    { 
     SqlCommand komut = new SqlCommand("sp_post_ekle", baglanti); 
     komut.CommandType = CommandType.StoredProcedure; 
     komut.Parameters.AddWithValue("post_id", post.Post_ID); 
     komut.Parameters.AddWithValue("post_user_id",Membership.GetUser().ProviderUserKey); 
     komut.Parameters.AddWithValue("post_baslik", post.Post_Baslik); 
     komut.Parameters.AddWithValue("post_etiket","#" + post.Post_Etiket); 
     komut.Parameters.AddWithValue("post_icerik", post.Post_Icerik); 
     baglanti.Open(); 
     komut.ExecuteNonQuery(); 
     baglanti.Close(); 
    } 
} 

yonet.cs

public static void PostEkle(Post post) 
{ 
    databaseworks.PostEkle(post); 
} 

回答

1

而在FormView或DetailsView控件處理的UI控件和數據源之間的集成,以及所有與綁定聲明的綁定,你沒有規範的(我認爲,即使您正在使用ControlParameter事項;要麼,或控制參數工作,但你需要的FormView控件)。

此外,ODS沒有在這裏獲得什麼,你在你的情況;你可以完全轉儲ObjectDataSource控件,推動在一個對象的數據備份到業務層和數據寫入你的命令。

+0

感謝回答@布賴恩像你說的,我不得不使用FormView的,我沒有,我現在有大約FormView控件(基本prblm)問題,如果u能幫助我將happy.question [鏈接](HTTP://計算器。 COM /問題/ 16238456/ASP淨窗體視圖-使用-對象數據源回發嵌件) – serdar 2013-04-26 14:13:32

相關問題