473,394 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

SQLDatasource not using SelectCommand from _Selecting Event.

Hello again...

I have tried using the SQLDatsource control as part of a user control that
just conatins a Repeater and the SQLDatasource control which is designated
as the Datsource for the Repeater. I set it up just like in the
documentation.

--------------------------- code ----------------------------------------

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:PCConnectionString %>"

DataSourceMode="DataSet" SelectCommand="Select * from table"
></asp:SqlDataSource>
--------------------------- code ----------------------------------------

Because I need a dynamic query determined at runtime I tried setting the
SelectCommand in the SqlDataSource1_Selecting event, which is SUPPOSED to
fire before the query is sent to the server. The code is below. Note that I
output the new contents of the SelectCommand in Response.Write. That
response line shows up at the very top of the page, yet the SQLDatasource1
insists on using the original SelectCommand in the declaration.

What am I doing wrong?

Thanks to all....

--------------------------- code ----------------------------------------

'This is run Before the Select command is sent to the Server

Protected Sub SqlDataSource1_Selecting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.SqlDataSourceSelectingEv entArgs) Handles
SqlDataSource1.Selecting

_selectCMD = " Select
SearchTitle,SearchDescription,sequence,dateUpdate, keywords " & _

" from user_searchCriteria where userid='" & Me.Session.Item("uid") & "'" &
_

" order by SearchTitle"

Me.SqlDataSource1.SelectCommand = _selectCMD

Response.Write(SqlDataSource1.SelectCommand)

End Sub

--------------------------- code ----------------------------------------


Feb 23 '07 #1
1 5749
Hi all..

Well the SP1 for VS2005 didn't fix the problem I was having so I took a
different approach. Instead of assigning the DataSource of the Repeater
during the declaration of the control I left it unassigned. For the
SQLDataSource control I left the SelectCommand unassigned. Instead, in the
associated source VB code-behind I did all that in the Page_Init event,
adding a DataBind() call, as follows:

Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Init

_userID = Me.Session.Item("uid")

_selectCMD = " Select
SearchTitle,SearchDescription,sequence,dateUpdate, keywords " & _
" from user_searchCriteria where userid='" & Me.Session.Item("uid") &
"'" & _
" order by SearchTitle"

Me.SqlDataSource1.SelectCommand = _selectCMD

Me.Repeater1.DataSource = Me.SqlDataSource1
Me.Repeater1.DataBind()

End Sub

It appears to be working now....
Lesson learned.

"John Kotuby" <jo***@powerlist.comwrote in message
news:uc**************@TK2MSFTNGP03.phx.gbl...
Hello again...

I have tried using the SQLDatsource control as part of a user control that
just conatins a Repeater and the SQLDatasource control which is designated
as the Datsource for the Repeater. I set it up just like in the
documentation.

--------------------------- code ----------------------------------------

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:PCConnectionString %>"

DataSourceMode="DataSet" SelectCommand="Select * from table"
</asp:SqlDataSource>

--------------------------- code ----------------------------------------

Because I need a dynamic query determined at runtime I tried setting the
SelectCommand in the SqlDataSource1_Selecting event, which is SUPPOSED to
fire before the query is sent to the server. The code is below. Note that
I output the new contents of the SelectCommand in Response.Write. That
response line shows up at the very top of the page, yet the SQLDatasource1
insists on using the original SelectCommand in the declaration.

What am I doing wrong?

Thanks to all....

--------------------------- code ----------------------------------------

'This is run Before the Select command is sent to the Server

Protected Sub SqlDataSource1_Selecting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.SqlDataSourceSelectingEv entArgs) Handles
SqlDataSource1.Selecting

_selectCMD = " Select
SearchTitle,SearchDescription,sequence,dateUpdate, keywords " & _

" from user_searchCriteria where userid='" & Me.Session.Item("uid") & "'"
& _

" order by SearchTitle"

Me.SqlDataSource1.SelectCommand = _selectCMD

Response.Write(SqlDataSource1.SelectCommand)

End Sub

--------------------------- code ----------------------------------------




Feb 24 '07 #2

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

Similar topics

5
by: Martin Bischoff | last post by:
Hi, is it possible to modify the values of a SqlDataSource's select parameters in the code behind before the select command is executed? Example: I have an SqlDataSource with a...
15
by: Swetha | last post by:
Hello I have a DropDownList that I am populating using the following SqlDataSource: <asp:DropDownList ID="parentIDDropDownList" runat="server" DataSourceID="SqlDataSource3"...
4
by: | last post by:
I'm building some user controls. I very much like how you can build custom properties to be bound to a user control, and how instances of that control will show those custom properties in the...
3
by: Daniel R. H. | last post by:
Hi, I'm having problems to get the value of a Querystring into the SelectCommand of a SQLDataSource, here's my code: ---------------------------------------------- <asp:SqlDataSource...
0
by: Dan Sikorsky | last post by:
I'm using a stored procedure as the select command for an SqlDataSource tied to a GridView. I've verified the sp returns rows in the Management Studio as well as in VS2005 when I Configure the...
1
by: Jason Wilson | last post by:
I have two dropdownlists that are bound to the same datasource and I have a couple of questions: 1) Because they are bound to the same datasource, I am assuming that they only make 1 round trip...
2
by: Brad Isaacs | last post by:
Good evening friends, I have added a Drop Down List box control to my web form. I am using the web.config connection string to access my SQL Server 2000 db. Inside that db I have a table named...
2
by: Julien Sobrier | last post by:
Hello, I have 2 SqlDataSource on the same page that retrieve the same column names: <asp:SqlDataSource ID="SqlStructure" runat="server" SelectCommand="SELECT a, b FROM c WHERE d = 0 /> ...
4
by: mohaaron | last post by:
This seems like it should be simple to do but for some reason I have been unable to make it work. I would like to databind a SqlDataSource to a GridView during the click event of a button. This...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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...
0
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...

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.