Click here to Skip to main content
15,880,543 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anyone tell me how to use button and images in link view control in microsoft visual studio 2010. i am unable to write c# code that has to be executed on button click. i have labels in the linkview control but i am unable to access them in page load function. i dont know why. god bless you.please help me.
Posted
Comments
Paulo Augusto Kunzel 26-Sep-13 13:00pm    
Could you show some examples of the problem?
faizel s 26-Sep-13 13:42pm    
i cant really show you the problem but i will tell you in detail about the problem.i wrote following html code for listview control
<asp:ListView ID="ListView2" runat="server"
onselectedindexchanged="ListView2_SelectedIndexChanged">
<layouttemplate>
<table style="position:relative;left:-100px;width:1200px; cellspacing="0" cellpadding="3" rules="all">
<tr style="background-color:Blue; color: White;">
<th style="font-family:Tahoma;">ITEM NAME</th>
<th></th>
<th style="width:135px">LOCATION</th>
<th>ID</th>
</tr>
<tbody>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</tbody>
</table>

<itemtemplate>
<tr>
<td>

<asp:Image ID="Image1" runat="server" ImageUrl='' /></td>
<td>
<asp:Label ID="Label1" runat="server" Text=<%# Eval("heading")%> Font-Underline="True"><br />
<asp:Label ID="Label2" runat="server" Text=<%# Eval("description") %>></td>
<td>
<asp:Label ID="Label3" runat="server" Text=<%# Eval("location") %>></td>
<td>
<asp:Label ID="Label4" runat="server" Text=<%# Eval("pop_id") %>></td>
<td>
 <asp:Button ID="Button1" runat="server" Text="Click Here For More" OnClientClick="openwindow()"/></td>
</tr>


here you can see i used labels and buttons.My problem is that i could'nt write button click function for the button in my aspx.cs page.Also i could'nt access label by label id in that page.Hope you understand what i am saying god bless you.

Use FindControl to access the labels inside the listview

protected void ListView_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
var lbl = e.Item.FindControl("Label1") as Label;
}
}

If you dont want to use the findcontrol method check the below link

http://blogs.msdn.com/b/scothu/archive/2008/03/26/accessing-controls-in-listview-templates.aspx[^]

Hope this helps
 
Share this answer
 
you cab use inbuilt control image button.
 
Share this answer
 

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