<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<head>
<title>Calling Data Functions in Code Behind (SQL)</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server" src="~/shared/fetchData_sql.cs" />
<script language="C#" runat="server">
SqlConnection myConn;
string tag, tagDesc;
void Page_Load ( Object src, EventArgs e ) {
if ( !IsPostBack ) {
tagsGrid.DataSource = fetchData ( "SELECT Tag FROM Tags ORDER BY Tag" );
tagsGrid.DataBind ( );
tagsGrid.SelectedIndex = 0;
getSelected ( null, null );
}
}
void setPage ( Object src, GridViewPageEventArgs e ) {
tagsGrid.PageIndex = e.NewPageIndex;
tagsGrid.DataSource = fetchData ( "SELECT Tag FROM Tags ORDER BY Tag" );
tagsGrid.DataBind ( );
tagsGrid.SelectedIndex = 0;
getSelected ( null, null );
}
void getSelected ( Object src, EventArgs e ) {
tag = tagsGrid.SelectedDataKey.Value.ToString ( );
tagDesc = Convert.ToString ( fetchScalar ( "SELECT Description FROM Tags WHERE Tag = '" + tag + "'" ) );
string query = "SELECT Att, Value, Description, Url FROM Att_Vals WHERE Parent = '" + tag + "'";
attsGrid.DataSource = fetchReader ( query );
attsGrid.DataBind ( );
attsGrid.Visible = attsGrid.Rows.Count > 0;
if ( attsGrid.Rows.Count > 0 )
desc.InnerHtml = "The <b>< " + tag + " ></b> element supports the following attributes, " +
"in addition to global attributes common to all HTML elements.";
else
desc.InnerHtml = "The <b>< " + tag + " ></b> element does not have attributes of its own, " +
"but supports global attributes common to all HTML elements.";
}
</script>
<style>
table.main { border: 1px inset }
table.tags { background-color: ghostwhite }
.tags th { background-color: navy; color: lime; padding: 5 }
.tags td { vertical-align: top; padding: 5 }
</style>
</head>
<body>
<!-- #include virtual="~/shared/top.inc" -->
<div class="header"><h2>Calling Data Functions in Code Behind (<b>SQL Server</b>)</h2></div>
<!-- #include virtual="~/shared/viewsrc_top.inc" -->
<center>
<form runat="server">
<table width=92% class="main" cellpadding=10 cellspacing=10>
<tr valign=top>
<td width=12% class="tags" align="center">
<asp:gridview id="tagsGrid" runat="server"
datakeynames="tag"
width="96%" align="center" font-size=10pt
cellpadding=5 gridlines="horizontal"
autogeneratecolumns=false
allowpaging pagesize=18
onPageIndexChanging="setPage"
onSelectedIndexChanged="getSelected">
<selectedrowstyle backcolor="sienna" forecolor="khaki" />
<pagersettings mode=numericfirstlast />
<columns>
<asp:buttonfield headertext="HTML Elements"
datatextfield="tag"
commandname="Select" />
</columns>
</asp:gridview>
</td>
<td width=88%>
<p><%= tagDesc %>
<p id="desc" runat=server />
<center>
<asp:gridview id="attsGrid" runat="server"
width="98%" align="center" font-size=10pt
cellpadding=8 cellspacing=1 gridlines="horizontal"
autogeneratecolumns=false visible=false>
<headerstyle backcolor="#004040"
forecolor="khaki" font-bold />
<alternatingrowstyle backcolor="beige" />
<columns>
<asp:hyperlinkfield headertext="Attribute"
datatextfield="att"
datanavigateurlfields="url"
datanavigateurlformatstring="/abkd/refs/atts/{0}.aspx"
target="atts"
itemstyle-width=15% />
<asp:boundfield headertext="Value"
datafield="Value"
itemstyle-width=35% />
<asp:boundfield headertext="Description"
datafield="description" />
</columns>
</asp:gridview>
</center>
</td></tr>
</table>
</form>
</center>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>