DataGrid里面的模板列中放的图片控件,怎么触发javascript写的事件啊?? 我想让那个图片当鼠标移上去的时候换成另外一张,怎么做啊,谢谢大家指点,我是新手 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 this.Image1.Attributes.Add("onmouseover","xx(this)");<script>function xx(varImage){ varImage.src = " ../images/b2.jpg";}</script> 在datagrid的ItemDataBound事件中给图片绑定事件 this.Image1.Attributes.Add("onmouseover","xx(this)");<script>function xx(varImage){ varImage.src = " ../b2.jpg";}</script>这样就可以了啊 建议在datagrid的ItemCreated事件中添加JS事件(Image) img = (Image)e.Item.findcontrol("Image1");img.ImageUrl = 1.gif;img.Attributes.add("onmouseover", "this.src=2.gif");img.attributes.add("onmouseout", "this.src=1.gif"); this.Image1.Attributes.Add("onmouseover","xx(this)");这句放在cs文件的pageload事件里面不可以吗?我运行了怎么报错了:异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 行 25: private void Page_Load(object sender, System.EventArgs e)行 26: {行 27: this.Image1.Attributes.Add("onmouseover","changepic(this.Image1)");行 28: // string myConnection=System.Configuration.ConfigurationSettings.AppSettings["connString"]; 用上面的方法的话,你要用FindControl先把图片找出来或者你可以直接在HTML代码的模版列中,给<IMG>对象加上Javascript也可以的 它说img在类或者命名空间中不存在 (Image) img = (Image)e.Item.findcontrol("Image1");img.ImageUrl = 1.gif;img.Attributes.add("onmouseover", "this.src=2.gif");img.attributes.add("onmouseout", "this.src=1.gif"); 为什么我在itemcreat事件里面用findcontrol会找不到image1这个控件 简单:private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { TableCell cell = e.Item.Cells[e.Item.Cells.Count-1]; Image img= (Image)(cell.Controls[0]); img.Attributes.Add("onclick", "click()"); } }e.Item.Cells[e.Item.Cells.Count-1]:-1代表最后表格最后一列;-2表示倒数第二列或e.Item.Cells[列数] 用<img onmouseover="this.src=图片地址" onmouseover="this.src=另一图片地址">多好啊,能不能服务器控件就不用服务器控件。 不可以用html标签代替的,因为要写事件的 控件放在datagrid里面的话,用findcontrol找不到这个控件,为什么啊,因为datagrid里面有多条记录的原因??? Image img= (Image)(cell.Controls[0]);这句报错,说转换无效 正则表达式如何提取地址中的省市??? 按钮操作前如何提示是否确认? ~~急呀!马上给分;;;》》 http如何自动跳转至https 《〈 FormsAuthentication.RedirectFromLoginPage(userId, false) !!!有人知道么 !!! 关于MYSQL语句问题?请高手指点! 请教一个问题,ADO.NET 关于使用jquery ajax 请求 session的问题[问题解决了,进来的就给分] 关于浏览器的自定义工具栏的问题(2)! 连接数据库的错误- 如何让datagrid数据列的颜色交替变化 在asp.net 中可以使用picturebox吗?
<script>
function xx(varImage)
{
varImage.src = " ../images/b2.jpg";
}
</script>
<script>
function xx(varImage)
{
varImage.src = " ../b2.jpg";
}
</script>
这样就可以了啊
(Image) img = (Image)e.Item.findcontrol("Image1");
img.ImageUrl = 1.gif;
img.Attributes.add("onmouseover", "this.src=2.gif");
img.attributes.add("onmouseout", "this.src=1.gif");
行 25: private void Page_Load(object sender, System.EventArgs e)
行 26: {
行 27: this.Image1.Attributes.Add("onmouseover","changepic(this.Image1)");
行 28: // string myConnection=System.Configuration.ConfigurationSettings.AppSettings["connString"];
或者你可以直接在HTML代码的模版列中,给<IMG>对象加上Javascript也可以的
img.ImageUrl = 1.gif;
img.Attributes.add("onmouseover", "this.src=2.gif");
img.attributes.add("onmouseout", "this.src=1.gif");
private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
TableCell cell = e.Item.Cells[e.Item.Cells.Count-1];
Image img= (Image)(cell.Controls[0]);
img.Attributes.Add("onclick", "click()");
}
}
e.Item.Cells[e.Item.Cells.Count-1]:
-1代表最后表格最后一列;
-2表示倒数第二列
或e.Item.Cells[列数]
这句报错,说转换无效