我在Datalist控件中有一个图像按钮,当我点击图像按钮时,文件应该下载我应该如何实现这个? [英] I have a imagebutton with in the Datalist control when i click on image button the file should download how should i implement this ?

查看:69
本文介绍了我在Datalist控件中有一个图像按钮,当我点击图像按钮时,文件应该下载我应该如何实现这个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中使用Datalist控件来显示数据,并且在datalist控件中使用一个图像按钮,如果我点击图像按钮关注文件应该下载。所以我想要代码如何强制这个。

In my project am using Datalist control to dispaly data and also am using one imagebutton with in the datalist control if i click on image button concern file should download.So i want the code how to impement this.

推荐答案

您可以使用数据列表中的项目数据绑定事件,并在此事件中使用查找控件来查找图像按钮。像这样:



protected void DataList_ItemDataBound(Object sender,DataListEventArgs e)

{

if(e。 Item.ItemType == ListItemType.Item)

{

GridViewRow row =(发送者为DataList).NamingContainer为GridViewRow;

if(row != null)

{

ImageButton img = row.FindControl(imbtn)as ImageButton;

if(img!= null)

{

//这里你可以为你的imgbutton做代码

}

}

}

}
You can use Item data bound event of data list and in this event use find control to find your image button. Like this:

protected void DataList_ItemDataBound(Object sender,DataListEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item)
{
GridViewRow row = (sender as DataList).NamingContainer as GridViewRow;
if (row != null)
{
ImageButton img = row.FindControl("imbtn") as ImageButton ;
if (img != null)
{
//Here you can do code for your imgbutton
}
}
}
}


这篇关于我在Datalist控件中有一个图像按钮,当我点击图像按钮时,文件应该下载我应该如何实现这个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆