GridView issue

DavePro1962

Member
Joined
Feb 5, 2010
Messages
6
Programming Experience
1-3
Hi all

I am new to ASP .NET and am trying to display a page which return the content of a table, this is fine and works well, however what I now want to do is change the SQL at run time so that it will run a specific SQL depend on the selection from a drop down and the text in a text box.

Please see the code I have written, it just wont work,:mad:

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="SearchProperties.aspx.vb" Inherits="Responsive_Repairs_Web.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<p>
<asp:DropDownList ID="ddlSearchCriteria" runat="server">
<asp:ListItem>UPRN</asp:ListItem>
<asp:ListItem>BPRN</asp:ListItem>
<asp:ListItem>BLOCK</asp:ListItem>
<asp:ListItem>ROAD</asp:ListItem>
<asp:ListItem>POST CODE</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server" onclick=submit/>
<script runat="server" language="VB">
Private searchSQL As String
Sub submit(ByVal sender As Object, ByVal e As EventArgs)
Select Case ddlSearchCriteria.Text
Case Is = "UPRN"
searchSQL = "select * from tblproperties_full where UPRN = " & Me.txtSearch.Text & ";"
Case Is = "BPRN"
searchSQL = "select * from tblproperties_full where BPRN = " & Me.txtSearch.Text & ";"
Case Is = "BLOCK"
searchSQL = "select * from tblproperties_full where prop_name = " & Me.txtSearch.Text & ";"
Case Is = "ROAD"
searchSQL = "select * from tblproperties_full where street = " & Me.txtSearch.Text & ";"
Case Is = "POST CODE"
searchSQL = "select * from tblproperties_full where POST_CODE = " & Me.txtSearch.Text & ";"
End Select


End Sub
</script>
</p>

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="PropertyList">
<Columns>
<asp:BoundField DataField="UPRN" HeaderText="UPRN" SortExpression="UPRN" />
<asp:BoundField DataField="BPRN" HeaderText="BPRN" SortExpression="BPRN" />
<asp:BoundField DataField="CLIENT" HeaderText="CLIENT"
SortExpression="CLIENT" />
<asp:BoundField DataField="PROP_NO" HeaderText="PROP_NO"
SortExpression="PROP_NO" />
<asp:BoundField DataField="PROP_NAME" HeaderText="PROP_NAME"
SortExpression="PROP_NAME" />
<asp:BoundField DataField="STREET" HeaderText="STREET"
SortExpression="STREET" />
<asp:BoundField DataField="AREA" HeaderText="AREA" SortExpression="AREA" />
<asp:BoundField DataField="POST_CODE" HeaderText="POST_CODE"
SortExpression="POST_CODE" />
</Columns>
</asp:GridView>

<asp:AccessDataSource> ID="PropertyList" runat="server"
DataFile="~/App_Data/PITS_Maintenance.accdb"
SelectCommand=searchSQL
</asp:AccessDataSource>
</asp:Content>

**************************************

Thanks in advance
 
Back
Top