dropdown list wont populate values from sql database
<p>I've been strugglng with this one problem for a while now. I have an application as:   </p>

<pre><code>  &lt;asp:SqlDataSource runat="server" ID="categoriesDataSource"
     SelectCommand="SELECT [CategoryID], [Name], [UserId] FROM [Categories] WHERE ([UserId] = @UserId) ORDER BY [Name]"&gt;
     &lt;SelectParameters&gt;
         &lt;asp:QueryStringParameter Name="CategoryID" QueryStringField="ID"  /&gt;
     &lt;/SelectParameters&gt;
  &lt;/asp:SqlDataSource&gt;

    Pick a category: &amp;nbsp;
  &lt;asp:DropDownList ID="categories" runat="server" AutoPostBack="True"
      DataSourceID="categoriesDataSource" DataTextField="Name" 
      DataValueField="CategoryID" AppendDataBoundItems="True"&gt;
    &lt;asp:ListItem Selected="True" Value=""&gt;-- All Categories --&lt;/asp:ListItem&gt;
 &lt;/asp:DropDownList&gt;

 &lt;asp:SqlDataSource ID="picturesDataSource" runat="server" ConnectionString="&lt;%$ ConnectionStrings:ConnectionString %&gt;"
            ProviderName="&lt;%$ ConnectionStrings:ConnectionString.ProviderName %&gt;"
            SelectCommand="SELECT PictureID, Title, UploadedOn
 FROM Pictures 
WHERE UserId = @UserId AND
(CategoryID = @CategoryID OR @CategoryID IS NULL)
ORDER BY UploadedOn DESC" CancelSelectOnNullParameter="False"&gt;
                &lt;SelectParameters&gt;
                    &lt;asp:QueryStringParameter Name="UserId" QueryStringField="ID" /&gt;
                    &lt;asp:ControlParameter ControlID="categories" Name="CategoryID" PropertyName="SelectedValue"
                        Type="Int32" /&gt;
                &lt;/SelectParameters&gt;
            &lt;/asp:SqlDataSource&gt;
            &lt;br /&gt;
    &lt;asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" 
        DataKeyNames="PictureID" DataSourceID="picturesDataSource" ForeColor="#333333" 
        GridLines="None"&gt;
        &lt;AlternatingRowStyle BackColor="White" /&gt;
        &lt;Columns&gt;
            &lt;asp:HyperLinkField DataNavigateUrlFields="PictureID" 
                DataNavigateUrlFormatString="~/Photodetail.aspx?ID={0}" Text="View Comments" /&gt;
            &lt;asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" /&gt;
            &lt;asp:BoundField DataField="UploadedOn" HeaderText="Date Added" 
                SortExpression="UploadedOn" /&gt;
            &lt;asp:ImageField DataImageUrlField="PictureID" 
                DataImageUrlFormatString="~/UploadedImages/{0}.jpg" HeaderText="Image"&gt;
                &lt;ControlStyle Width="100px" /&gt;
            &lt;/asp:ImageField&gt;
        &lt;/Columns&gt;
        &lt;EditRowStyle BackColor="#2461BF" /&gt;
        &lt;FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /&gt;
        &lt;HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /&gt;
        &lt;PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /&gt;
        &lt;RowStyle BackColor="#EFF3FB" /&gt;
        &lt;SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /&gt;
        &lt;SortedAscendingCellStyle BackColor="#F5F7FB" /&gt;
        &lt;SortedAscendingHeaderStyle BackColor="#6D95E1" /&gt;
        &lt;SortedDescendingCellStyle BackColor="#E9EBEF" /&gt;
        &lt;SortedDescendingHeaderStyle BackColor="#4870BE" /&gt;
    &lt;/asp:GridView&gt;
</code></pre>

<p>When i  take away the </p>

<pre><code>&lt;SelectParameters&gt;
    &lt;asp:QueryStringParameter Name="CategoryID" QueryStringField="ID"  /&gt;
&lt;/SelectParameters&gt;
</code></pre>

<p>and <code>([UserId] = @UserId)</code>, the dropdown list control will populate values from the database but when I leave those 2, it won't populate any value from the database. </p>

<p>When I remove  the </p>

<pre><code> &lt;asp:QueryStringParameter Name="CategoryID" QueryStringField="ID"  /&gt;
     &lt;/SelectParameters&gt;,
</code></pre>

<p>and leave <code>([UserId] = @UserId)</code>, I get the error:</p>

<blockquote>
  <p>Must declare the scalar variable "@UserId". </p>
</blockquote>

<p>Can somebody please help me out?
Thanks in advance</p>
