Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Mar 2006
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts

    SqlDataSource control error when trying to sort the data from the grid

    Hello:

    I forgot what to do in a case like this. I have a SqlDataSource control within a label and I want to allow auto sorting, but when I click on the sort link the page comes back with:

    The SqlDataSource control 'sqlViewIncompleteForms' does not have a naming container. Ensure that the control is added to the page before calling DataBind.

    [HttpException (0x80004005): The SqlDataSource control 'sqlViewIncompleteForms' does not have a naming container. Ensure that the control is added to the page before calling DataBind.]
    System.Web.UI.WebControls.DataBoundControlHelper.FindControl(Control control, String controlID) +1590679
    System.Web.UI.WebControls.ControlParameter.Evaluate(HttpContext context, Control control) +76
    System.Web.UI.WebControls.Parameter.UpdateValue(HttpContext context, Control control) +46
    System.Web.UI.WebControls.ParameterCollection.UpdateValues(HttpContext context, Control control) +103
    System.Web.UI.WebControls.SqlDataSource.LoadCompleteEventHandler(Object sender, EventArgs e) +40
    System.EventHandler.Invoke(Object sender, EventArgs e) +0
    System.Web.UI.Page.OnLoadComplete(EventArgs e) +2010392
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1209

    How do I over come this? Do I have to use the find control method on page_load? Here is the code portion .vb

    <% 'Label which contains the default.aspx home content %>
    <asp:Label ID="recip_home_display" runat="server" Visible="false">
    <div align="center" class="HeaderSmall">Incomplete Recip Submissions</div>
    <asp:GridView ID="RecipStatusGridView" runat="server" AutoGenerateColumns="False" BorderWidth="0px" DataKeyNames="queue_id"
    DataSourceID="sqlViewIncompleteForms" AllowPaging="True" AllowSorting="True" CellPadding="2" CellSpacing="2" CssClass="TextSmall" HorizontalAlign="Center" Width="500px" Visible="False">
    <Columns>
    <asp:BoundField DataField="queue_id" HeaderText="Incomplete Listings" HtmlEncode="False"
    InsertVisible="False" ReadOnly="True" SortExpression="queue_id">
    <ControlStyle CssClass="LinkNormal" />
    <ItemStyle HorizontalAlign="Center" />
    <HeaderStyle HorizontalAlign="Center" />
    </asp:BoundField>
    <asp:BoundField DataField="form_type" HeaderText="Listing Type" SortExpression="form_type">
    <ItemStyle HorizontalAlign="Center" />
    <HeaderStyle HorizontalAlign="Center" />
    </asp:BoundField>
    <asp:BoundField DataField="listing_address" HeaderText="Listing Address" ReadOnly="True"
    SortExpression="listing_address">
    <ItemStyle HorizontalAlign="Center" />
    <HeaderStyle HorizontalAlign="Center" />
    </asp:BoundField>
    <asp:BoundField DataField="last_modified_date" DataFormatString="{0:d}" HeaderText="Last Modified"
    HtmlEncode="False" SortExpression="last_modified_date">
    <ItemStyle HorizontalAlign="Center" />
    <HeaderStyle HorizontalAlign="Center" />
    </asp:BoundField>
    </Columns>
    <HeaderStyle BackColor="#5C6F8D" />
    <AlternatingRowStyle BackColor="#e9eaf0" />
    </asp:GridView>
    <asp:SqlDataSource ID="sqlViewIncompleteForms" runat="server" ProviderName="System.Data.SqlClient" ConnectionString="<%$ Appsettings:connectionstring %>" SelectCommandType="StoredProcedure" SelectCommand="spGetIncompleteForms">
    <SelectParameters>
    <asp:ControlParameter ControlID="active_member_id" Name="AgentId" />
    </SelectParameters>
    </asp:SqlDataSource>
    </asp:Label>

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    I'd put it in a placeholder, not a label, personally.

    Anyway, take the data source out of the label. Put it somewhere else that doesn't have visible=false in it.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    To elaborate, visible=false will prevent a control from rendering.
    Never put data sources (or any other important components that you expect to always be present) as children of a control that might not always be rendered.

    http://msdn2.microsoft.com/en-us/lib...le(VS.80).aspx

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #4
    New Coder
    Join Date
    Mar 2006
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by nikkiH View Post
    To elaborate, visible=false will prevent a control from rendering.
    Never put data sources (or any other important components that you expect to always be present) as children of a control that might not always be rendered.

    http://msdn2.microsoft.com/en-us/lib...le(VS.80).aspx
    Thanks, I totally agree, but I was just thinking of keeping the form more clean and organized, but dealing with Child controls are a pain. I guess there is no other better way?

  • #5
    New Coder
    Join Date
    Mar 2006
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by binici View Post
    Thanks, I totally agree, but I was just thinking of keeping the form more clean and organized, but dealing with Child controls are a pain. I guess there is no other better way?
    Ok, I see how much better it is to use a placeholder control and use the visible method.

    Thanks!

  • #6
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Right; just use Placeholder instead of Label and put the sql data sources as direct children of Page, but the rest of your content can go in placeholders.

    If you like clean, check out the new view controls. Done are the days of just using a ton of placeholders and setting visible...you can use view controls and set them like little pages all in your big page.
    Master pages are a neat addition to 2.0 as well.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •