Note that there are some explanatory texts on larger screens.

plurals
  1. POBind asp:Parameter in asp:SqlDataSource to Database field
    primarykey
    data
    text
    <p>I use an <code>asp:SqlDataSource</code> Element to fetch Data and then display it in an <code>asp:ListView</code>.</p> <p>For the sake of simplicity, let's assume the Database consists of the rows and <code>id</code>, <code>author</code> (it's actually more, but that doesn't matter). </p> <p>This is the code I use:</p> <pre><code>&lt;asp:SqlDataSource ID="NewsDataSource" runat="server" ConnectionString="&lt;%$ connectionStrings:RemoteSqlConnection %&gt;" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [news]" UpdateCommand="UPDATE [news] SET author=@author WHERE id=@id" DeleteCommand="DELETE FROM [news] WHERE id=@id" InsertCommand="INSERT INTO [news] (author) VALUES (@author)"&gt; &lt;UpdateParameters&gt; &lt;asp:Parameter Name="id" Type="Int32" /&gt; &lt;/UpdateParameters&gt; &lt;DeleteParameters&gt; &lt;asp:Parameter Name="id" Type="Int32" /&gt; &lt;/DeleteParameters&gt; &lt;/asp:SqlDataSource&gt; </code></pre> <p>My problem is, that the parameter <code>id</code> which I define for <code>UpdateParameters</code> and <code>DeleteParameters</code> is always <code>null</code>. It doesn't seem to be associated with the database field <code>id</code>. </p> <p>One hack which allowed me to fix the problem (but only for the update case) was to insert an invisible <code>asp:Label</code> to which I binded the <code>id</code> (Just like I binded the Author field to a Textbox). </p> <p>I don't think that the ListView code should be relevant, but I'll try to include some lines which are relevant here:</p> <pre><code>&lt;asp:ListView runat="server" DataSourceID="NewsDataSource"&gt; &lt;LayoutTemplate&gt; &lt;div id="itemPlaceholder" runat="server"&gt;&lt;/div&gt; &lt;/LayoutTemplate&gt; &lt;ItemTemplate&gt; &lt;%# Eval("author")%&gt; &lt;/ItemTemplate&gt; &lt;EditItemTemplate&gt; &lt;!-- This line is only the workaround solution --&gt;&lt;asp:Label ID="idLabel" runat="server" Text='&lt;%# Bind("id")%&gt;'&gt;&lt;/asp:Label&gt; &lt;asp:TextBox ID="authorTextbox" runat="server" Text='&lt;%# Bind("author")%&gt;'&gt;&lt;/asp:TextBox&gt; &lt;/EditItemTemplate&gt; &lt;/asp:ListView&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload