Permalink
Browse files

SearchResults changed

  • Loading branch information...
1 parent 6ca3046 commit 1bbcb5633629070f6aa56105c54cae98bf9a5f17 @ArtisOracle committed Apr 9, 2012
View
BIN StudentAlumniTrackingTool/StudentAlumniTrackingTool.suo
Binary file not shown.
View
1 StudentAlumniTrackingTool/StudentAlumniTrackingTool/WebPages/Error.aspx
@@ -7,6 +7,7 @@
<p>
There has been an error. It most likely means you were not allowed to do something you were trying to do.
</p>
+<asp:Label CssClass="failureNotification" runat="server" ID = "ErrorSource"></asp:Label>
<p>
<a href="../Default.aspx">Return home</a>
</p>
View
3 StudentAlumniTrackingTool/StudentAlumniTrackingTool/WebPages/Error.aspx.cs
@@ -12,7 +12,8 @@ public partial class Error : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
-
+ // Set error text of reasoning of what may have happened.
+ ErrorSource.Text = Request.ServerVariables["ErrorOccured"];
}
}
}
View
9 StudentAlumniTrackingTool/StudentAlumniTrackingTool/WebPages/Error.aspx.designer.cs
@@ -11,5 +11,14 @@ namespace StudentAlumniTrackingTool.WebPages {
public partial class Error {
+
+ /// <summary>
+ /// ErrorSource control.
+ /// </summary>
+ /// <remarks>
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ /// </remarks>
+ protected global::System.Web.UI.WebControls.Label ErrorSource;
}
}
View
22 StudentAlumniTrackingTool/StudentAlumniTrackingTool/WebPages/SearchResults.aspx
@@ -13,28 +13,28 @@
AutoGenerateColumns = "False" DataSourceID = "SqlDataSource1"
Width="100%" onselectedindexchanged="ResultsGridView_SelectedIndexChanged">
<Columns>
- <asp:BoundField DataField = "LastName" HeaderText = "Last Name" SortExpression = "LastName" />
- <asp:TemplateField HeaderText = "First Name">
- <ItemTemplate>
+ <asp:BoundField DataField = "Lastname" HeaderText = "Last Name" SortExpression = "LastName" />
+ <asp:BoundField DataField = "Firstname" HeaderText = "First Name" SortExpression = "FirstName" />
+ <asp:BoundField DataField = "Education" HeaderText = "Education" SortExpression = "Education" />
+ <%--<asp:TemplateField HeaderText = "First Name">
+ <ItemTemplate>
<asp:LinkButton ID = "LinkName" runat = "server"
- Text='<%# Eval("Email") %>'
- PostBackUrl = '<%"~/WebPages/Profile.aspx?name="+Eval("Email") %>'> </asp:LinkButton>
- </ItemTemplate>
- </asp:TemplateField>
+ Text='<%# Eval("Email") %>'> </asp:LinkButton>
+ </ItemTemplate>
+ </asp:TemplateField>--%>
+ <%--Education --%>
<asp:BoundField DataField = "Education" HeaderText = "Education" SortExpression = "Education" />
<asp:TemplateField HeaderText="Edit" ControlStyle-Width = "25px" >
<ItemTemplate>
- <asp:LinkButton ID = "EditImageLink" runat = "server"
- PostBackUrl = '<%"~/WebPages/Edit.aspx?name="+Eval("Email") %>' >
+ <asp:LinkButton ID = "EditImageLink" runat = "server" >
<asp:Image AlternateText = "Edit" ImageUrl = "~/Images/pencil.gif" runat = "server" />
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete" ControlStyle-Width="25px">
<ItemTemplate>
- <asp:LinkButton ID = "DeleteImageLink" runat = "server"
- PostBackUrl = '<%"~/WebPages/Delete.aspx?name="+Eval("Email") %>' >
+ <asp:LinkButton ID = "DeleteImageLink" runat = "server" >
<asp:Image ID = "DeleteImg" AlternateText = "Delete" ImageUrl = "~/Images/delete.gif" runat = "server" />
</asp:LinkButton>
</ItemTemplate>
View
42 StudentAlumniTrackingTool/StudentAlumniTrackingTool/WebPages/SearchResults.aspx.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
@@ -12,8 +13,9 @@ public partial class SearchResults : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
+ // Make sure our query has content, if it does not, we don't search for anything
int count = 0;
- string queryString = Request.ServerVariables["SearchQuery"];
+ string queryString = Request.ServerVariables["SearchQuery"]; // session var from Search
if (queryString == null)
{
NoResultsPanel.Visible = true;
@@ -23,7 +25,43 @@ protected void Page_Load(object sender, EventArgs e)
{
ResultsPanel.Visible = true;
- SqlDataSource1.ConnectionString = null;
+ SqlDataSource1.ConnectionString = null;
+
+ }
+ // Take the query string as a session var "passed in" from Search and run it
+ // First gather connection string
+ string connectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
+ SqlCommand sqlCom = new SqlCommand(queryString);
+ SqlConnection sqlConn = new SqlConnection(connectionString);
+
+ // Try running the command
+
+ try {
+ sqlCom = new SqlCommand("SELECT ");
+ // The variables in the DataGrid NEED to be identical to what is in the SQL query
+ sqlConn = new SqlConnection(connectionString);
+ sqlConn.Open();
+
+ /*
+ * Bind the datasource of the GridView on this SearchResults.aspx page to the
+ * results generated by running this query.
+ */
+
+ // Execute SQL
+ ResultsGridView.DataSource = sqlCom.ExecuteReader();
+
+ // Bind
+ ResultsGridView.DataBind();
+ }
+
+ catch (Exception ex) {
+ Response.Redirect("Error.aspx");
+ Session["ErrorOccured"] = ex.ToString();
+ }
+ finally {
+ // Close and dispose (hey, that rhymed!)
+ sqlConn.Close();
+ sqlCom.Dispose();
}
}

0 comments on commit 1bbcb56

Please sign in to comment.