Click here to Skip to main content
16,018,664 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:
C#
<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>
Posted
Updated 17-Jul-13 20:06pm
v2
Comments
gatturamesh 18-Jul-13 1:52am    
please help me someone it is very urgent to me

1 solution

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
             }
          }
     }
}
 
Share this answer
 
Comments
gatturamesh 18-Jul-13 2:07am    
hi jaideepsinh ...
i had placed image button in a datalisty not in grid view
gatturamesh 18-Jul-13 2:17am    
what code i had to write in image button
jaideepsinh 18-Jul-13 2:22am    
Create Item data bound event in you data list.
<asp:DataList ID="DataList1" runat="server" OnItemCommand="DataList1_ItemCommand">

<asp:ImageButton ID="imbtn" runat="server" ImageUrl="~/images/animate.gif" ommandName="imgClick" />
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "imgClick")
{
//Your Code..
}
}
gatturamesh 18-Jul-13 3:02am    
if (e.CommandName == "imgClick")
{
//Your Code..
}

what i have ti write in that
jaideepsinh 18-Jul-13 3:19am    
Your code means what you want to do on image button click.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900