Problem with SqlDataSource when trying to sort datagrid items

Discussion in 'C#' started by binici, Feb 5, 2007.

  1. #1
    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>
     
    binici, Feb 5, 2007 IP
  2. binici

    binici Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Ok, someone helped me on this issue. It is better to use a placeholder control instead to avoid the child controls.
     
    binici, Feb 5, 2007 IP
  3. TasteOfPower

    TasteOfPower Peon

    Messages:
    572
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i hate placeholders. i never use em.
     
    TasteOfPower, Feb 5, 2007 IP
  4. Lord Matt

    Lord Matt Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I'd forgotten how verbose ASP can be.

    I'd want to push a pointer onto a simple variable name and use it as an object

    MyVar &= System.Web.UI.WebControls.OBJECT

    But I'm not even sure if you can. I'm glad I rarely code in it these days.

    But any sort of marker (place holder, pointer, etc) is a programming boon without which everything becomes very hard to read and rather bulky.
     
    Lord Matt, Feb 6, 2007 IP
  5. MarkusJ_NZ

    MarkusJ_NZ Well-Known Member

    Messages:
    240
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #5
    LordMatt, If I understand correctly what you are trying to do (Kind of like pointers in C++) look at delegates in C#.
    Regards
    Markus
     
    MarkusJ_NZ, Feb 22, 2007 IP