...

View Full Version : SqlDataSource control error when trying to sort the data from the grid



binici
02-05-2007, 08:12 PM
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>

nikkiH
02-05-2007, 08:26 PM
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.

nikkiH
02-05-2007, 08:29 PM
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/library/system.web.ui.control.visible(VS.80).aspx

binici
02-05-2007, 08:34 PM
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/library/system.web.ui.control.visible(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?

binici
02-05-2007, 09:31 PM
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!

nikkiH
02-05-2007, 10:03 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum