473,505 Members | 15,626 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Issue: The SqlDataSource control does not have a naming container

Hi All,

Could any expert point out what is wrong in my code?
I search around but couldn't found answer. It seems that I am the first
person have this problem. Thanks in advanced

I have a gridview that one column contains a dropDownList and a
SqlDataSource control.
I try to set up dropDownList selection by following code.

------------------------------------------------
Protected Sub GridViewCapacity_RowCreated(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridViewCapacity.RowCreated
If (e.Row.RowState And DataControlRowState.Edit) <> 0 OrElse
(e.Row.RowState And DataControlRowState.Insert) <> 0 Then

Dim tmp As DropDownList =
CType(e.Row.FindControl("DropDownListLineSS"), DropDownList)
tmp.DataBind()

If Not
IsNothing(tmp.Items.FindByValue(DataBinder.Eval(e. Row.DataItem,
"DropDownListLineSS").ToString())) Then
tmp.SelectedValue = DataBinder.Eval(e.Row.DataItem,
"AssignedLineSS").ToString()
End If
End If
End Sub
------------------------------------------------

Following error message was displayed when execute line "
tmp.DataBind() "

The SqlDataSource control 'SqlDataSourceLineSS' does not have a naming
container. Ensure that the control is added to the page before calling
DataBind.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The SqlDataSource control
'SqlDataSourceLineSS' does not have a naming container. Ensure that
the control is added to the page before calling DataBind.

Source Error:
Line 50: 'DropDownListLineSS
Line 51: tmp =
CType(e.Row.FindControl("DropDownListLineSS"), DropDownList)
Line 52: tmp.DataBind()
Line 53:
Line 54: If Not
IsNothing(tmp.Items.FindByValue(DataBinder.Eval(e. Row.DataItem,
"DropDownListLineSS").ToString())) Then
Source File: C:\Work\WIP\EditCapacityData.aspx.vb Line: 52

Mar 10 '06 #1
2 6067
Wouldn't the tmp = Ctype.... code copy the object data in
DropDownListSS into tmp? Do you need to call tmp.DataBind()?

I think what's happening is you are getting the datasource property on
tmp from dropdownlistss and that's causing the problem. tmp isn't on
the page, it's local, so when sqldatasourcess tries to bind to it, it's
not found.

But that is just a guess, i'm not positive if that's the problem.

HTH,
Darren Kopp
http://blog.secudocs.com/

Mar 10 '06 #2
Thanks for reply.
The reason I call DataBind is because I could not find query data in
DropDownListSS control.

I found that it seems too early to initialize the DropDownList control
in RowCreated function. In gridview PreRender function, the query data
in the DropDownListSS is load properly.

My question is: How can I initialize DropDownList in PreRender
function.
The hard part is following code doesn't work in gridview PreRender
function:

DataBinder.Eval(e.Row.DataItem, "AssignedLineSS").ToString()

Thanks

Darren Kopp wrote:
Wouldn't the tmp = Ctype.... code copy the object data in
DropDownListSS into tmp? Do you need to call tmp.DataBind()?

I think what's happening is you are getting the datasource property on
tmp from dropdownlistss and that's causing the problem. tmp isn't on
the page, it's local, so when sqldatasourcess tries to bind to it, it's
not found.

But that is just a guess, i'm not positive if that's the problem.

HTH,
Darren Kopp
http://blog.secudocs.com/


Mar 10 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3080
by: Alex | last post by:
Interested in more .NET stuff visit www.dedicatedsolutions.co.uk The DataList is not as powerful as the DataGrid. It requires more work from you since it has no default data presentation format....
3
6876
by: neverstill | last post by:
Hi- I have an asp:image control in the ItemTemplate of a DataList currently, in the ItemDataBound event, I am getting a reference to the image control by looping through all the controls in the...
3
1745
by: P.L. | last post by:
Hi! I have problem with Datarepeater control. When I load template from external aspx file ItemTemplate = Page.LoadTemplate(....); I can't find control in ItemDataBound event. ...
2
4900
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
5
7674
by: msch-prv | last post by:
Hi, I am trying to tie a SQLDataSource control to MySQL without success. The connection string works ok with an ObjectDataSource. (Native asp.net 2.0 MySQL dll loaded in /bin) For some reason,...
6
6449
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hi... I'm trying to implement roles in various components (i.e. using different sets of configuration depending, in this case, on which environment your in). Pretty easy to add an AppSettings...
8
6143
oll3i
by: oll3i | last post by:
it worked but suddenly when i run it and click a button it throws exception ? D:\SR>java Producent queue1 queue2 queue3 queue4 queue1,queue2,queue3,queue4...
1
1415
by: Nathan Sokalski | last post by:
I am writing a Validator by inheriting from the BaseValidator class. I need to access the control referred to by the ControlToValidate property. Because ControlToValidate is a String, I will need...
2
3579
by: =?Utf-8?B?VkIuTmV0IFBybw==?= | last post by:
I have a user control (.ascx) with a combo box in it. I place it and a SQLDataSource control on a web form. I want a SQLDataSource parameter to point to the combo box, but it seems that the...
0
7216
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7303
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.