Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Controls / October 2006

Tip: Looking for answers? Try searching our database.

asp.net 2.0 gridview controls - bound or unbound?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pol_c@btinternet.com - 25 Oct 2006 11:52 GMT
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
alvinzc@gmail.com - 26 Oct 2006 03:31 GMT
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
alvinzc@gmail.com - 26 Oct 2006 03:35 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.