Question : ASP.NET ListView showing unexpected data..

Hi have a list cointrol that is bound to an Access DatSource. The problem is when I click search button it starts showing blank data , Am I missing something? What is wrong in my code?

THANKS
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:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="ProviderSearch.aspx.vb" Inherits="ProviderSearch" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    
    <br />
    
    <table cellpadding="0" cellspacing="0" style="border-right: #000000 thin solid; border-top: #000000 thin solid;
                                    border-left: #000000 thin solid; border-bottom: #000000 thin solid; background-color: #FFFFFF; border-width: 1px;"
                                    width="100%">
    <tr>
        <td colspan="2" style="width: 100%; height: 22px; text-align: left;">
            <span style="font-size: 10pt; font-family: Tahoma;">
            <strong style="width: 100%; text-align: center">Search Options</strong></span></td>
    </tr>
    <tr style="font-size: 12pt">
        <td style="width: 38%; text-align: left; height: 24px;">
                                            <span id="providerLabel" style="font-family:Times New Roman;font-size:10pt;">Provider Name:</span>
            <asp:TextBox ID="providerTextBox" runat="server"></asp:TextBox>
            <span style="font-size: 10pt">(All or part of name)</span></td>
        <td style="width: 30%; height: 24px; text-align: left;">
            &nbsp;</td>
    </tr>
    <tr>
        <td style="width: 38%; text-align: left; height: 20px;">
            <span id="specialtyLabel" 
            style="font-family:Times New Roman;font-size:10pt; text-align: left;">Specialty:</span>
            <asp:DropDownList ID="specialityDropDown" runat="server" 
                DataSourceID="AccessDataSource1" DataTextField="Specialty" 
                DataValueField="Specialty">
                              
            </asp:DropDownList>
        </td>
        <td style="width: 30%; height: 20px; text-align: left;">
            <asp:Button ID="searchButton" runat="server" Text="Search" />
        </td>
    </tr>
    <tr>
        <td style="width: 38%; text-align: left; height: 21px;">
            <span id="zipCodeLabel" style="font-family:Times New Roman;font-size:10pt;">Zip Code:</span>
            <asp:TextBox ID="txtZipCode" runat="server"></asp:TextBox>
&nbsp;
            <asp:DropDownList ID="distanceDropDown"  runat="server">
                <asp:ListItem Selected="True" Value ="1000">Find Closest</asp:ListItem>
                <asp:ListItem Value ="10">Within 10 Miles</asp:ListItem>
                <asp:ListItem Value ="25">Within 25 Miles</asp:ListItem>
                <asp:ListItem Value ="50">Within 50 Miles</asp:ListItem>
                <asp:ListItem Value ="100">Within 100 Miles</asp:ListItem>
            </asp:DropDownList>
        </td>
        <td style="width: 30%; height: 21px; text-align: left;">
            <asp:Button ID="showallButton" runat="server" Text="Show All" />
            <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
                DataFile="~/App_Data/Providers.accdb" 
                
                SelectCommand="SELECT DISTINCT [Specialty] FROM [tbl_Providers] ORDER BY [Specialty] ASC">
            </asp:AccessDataSource>
        </td>
    </tr>
</table>
    <br />
    
    <asp:ListView ID="ListView1" runat="server" DataSourceID="AccessDataSource2"  >
        <AlternatingItemTemplate>
        
            <span style="background-color: #FFFFFF;color: #284775;">
            <b>
            <asp:Label ID="Last_NameLabel" runat="server" Text='<%# Eval("Last_Name") %>' />
            ,
             <asp:Label ID="First_NameLabel" runat="server" 
             Text='<%# Eval("First_Name") %>' /></b>
             <br />
            
            <asp:Label ID="SpecialtyLabel" runat="server" Text='<%# Eval("Specialty") %>' />
            <br />
            <asp:Label ID="Specialty_2Label" runat="server" 
            Text='<%# Eval("[Specialty2]") %>' />
            <br />
            Address:
             <asp:Label ID="AddressLabel" runat="server" Text='<%# Eval("Address") %>' />
            <br />
            <asp:Label ID="Address2Label" runat="server" Text='<%# Eval("Address2") %>' />
            <br />
             <asp:Label ID="CityLabel" runat="server" Text='<%# Eval("City") %>' />
            ,
            <asp:Label ID="StateLabel" runat="server" Text='<%# Eval("State") %>' />
            ,
            <asp:Label ID="ZipLabel" runat="server" Text='<%# Eval("Zip") %>' />
            <br />
           
            Phone:
            <asp:Label ID="PhoneLabel" runat="server" Text='<%# Eval("Phone") %>' />
            <br />
            Fax:
            <asp:Label ID="FaxLabel" runat="server" Text='<%# Eval("Fax") %>' />
            <br />
            <br></br>
</span>
        </AlternatingItemTemplate>
       
        <EmptyDataTemplate>
            <span></span>
        </EmptyDataTemplate>
        
        <ItemTemplate>
            <span style="background-color: #E0FFFF;color: #333333;">
          
          <b>
            <asp:Label ID="Last_NameLabel" runat="server" Text='<%# Eval("Last_Name") %>' />
            ,
             <asp:Label ID="First_NameLabel" runat="server" 
             Text='<%# Eval("First_Name") %>' /></b>
             <br />
            </b>
            <asp:Label ID="SpecialtyLabel" runat="server" Text='<%# Eval("Specialty") %>' />
            <br />
            <asp:Label ID="Specialty_2Label" runat="server" 
            Text='<%# Eval("[Specialty2]") %>' />
            <br />
            Address:
            <br />
            <asp:Label ID="AddressLabel" runat="server" Text='<%# Eval("Address") %>' />
            <br />
            <asp:Label ID="Address2Label" runat="server" Text='<%# Eval("Address2") %>' />
            <br />
            <asp:Label ID="CityLabel" runat="server" Text='<%# Eval("City") %>' />
            ,
            <asp:Label ID="StateLabel" runat="server" Text='<%# Eval("State") %>' />
            ,
            <asp:Label ID="ZipLabel" runat="server" Text='<%# Eval("Zip") %>' />
            <br />
           
            Phone:
            <asp:Label ID="PhoneLabel" runat="server" Text='<%# Eval("Phone") %>' />
            <br />
            Fax:
            <asp:Label ID="FaxLabel" runat="server" Text='<%# Eval("Fax") %>' />
            <br />
<br />
</span>
        </ItemTemplate>
        <LayoutTemplate>
            <div ID="itemPlaceholderContainer" runat="server" 
                style="font-family: Verdana, Arial, Helvetica, sans-serif;">
                <span runat="server" id="itemPlaceholder" />
            </div>
            <div style="text-align: center;background-color: #5D7B9D;font-family: Verdana, Arial, Helvetica, sans-serif;color: #FFFFFF;">
                <asp:DataPager ID="DataPager1" runat="server" PageSize="15">
                    <Fields>
                        <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                            ShowLastPageButton="True" />
                        
                    </Fields>
                </asp:DataPager>
            </div>
        </LayoutTemplate>
        <SelectedItemTemplate>

            <span style="background-color: #E2DED6;font-weight: bold;color: #333333;">
            <asp:Label ID="Last_NameLabel" runat="server" Text='<%# Eval("Last_Name") %>' />
            ,
            <asp:Label ID="First_NameLabel" runat="server" 
                Text='<%# Eval("First_Name") %>' />
            <br />
                     
            <asp:Label ID="SpecialtyLabel" runat="server" Text='<%# Eval("Specialty") %>' />
            <br />
            <asp:Label ID="Specialty_2Label" runat="server" 
            Text='<%# Eval("[Specialty2]") %>' />
            <br />
            Address:
            <asp:Label ID="AddressLabel" runat="server" Text='<%# Eval("Address") %>' />
            <br />
            <asp:Label ID="Address2Label" runat="server" Text='<%# Eval("Address2") %>' />
            <br />
            <asp:Label ID="CityLabel" runat="server" Text='<%# Eval("City") %>' />
            ,
            <asp:Label ID="StateLabel" runat="server" Text='<%# Eval("State") %>' />
            ,
            <asp:Label ID="ZipLabel" runat="server" Text='<%# Eval("Zip") %>' />
            <br />
            Phone:
            <asp:Label ID="PhoneLabel" runat="server" Text='<%# Eval("Phone") %>' />
            <br />
            Fax:
            <asp:Label ID="FaxLabel" runat="server" Text='<%# Eval("Fax") %>' />
            <br />
            </span>
        </SelectedItemTemplate>
    </asp:ListView>
       

 
       <asp:AccessDataSource ID="AccessDataSource2" runat="server" 
        DataFile="~/App_Data/Providers.accdb" 
        SelectCommand="SELECT [First_Name] AS First_Name, [Last_Name] AS Last_Name, [Specialty], [Specialty2],[Address], [Address2], [City], [State], [Zip], [Phone], [Fax] FROM [tbl_Providers] WHERE  
        (@Specialty IS NULL OR Specialty LIKE '%' + @Specialty + '%') AND  
        (@Zip IS NULL OR Zip LIKE '%' + @Zip + '%') "
  
        CancelSelectOnNullParameter="False">

        <SelectParameters>

         <asp:ControlParameter ControlID="specialityDropDown" Name="Specialty" Type="String" />
         <asp:ControlParameter ControlID="txtZipCode" Name="Zip" Type="String" />
     
</SelectParameters>
       
        </asp:AccessDataSource>
           <br />
</asp:Content>

Answer : ASP.NET ListView showing unexpected data..

I said ConvertEmptyStringToNull="true" to yours ControlParameters.

That way, if your control`s value is the empty string (""), the ControlParameters will pass the null value to your @parameter. since you are testing for it (@Zip IS NULL or ...) you need to set this property to true so an empty textbox will send a null value to the query.

 

Random Solutions  
 
programming4us programming4us