I have a list of 300 tables saved in a table called fieldspecifics
I have an aspx page on which I have a listbox where the user can select a table
When a table is selected I want the page to display the data from fieldnames which are specified in the fieldspecifics table
The fieldspecifics table has Tablename field, tableid field, showfield1, showfield2.
The tables I want displayed are saved in this one table where showfield1 is the first fieldname I want displayed for that table.
I wanted to do it like this so that I didn't have to write seperate aspx pages for each table.
I have included my first attempt at it which just displays the fieldname for the table selected
I want it to display all records in the table with these two field names
This is the aspx page
<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.SqlClient" %>
<html>
<head>
<title>Archives - Select a Table To Search</title>
</head>
<body>
<form runat="server" method="post">
<asp:ListBox id="lbxTables"
runat="server" AutoPostBack="True"
Rows="5"
OnSelectedIndexChanged="subListChange"/>
<br/><br/>
<asp
atagrid id= "dgtabledata" runat="server" />
</form>
</body>
</html>
<script language="VB" runat="server">
Sub Page_Load(Source As Object, E As EventArgs)
If Not IsPostback then
Dim strConnection As String = Configurationsettings.appsettings("Archives")
Dim strSQLforListbox as string = "SELECT nameoftable,TABLEID FROM fieldspecifics ORDER BY nameoftable"
Dim objConnection As New SqlConnection(strConnection)
Dim objCommand As New SqlCommand(strSQLforListbox, objConnection)
objconnection.open()
lbxTables.Datasource = objcommand.executeReader()
lbxTables.DataTextField = "nameoftable"
lbxTables.datavaluefield = "TABLEID"
lbxTables.DataBind()
objconnection.Close()
End If
End Sub
Sub subListChange(S as object, E As EventArgs)
'Response.Write("subListchange triggered")
Dim strConnection as String = Configurationsettings.appsettings("Archives")
Dim objConnection as new sqlconnection(strconnection)
Dim objcommand as new sqlcommand("sp_Settable", objconnection)
objcommand.commandtype =commandtype.storedprocedure
Dim objparameter as new sqlparameter("@tableid" ,sqldbtype.int )
objcommand.parameters.add(objparameter)
objParameter.Direction =ParameterDirection.Input
objparameter.value =lbxTables.Selecteditem.Value
objconnection.Open()
dgtabledata.datasource = objcommand.executereader()
dgtabledata.databind()
objconnection.close()
End Sub
</script>
The storeprocedure 'sp_Settable' is
CREATE PROCEDURE archivesuser.sp_Settable @tableid int
AS SELECT ShowField1, ShowField2 FROM fieldspecifics WHERE TABLEID = @tableid
GO
I have an aspx page on which I have a listbox where the user can select a table
When a table is selected I want the page to display the data from fieldnames which are specified in the fieldspecifics table
The fieldspecifics table has Tablename field, tableid field, showfield1, showfield2.
The tables I want displayed are saved in this one table where showfield1 is the first fieldname I want displayed for that table.
I wanted to do it like this so that I didn't have to write seperate aspx pages for each table.
I have included my first attempt at it which just displays the fieldname for the table selected
I want it to display all records in the table with these two field names
This is the aspx page
<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.SqlClient" %>
<html>
<head>
<title>Archives - Select a Table To Search</title>
</head>
<body>
<form runat="server" method="post">
<asp:ListBox id="lbxTables"
runat="server" AutoPostBack="True"
Rows="5"
OnSelectedIndexChanged="subListChange"/>
<br/><br/>
<asp
</form>
</body>
</html>
<script language="VB" runat="server">
Sub Page_Load(Source As Object, E As EventArgs)
If Not IsPostback then
Dim strConnection As String = Configurationsettings.appsettings("Archives")
Dim strSQLforListbox as string = "SELECT nameoftable,TABLEID FROM fieldspecifics ORDER BY nameoftable"
Dim objConnection As New SqlConnection(strConnection)
Dim objCommand As New SqlCommand(strSQLforListbox, objConnection)
objconnection.open()
lbxTables.Datasource = objcommand.executeReader()
lbxTables.DataTextField = "nameoftable"
lbxTables.datavaluefield = "TABLEID"
lbxTables.DataBind()
objconnection.Close()
End If
End Sub
Sub subListChange(S as object, E As EventArgs)
'Response.Write("subListchange triggered")
Dim strConnection as String = Configurationsettings.appsettings("Archives")
Dim objConnection as new sqlconnection(strconnection)
Dim objcommand as new sqlcommand("sp_Settable", objconnection)
objcommand.commandtype =commandtype.storedprocedure
Dim objparameter as new sqlparameter("@tableid" ,sqldbtype.int )
objcommand.parameters.add(objparameter)
objParameter.Direction =ParameterDirection.Input
objparameter.value =lbxTables.Selecteditem.Value
objconnection.Open()
dgtabledata.datasource = objcommand.executereader()
dgtabledata.databind()
objconnection.close()
End Sub
</script>
The storeprocedure 'sp_Settable' is
CREATE PROCEDURE archivesuser.sp_Settable @tableid int
AS SELECT ShowField1, ShowField2 FROM fieldspecifics WHERE TABLEID = @tableid
GO