drees727
asked on
ASP.NET Select Command - Call Function
I have 3 files (Test1.aspx, Test1.aspx.vb, TestResults.aspx). I'm using a function to create my SelectCommand sql string. On my TestResults.aspx page, I want to call the function but I'm getting a "Declaration Expected" error message for 'GridView1'. If i try to declare GridView1, it says it's already declared. Any suggestions? Here is what my files look like:
************************** ********** *****
Test1.aspx (this page actually contains several drop down lists and text boxes - I shortened here for simplicity)
<form id="form1" runat="server">
<div>
<asp:TextBox ID="Input Value1" runat="server" Wrap="False"></asp:TextBox >
<br />
<asp:TextBox ID="Input Value2" runat="server"></asp:TextB ox><br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" /></div>
</form>
************************** ********** **
Test1.aspx.vb (SQLString function is actually a long if/then statement that uses the values from the form fields on Test1.aspx.).
Public Class Test1
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Server.Transfer("TestResul ts.aspx")
End Sub
Public Shared Function SQLString() As String
SQLString = "SELECT * FROM Table1"
End Function
End Class
************************** ********** ***
TestResults.aspx looks like this:
<%@ Page Language="VB" AutoEventWireup="false"%>
<script runat=server>
GridView1.SelectCommand = Test1.SQLString()
</script>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False " DataSourceID="AccessDataSo urce1">
<Columns>
<asp:BoundField DataField="Field1" HeaderText="Field1" SortExpression="Field1" />
<asp:BoundField DataField="Field2" HeaderText="Field2" SortExpression="Field2" />
<asp:BoundField DataField="Field3" HeaderText="Field3" SortExpression="Field3" />
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="mydb.mdb"></asp: AccessData Source>
**************************
Test1.aspx (this page actually contains several drop down lists and text boxes - I shortened here for simplicity)
<form id="form1" runat="server">
<div>
<asp:TextBox ID="Input Value1" runat="server" Wrap="False"></asp:TextBox
<br />
<asp:TextBox ID="Input Value2" runat="server"></asp:TextB
<br />
<asp:Button ID="Button1" runat="server" Text="Button" /></div>
</form>
**************************
Test1.aspx.vb (SQLString function is actually a long if/then statement that uses the values from the form fields on Test1.aspx.).
Public Class Test1
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Server.Transfer("TestResul
End Sub
Public Shared Function SQLString() As String
SQLString = "SELECT * FROM Table1"
End Function
End Class
**************************
TestResults.aspx looks like this:
<%@ Page Language="VB" AutoEventWireup="false"%>
<script runat=server>
GridView1.SelectCommand = Test1.SQLString()
</script>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False
<Columns>
<asp:BoundField DataField="Field1" HeaderText="Field1" SortExpression="Field1" />
<asp:BoundField DataField="Field2" HeaderText="Field2" SortExpression="Field2" />
<asp:BoundField DataField="Field3" HeaderText="Field3" SortExpression="Field3" />
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="mydb.mdb"></asp:
I think you need to set the Select property of the AccessDataSource1 datasource control, not the grid.
ASKER
I modifed it the following but am getting 'Declaration Expected' for AccessDataSource1.
<script runat=server>
AccessDataSource1.SelectCo mmand = Test1.SQLString()
</script>
<script runat=server>
AccessDataSource1.SelectCo
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.