读书人

,怎么给动态生成的图片控件做链接?

发布时间: 2012-01-14 20:02:35 作者: rapoo

求助,如何给动态生成的图片控件做链接??
绑定数据函数
(1)
private void BindFileDown()
{
for(...)
{
ds.Tables[0].Rows[i][ "PictureName "] = " <a title= ' " + FileSize + " ' href= '# ' onclick=\ "javascript:popWindows( '../../DLPicture.aspx? " + Constant.Query_DownloadRefNum + "= " + ds.Tables[0].Rows[i][ "DocID "].ToString() + " ')\ "> <img width=80 height=60 border=0 src= '../../DLPicture.aspx? " + Constant.Query_DownloadRefNum + "= " + ds.Tables[0].Rows[i][ "DocID "].ToString() + " ' /> </a> "; ---> 这行读取图片到img 在链接图片,点击可以打开图片
}
A.DataSource = ds;
A.DataBind();
}

若是这样图片能正常读出.

(2)
private void A_ItemDataBound(...)
{

e.Item.Cells[9].Text = " <div id=Confid " + key + " > " + e.Item.Cells[9].Text + " </div> " + tempDdl;

....
HtmlInputFile Picture=new HtmlInputFile();//Picture
Picture.Style.Add( "display ", "none ");
Picture.Style.Add( "width ", "150 ");
Picture.ID= "Picture " + key;
e.Item.Cells[12].Controls.Add(Picture); --> 想实现当点更改时,可以更改图片,但增加这几句后,图片就不能读取,DataGrid的PictureName列为空,为何会是这样?
前面不是梆定了吗?
}

(3)
private void A_ItemDataBound(...)
{
...
也可在这重新读图片
HtmlImage im=new HtmlImage();
im.Style.Add( "width ", "80 ");
im.Style.Add( "height ", "60 ");
im.Style.Add( "border ", "0 ");
im.Src= "../../DLPicture.aspx? " + Constant.Query_DownloadRefNum + "= " + ds.Tables[0].Rows[e.Item.ItemIndex][ "DocID "].ToString();
e.Item.Cells[12].Controls.Add(im);//add

但我怎样对im图片控件 做链接??
" <a title= ' " + FileSize + " ' href= '# ' onclick=\ "javascript:popWindows( '../../DLPicture.aspx? " + Constant.Query_DownloadRefNum + "= " + ds.Tables[0].Rows[i][ "DocID "].ToString() + " ')\ "> 这句怎样加上去?

}
麻烦各位达人,出出策,谢谢~~


[解决办法]
把添加图片那里修改,Lable Lb = new Lable();
Lb.Text = " <a title= ' " + FileSize + " ' href= '# ' onclick=\ "javascript:popWindows( '../../DLPicture.aspx? " + Constant.Query_DownloadRefNum + "= " + ds.Tables[0].Rows[i][ "DocID "].ToString() + " ')\ "> <img src=\ "../../DLPicture.aspx? " + Constant.Query_DownloadRefNum + "= " + ds.Tables[0].Rows[e.Item.ItemIndex][ "DocID "].ToString();+ " </a> ";


e.Item.Cells[12].Controls.Add(Lb);

或者
e.Item.Cells[12].Text = " <a title= ' " + FileSize + " ' href= '# ' onclick=\ "javascript:popWindows( '../../DLPicture.aspx? " + Constant.Query_DownloadRefNum + "= " + ds.Tables[0].Rows[i][ "DocID "].ToString() + " ')\ "> <img src=\ "../../DLPicture.aspx? " + Constant.Query_DownloadRefNum + "= " + ds.Tables[0].Rows[e.Item.ItemIndex][ "DocID "].ToString();+ " </a> ";

即直接把Html代码写入到列上就OK了,//一上字符串是把你的拿来临时拼凑的,本人不保证不报错,不过方法应该已经表达清楚了吧-。-

读书人网 >asp.net

热点推荐