asp.net 2.0 gridview controls - bound or unbound?

P

pol_c

I am fairly new to asp's and .Net and I would like to use a session
variable when defining the Select Command for a gridview but it doesnt
seem to like it (see code sample below). Does anyone have any
suggestions?

<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$
ConnectionStrings:progressConnectionString %>"
SelectCommand= "SELECT [SONo], [SOContact], [SOCustOrder],
[SODate], [SOContractNo], [SOSalesRep] FROM [SalesOrder] WHERE
[SOCustID ] = '" & Session("myAccount") & "' ORDER BY [SONo],
[SODate];">
</asp:SqlDataSource>

Previously before I had populated the grid on the page load which
worked but this wouldnt allow me to allow paging and sorting on the
grid (see below)

<%@ Page Language="VB" MasterPageFile="~/Progress.master"
Title="Untitled Page" %>

<script runat="server">
Dim strConn As String =
ConfigurationManager.ConnectionStrings("ProgressConnectionString").ConnectionString
Dim myReader As SqlDataReader

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)

Using con As New SqlConnection(strConn)
con.Open()

Dim strSQL As String = "SELECT [SONo], [SOContact],
[SOCustOrder], " _
& "[SODate], [SOContractNo], [SOSalesRep] " _
& "FROM [SalesOrder] " _
& "WHERE [SOCustID ] = '" & CStr(Session("myAccount"))
& "' " _
& "ORDER BY [SONo], [SODate];"

' Create command
Dim myCommand As New SqlCommand(strSQL, con)
myReader = myCommand.ExecuteReader()

If myReader.HasRows Then
Me.CustomerOrdersGrid.DataSource = myReader
Me.CustomerOrdersGrid.DataBind()
End If

End Using

End Sub
</script>


Many thanks in advance

Paul
 
A

alvinzc

Hi,

It can be done by specifying the SessionParameter control in the
<SelectParameters> of SqlDataSource. For instance,

<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$
ConnectionStrings:progressConnectionString %>"
SelectCommand= "SELECT [SONo], [SOContact], [SOCustOrder],
[SODate], [SOContractNo], [SOSalesRep] FROM [SalesOrder] WHERE
[SOCustID ] = @MyAccount ORDER BY [SONo],
[SODate];">
<SelectParameters>
<asp:SessionParameter Name="MyAccount" DefaultValue="myAccount"
......./>
</asp:SqlDataSource>


Hope this helps..



Regards,
Alvin Chooi
Microsoft ASP.NET Enthusiast
http://alvinzc.blogspot.com
 
A

alvinzc

Hi, it can be done by specifying the value to the SessionParameter
control in the <SelectParameters> of SqlDataSource. For instance,


<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$
ConnectionStrings:progressConnectionString %>"
SelectCommand= "SELECT [SONo], [SOContact], [SOCustOrder],
[SODate], [SOContractNo], [SOSalesRep] FROM [SalesOrder] WHERE
[SOCustID ] = @MyAccount ORDER BY [SONo],
[SODate];">
<SelectParameters>
<asp:SessionParameter Name="MyAccount" DefaultValue="myAccount"
........./>
</SelectParameters>
</asp:SqlDataSource>


Hope this helps..


Regards,
Alvin Chooi
Microsoft ASP.NET Enthusiast
http://alvinzc.blogspot.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top