datalist中的图像按钮 [英] image button in datalist

查看:62
本文介绍了datalist中的图像按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨gud mng all,

我在datalist转发器中放置了一个图像按钮如何在cs中生成一个图像按钮,当我点击该按钮时我必须下载一个文件。这里是我的设计页面代码:

< asp:DataList ID =   DataList1 runat =   server Width =   800 >  
< itemtemplate>
< table border = 0 cellspacing = 2 cellpadding = 3 width = 690 align = left >
< tr>
< td class = tabledata1 width = 150>文件名:
< / td >
< td class = tabledata0 colspan = 2>< asp:Label ID = Label1 runat = server Text = ' <%#Eval(FileName)%>' < span class =code-keyword>> < / td >
< / tr >
< tr>
< td class = tabledata1 width = 150>说明 < / td >
< td class = tabledata0 colspan = 2 >
< asp:Label ID = Label2 runat = server Text = ' <%#Eval(说明)%>' > < / td >
< / tr >
< tr>
< td class = tabledata1 width = 150>下载种子:< / td >
< td class = tabledata0 colspan = 2> < / td >
< / tr >
< tr>
< td>
将ASP:ImageButton的ID = <跨度类= 代码串> <跨度类= 代码串 > imbtn RUNAT = <跨度类=代码-string>
server ImageUrl = 〜/ images / animate.gif ImageAlign = 中间 />
<% - onclick = imbtn_Click - %>
< / td >
< / tr < span class =code-keyword>>

< / table >
< / itemtemplate >

解决方案

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



保护无效DataList_ItemDataBound(对象发件人,DataListEventArgs E)
{
如果(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)
{
//这里你可以为你的imgbutton做代码
}
}
}
}


hi gud mng all ,
I had placed a image button in a datalist repeater how to generate a that image button in cs and when i click on that button i had to download a file.Here is my design page code:

<asp:DataList ID="DataList1" runat="server" Width="800">
<itemtemplate>
<table border="0" cellspacing="2" cellpadding="3" width="690" align="left">
<tr>
<td class="tabledata1" width="150">File Name:
</td>
<td class="tabledata0" colspan="2"><asp:Label ID="Label1" runat="server" Text='<%#Eval("FileName")%>'></td>
</tr>
<tr>
<td class="tabledata1" width="150">Description</td>
<td class="tabledata0" colspan="2">
<asp:Label ID="Label2" runat="server" Text='<%#Eval("Description") %>'></td>
</tr>
<tr>
<td class="tabledata1" width="150">Download torrent:</td>
<td class="tabledata0" colspan="2"</td>
</tr>
<tr>
<td>
<asp:ImageButton ID="imbtn" runat="server" ImageUrl="~/images/animate.gif" ImageAlign="Middle"  /> 
<%-- onclick="imbtn_Click"--%>
</td>
</tr>
</table>
</itemtemplate>

解决方案

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天全站免登陆