I have a listview in asp.net like this:
<asp:ListView ID="lvLoads" DataKeyNames="BookingId" OnItemCommand="lvLoads_OnItemCommand" runat="server">
<EmptyDataTemplate>
<table>
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<GroupTemplate>
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</GroupTemplate>
<ItemTemplate>
<fieldset>
<table class="table table-striped table-responsive">
<thead>
<tr class="hidden-lg">
<th width="15%">Type</th>
<th width="31%">Details</th>
<th width="25%">Distance/Duration</th>
<th width="21%"> </th>
</tr>
</thead>
<tbody>
<tr>
<td width="15%">
<asp:Label CssClass="hide" ID="lblBokingId" runat="server"><%# Eval("BookingId") %></asp:Label>
<asp:Label ID="lblLoadTypeName" runat="server"> <%# Eval("LoadTypeName") %></asp:Label>
<br>
</td>
<td width="21%">
<asp:LinkButton ID="btnViewMore" CssClass="btn btn-warning" CommandName="ViewMore" runat="server">View More</asp:LinkButton>
</td>
</tr>
</tbody>
</table>
</fieldset>
</ItemTemplate>
</asp:ListView>
Now on click of the button ViewMore i wrote this code to extract listviewItem's value:
var id = ((Label)e.Item.FindControl("lblBookingId")).Text;
var name = ((Label)e.Item.FindControl("lblLoadTypeName")).Text;
But e.Item.FindControl("lblBookingId")
always comes null. I checked the page's html by using inspect element of chrome, and i was shocked to see that my id somehow got changed to ContentSection_ctl00_lblLoadTypeName_0
I am really stuck at this. Please help me. Thanx in Advance