-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tutorial.aspx.cs
145 lines (131 loc) · 5.23 KB
/
Tutorial.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Data.SqlClient;
using System.Data;
public partial class Tutorial : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GridView1.Visible = false;
if (!IsPostBack)
{
SqlConnection con;
using (con = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnStringDb"].ToString()))
{
SqlCommand cmd = new SqlCommand("Select Distinct UniversityName FROM Tutorial", con);
con.Open();
DropDownList1.DataSource = cmd.ExecuteReader();
DropDownList1.DataTextField = "UniversityName";
DropDownList1.DataValueField = "UniversityName";
DropDownList1.DataBind();
con.Close();
}
DropDownList1.Items.Insert(0, new ListItem("select", ""));
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList2.Items.Clear();
DropDownList3.Items.Clear();
SqlConnection con;
GridView1.Visible = false;
using (con = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnStringDb"].ToString()))
{
SqlCommand cmd = new SqlCommand("Select Distinct Department FROM Tutorial Where UniversityName='" + DropDownList1.SelectedItem.Value + "'", con);
con.Open();
DropDownList2.DataSource = cmd.ExecuteReader();
DropDownList2.DataTextField = "Department";
DropDownList2.DataValueField = "Department";
DropDownList2.DataBind();
con.Close();
}
if (!DropDownList2.SelectedItem.Text.Equals("select"))
{
DropDownList2.Items.Insert(0, new ListItem("select", ""));
DropDownList2.SelectedIndex = 0;
}
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList3.Items.Clear();
SqlConnection con;
using (con = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnStringDb"].ToString()))
{
SqlCommand cmd = new SqlCommand("Select Distinct Subject FROM Tutorial Where UniversityName='" + DropDownList1.SelectedItem.Value + "' AND Department='" + DropDownList2.SelectedItem.Value + "'", con);
con.Open();
DropDownList3.DataSource = cmd.ExecuteReader();
DropDownList3.DataTextField = "Subject";
DropDownList3.DataValueField = "Subject";
DropDownList3.DataBind();
con.Close();
}
if (!DropDownList3.SelectedItem.Text.Equals("select"))
{
DropDownList3.Items.Insert(0, new ListItem("select", ""));
DropDownList3.SelectedIndex = 0;
}
GridView1.Visible = false;
}
DataTable dtTutorial = new DataTable();
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
if (IsPostBack)
{
HiddenField1.Value = DropDownList1.SelectedValue;
HiddenField2.Value = DropDownList2.SelectedValue;
HiddenField3.Value = DropDownList3.SelectedValue;
}
GridView1.Visible = true;
SqlConnection con;
using (con = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnStringDb"].ToString()))
{
SqlCommand cmd = new SqlCommand("Select id,Topic,Description,link FROM Tutorial Where UniversityName='" + DropDownList1.SelectedItem.Value + "' AND Department='" + DropDownList2.SelectedItem.Value + "' AND Subject='" + DropDownList3.SelectedItem.Value + "'", con);
dtTutorial.Columns.Add("Topic");
dtTutorial.Columns.Add("Description");
dtTutorial.Columns.Add("Visit");
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
DataRow dr = dtTutorial.NewRow();
dr["Topic"] = rdr["Topic"];
dr["Description"] = rdr["Description"];
dr["Visit"] = rdr["id"];
dtTutorial.Rows.Add(dr);
}
con.Close();
}
GridView1.DataSource = dtTutorial;
GridView1.DataBind();
foreach (GridViewRow gr in GridView1.Rows)
{
HyperLink hp = new HyperLink();
hp.Text = "Click here";
hp.NavigateUrl = "~/Details.aspx?id=" + gr.Cells[2].Text;
gr.Cells[2].Controls.Add(hp);
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
Response.Write("<script>alert('hello')</script>");
GridView1.Visible = true;
GridView1.DataSource = dtTutorial;
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
BindData();
}
void BindData()
{
GridView1.DataSource = dtTutorial;
GridView1.DataBind();
}
protected void GridView1_PageIndexChanging1(object sender, GridViewPageEventArgs e)
{
Response.Write("<script>alert('hello')</script>");
}
}