是有可能的DataTable對象傳遞給另一個控制對象作爲參數作爲休耕:如何通過DataTable對象作爲參數傳遞給對象控制
protected void DropDownlist2(string model)
{
qureyString = "Select modelcar from useritem where [email protected]";
SqlCommand cmd = new SqlCommand(qureyString, useritemConnectionString1);
cmd.Parameters.AddWithValue("@model", model);
useritemConnectionString1.Open();
DataTable dt = new DataTable();
SqlDataAdapter ad = new SqlDataAdapter(cmd);
ad.Fill(dt);
if (dt.Rows.Count > 0)
{
DropDownList2.DataSource = dt;
DropDownList2.DataBind();
}
useritemConnectionString1.Close();
Button1(dt);
}
private void Button1_Click(DataTable dt)
{
SqlDataReader dr=cmd.ExecuteReader();
if(dr.HasRows)
{
while (dr.Read())
{
System.Web.UI.WebControls.Image imgControl = new System.Web.UI.WebControls.Image();
HtmlGenericControl paraContainer = new HtmlGenericControl("p");
paraContainer.Controls.Add(imgControl);
PlaceHolder1.Controls.Add(paraContainer);
//Get Image Information
imgControl.ImageUrl = dr["Image"].ToString();
}
}
else dr.Close();
}
}
由於某種原因,它給了我這個錯誤消息的button1_Click(System.data .datatable)由於其保護級別而不可訪問
即使你將其設爲'protected',你也不能將'DataTable'傳遞給click事件處理程序,因爲它的簽名是不同的('Object sender,Eventargs e)'。 –