|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
asp.net 2.0 gridview controls - bound or unbound?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 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 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
3 step wizard - ignore last step
Can't duplicate ID in subclassed GridView Javascript and asp.net - TextBox backcolor not changing... Gridview sorting event - Gridview Datasource always Null .. why??? WebParts & Highend Portals way to make 2 GridViews line up javascript and navigateurl a bug in BaseValidator.RegisterValidatorCommonScript() implementat GridView - ObjectDataSource - Dynamic Columns My own control - exception in Design view |
|||||||||||||||||||||||