Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

SearchResults changed

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

0 comments on commit 1bbcb56

Please sign in to comment.
Something went wrong with that request. Please try again.