Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   SQLDatasource not using SelectCommand from _Selecting Event. (http://www.velocityreviews.com/forums/t387120-sqldatasource-not-using-selectcommand-from-_selecting-event.html)

John Kotuby 02-23-2007 01:10 PM

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 ----------------------------------------





John Kotuby 02-24-2007 04:53 PM

Re: SQLDatasource not using SelectCommand from _Selecting Event.
 
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" <johnk@powerlist.com> wrote in message
news:uc6eJq0VHHA.4624@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 ----------------------------------------
>
>
>
>
>






All times are GMT. The time now is 05:16 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.