Question : asp.net - I have a problem - i cannot connect an ajax calendar extention & textbox to the where clause of a gridview datasouce..

I have a problem - i cannot connect an ajax calendar extention & textbox to the where clause of a gridview datasouce.

See code.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
<%@ Page Language="VB"   MasterPageFile="~/Nested Master Pages/admin.master" Title="Untitled Page"  %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.IO" %>

<script runat="server">
    
    Public Sub Page_Load()
        currentUser = Membership.GetUser()
        SqlDataSource1.SelectParameters("UserId").DefaultValue = currentUser.ProviderUserKey.ToString()
        SqlDataSource1.DataBind()
    End Sub

    Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        'If Cancel button is clicked, send user to Default
        Response.Redirect("~/Annonymous/index.aspx")
    End Sub

    Dim currentUser As MembershipUser
    
    Dim TotalUnitPrice As Decimal = 0.0
    Function GetUnitPrice(ByVal fltOrderAmount As Decimal) As Decimal
        TotalUnitPrice += fltOrderAmount
        Return fltOrderAmount
    End Function
    Function GetTotal() As Decimal
        Return TotalUnitPrice
    End Function
    
    Protected Sub btnexportexcel_click(ByVal sender As Object, ByVal e As System.EventArgs)
        Response.Clear()
        Response.Buffer = True
        'For Word: 
        'Response.AddHeader("content-disposition", "attachment;filename=data.doc")
        'Response.ContentType = "application/vnd.ms-word"
        'For Excel 
        Response.AddHeader("content-disposition", "attachment;filename=SummaryReport.xls")
        Response.ContentType = "application/vnd.ms-excel"
        Response.Charset = ""
        Me.EnableViewState = False
        Dim oStringWriter As New System.IO.StringWriter()
        Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)
        SqlDataSource1.RenderControl(oHtmlTextWriter)
        Response.Write(oStringWriter.ToString())
        Response.[End]()
    End Sub
    
    Protected Sub OnSelectedData(ByVal sender As Object, ByVal e As SqlDataSourceStatusEventArgs)
        ' Set the record count label   
        MessageLabel.Text = "Total Records: " + e.AffectedRows.ToString()
    End Sub
    
</script>

<%-- Add content controls here --%>

<asp:Content ID="Content2" runat="server" contentplaceholderid="ContentPlaceHolder4">

    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> </asp:ToolkitScriptManager> 
 Begin Date&nbsp;&nbsp;<asp:TextBox ID="BeginDate" runat="server" Width="70"></asp:TextBox>
    <asp:Image id="Image1" runat="server"  ImageUrl="~/images1/calendar_scheduleHS.png" />
    <asp:CalendarExtender ID="CalendarExtender1"  runat="server" TargetControlID="BeginDate" PopupButtonID="Image1">
    </asp:CalendarExtender>
    End Date&nbsp;&nbsp;<asp:TextBox ID="EndDate" runat="server" Width="70"></asp:TextBox>
     <asp:Image id="Image2" runat="server"  ImageUrl="~/images1/calendar_scheduleHS.png" />
    <asp:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="EndDate" PopupButtonID="Image2">
    </asp:CalendarExtender>
         
      <asp:GridView ID="GridView2" AllowSorting="true" AllowPaging="true" Runat="server" Width="860"
        DataSourceID="SqlDataSource1"  ShowFooter="true" DataKeyNames="Id"   Font-Size="XX-Small" AutoGenerateColumns="False" FooterStyle-HorizontalAlign="Right">
         <Columns>
            <asp:TemplateField ItemStyle-BackColor = "#F4F4F4" HeaderStyle-BackColor="#A1C1D9" HeaderStyle-Font-Size="9"  HeaderStyle-Width="300" ItemStyle-HorizontalAlign="Center" HeaderText="Company Infomation">
                <ItemTemplate>
                    <asp:Label ID="lblCompany" runat="server" BackColor = "#F4F4F4" Text='<%# Eval("Company") %>'></asp:Label>  
                      <asp:Label ID="lblName" runat="server" BackColor = "#F4F4F4" Text='<%#Eval("Name")%>'></asp:Label><br />
                       <asp:Label ID="Lblphone" runat="server" BackColor = "#F4F4F4" Text='<%#Eval("Phone")%>'></asp:Label><br />
                        <asp:Label ID="LblWebSiteUrl" runat="server" BackColor = "#F4F4F4" Text='<%#Eval("WebSiteUrl")%>'></asp:Label>  
                        <asp:Label ID="LblEmail" runat="server" BackColor = "#F4F4F4" Text='<%#Eval("Email")%>'></asp:Label>                 
                </ItemTemplate>
            </asp:TemplateField>


          <asp:BoundField HeaderText=" ID " DataField="ID"  HeaderStyle-BackColor="#A1C1D9" ReadOnly="true" ControlStyle-Width="20" />
          <asp:BoundField HeaderText=" Year " DataField="Year"  HeaderStyle-BackColor="#A1C1D9" ItemStyle-HorizontalAlign="Center" ControlStyle-Width="30" />
          <asp:BoundField HeaderText=" Make " DataField="Make" HeaderStyle-BackColor="#A1C1D9"  ItemStyle-Width="150"/>
          <asp:BoundField HeaderText=" Model " DataField="Model" HeaderStyle-BackColor="#A1C1D9" ItemStyle-Width="100" />
          <asp:BoundField HeaderText=" Type " DataField="Type"  HeaderStyle-BackColor="#A1C1D9" ItemStyle-Width="150" />
          <asp:BoundField HeaderText=" MilesHours " DataField="MilesHours" HeaderStyle-BackColor ="#A1C1D9" ItemStyle-HorizontalAlign="Right" ControlStyle-Width="60" />
          <asp:BoundField HeaderText=" VinSerial " DataField="VinSerial" HeaderStyle-BackColor ="#A1C1D9" ItemStyle-HorizontalAlign="Center" ControlStyle-Width="60" />
          <asp:BoundField HeaderText=" Description " DataField="Description" HeaderStyle-BackColor="#A1C1D9" ItemStyle-Width="150" />
          <asp:BoundField HeaderText=" Location " DataField="Location" HeaderStyle-BackColor ="#A1C1D9" FooterText="Company Total"  ItemStyle-Width="150"/>
          
          <asp:TemplateField HeaderText="Price" HeaderStyle-BackColor="#A1C1D9" FooterStyle-Font-Bold="True" HeaderStyle-Width="40" ItemStyle-HorizontalAlign="Right">
             <ItemTemplate>
               $<%# GetUnitPrice(Decimal.Parse(Eval("Price").ToString())).ToString("N0")%>
             </ItemTemplate>
             <FooterTemplate>
               $<%# GetTotal().ToString("N0") %>
             </FooterTemplate>
          </asp:TemplateField>
          <asp:BoundField HeaderText="Sign Up Date" HeaderStyle-BackColor="#A1C1D9"  ItemStyle-HorizontalAlign="Center" dataformatstring="{0:M-dd-yyyy}" DataField="SignUpDate"  HeaderStyle-Width="70" />
          <asp:BoundField HeaderText="Ending Date"  HeaderStyle-BackColor="#A1C1D9" ItemStyle-HorizontalAlign="Center" dataformatstring="{0:M-dd-yyyy}" DataField="LastLockOutDate" HeaderStyle-Width="70" />

        </Columns>
      </asp:GridView>
 
       <asp:SqlDataSource ID="SqlDataSource1"   OnSelected="OnSelectedData" runat="server"
        ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString %>" 

        SelectCommand="SELECT E.ID, E.UserId, E.Year, E.Make, E.Model, E.Type, E.MilesHours, E.VinSerial, E.Description, E.Location, E.Price, E.SignUpDate, E.EquipmentID 
                    
        FROM [Used_Trucks].[dbo].[Equipment] E
                     
        WHERE E.IsLockedOut = 'True' and (Signupdate between CONVERT(datetime, @BeginDate, 101) And CONVERT(datetime, @EndDate, 101))     
        ORDER BY userId, SignUpDate DESC">

           <SelectParameters>
                <asp:ControlParameter Name="BeginDate" controlId="CalendarExtender1"  PropertyName="SelectedDate" />
                <asp:ControlParameter Name="EndDate"  ControlID="CalendarExtender2"  PropertyName="SelectedDate"/>
           </SelectParameters>
       
       </asp:SqlDataSource>


      <table align="center">
          <tr><td align="center">
               <asp:Button ID="btnExportExcel" runat="server" Text="ExportToExcel" CausesValidation="false" onclick="btnexportExcel_click" />
          </td></tr>
      </table>
      <asp:label id="MessageLabel" forecolor="Red" runat="server"/>

</asp:Content>

Answer : asp.net - I have a problem - i cannot connect an ajax calendar extention & textbox to the where clause of a gridview datasouce..

can u please more ur question more clear
are u trying to filter ur grid based on a date
Random Solutions  
 
programming4us programming4us