我想顯示的ImageButton圖像URL的CSS點擊彈出然而,該事件不會得到所謂的轉讓ImageButton的點擊,並在CSS彈出顯示
我後面的代碼如下:
protected void Page_Load(object sender, EventArgs e)
{
uid = (string)Session["uid"];
api = (FacebookAPI)Session["Api"];
con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\FB\\App_Data\\Database.mdf;Integrated Security=True;User Instance=True");
con.Open();
string query = "SELECT [FB_Id],[Pic_square],[Name],[Profile_url],[Loc_city],[contact_email],[Affiliations],[Edu_Hist],[Work_Hist] FROM [User1] WHERE([FB_Id] IN (SELECT [FB_Id2] FROM [Connections] WHERE([FB_Id1] ='812534558') AND ([Connected] = 'True')))";
adapter = new SqlDataAdapter(query, con);
ds = new DataSet();
adapter.Fill(ds);
int count = ds.Tables[0].Rows.Count;
for (int i = 0; i < count; i++)
{
HtmlGenericControl listitem = new HtmlGenericControl("li");
HtmlGenericControl anchor = new HtmlGenericControl("a");
ImageButton im = new ImageButton();
im.ImageUrl = (string)ds.Tables[0].Rows[i].ItemArray[1];
im.ID = "image" + i;
im.Height = 80;
im.Width = 80;
//anchor.InnerHtml = fr.data[i].name;
anchor.Controls.Add(im);
anchor.Attributes.Add("href", "#lightbox-unlocked");
anchor.Attributes.Add("class", "open-popup");
anchor.Attributes.CssStyle.Add("div", "holder");
listitem.Controls.Add(anchor);
im.Click += new ImageClickEventHandler(im_Click); // not working
if (i <= 5)
{
list.Controls.Add(listitem);
Panel1.Controls.Add(list);
}
else if (5 < i && i <= 11)
{
list1.Controls.Add(listitem);
Panel2.Controls.Add(list1);
}
else if (11 < i && i<= 17)
{
list2.Controls.Add(listitem);
Panel3.Controls.Add(list2);
}
else if (17 < i && i <= 23)
{
list3.Controls.Add(listitem);
Panel4.Controls.Add(list3);
}
else
{
list4.Controls.Add(listitem);
Panel5.Controls.Add(list4);
}
}
protected void im_Click(object sender, ImageClickEventArgs e)
{
ImageButton im1 = (ImageButton)sender;
string i1 = im1.ID.Substring(im1.ID.Length - 1, 1);
Regex re = new Regex(@"\d+");
Match m = re.Match(im1.ID);
int j2 = Convert.ToInt16(m.Value);
int j1 = Convert.ToInt32(i1);
Image2.ImageUrl = (string)ds.Tables[0].Rows[j1].ItemArray[1];
}
保護無效im_Click(對象發件人,ImageClickEventArgs E) {} 我已經嘗試調試和它不拿出這一點 – 2012-04-03 11:55:24
,因爲你必須運行在頁面加載你創建代碼。 – 2012-04-03 11:59:04
它已經在Page_Load – 2012-04-03 12:01:34