在以下代碼中,asp不會輸入動作偵聽器(Button1_Click)。 任何人都可以幫忙嗎?事件處理程序不會被調用
protected void Project_Click(object sender, EventArgs e)
{
Courses.ActiveViewIndex = 0;
String ConnStr = ConfigurationManager.ConnectionStrings["MyRuMoR"].ToString();
SqlConnection conn = new SqlConnection(ConnStr);
conn.Open();
SqlCommand cmd = new SqlCommand("ViewProjects", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@course_code", "PHYS305");
SqlDataReader rdr = cmd.ExecuteReader();
int c = 1;
while (rdr.Read())
{
String name = rdr.GetString(rdr.GetOrdinal("name"));
int p_id = rdr.GetInt32(rdr.GetOrdinal("p_id"));
LinkButton lb = new LinkButton();
lb.ID = p_id.ToString();
lb.Text = "Project " + c + " is: " + name;
form1.Controls.Add(lb);
lb.Click += new EventHandler(this.Button1_Click);
c++;
}
conn.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("Hello");
}
你的意思是事件處理程序。動作偵聽器是一個Java概念。 – Oded 2011-12-25 12:24:14
你最好改變你的邏輯,改用Repeater,在'Project_Click'方法中綁定它的數據源。 – 2011-12-25 12:28:05