So I had have a table populating with data but I was wondering how I could pass two bits of data from a row depending on which link at the end of the row is clicked.
<%WebReceiptSummary[] receipts = GetReceipts();
if (receipts != null)
{
for (int i = 0; i < receipts.Length; i++)
{%>
<tr>
<td><%= receipts[i].Type%></td>
<td><%= receipts[i].PolicyNo%></td>
<td><%= receipts[i].Date%></td>
<td class="c"><%= receipts[i].Amount%></td>
<td class="r"><asp:LinkButton OnCommand="PDFLinkClick"
CommandArgument="<%= receipts[i].PDF %>&<% receipts[i].PolicyNo %>" runat="server">View PDF</asp:LinkButton></td>
</tr>
<% }
}
%>
Obviously my CommandArgument just passes back the string <%= receipts[i].PDF %>&<% receipts[i].PolicyNo %> not the values. What would be the best way of doing this? I was also thinking of using;
<asp:HiddenField ID="hiddenIsCaptchaReadyValidate" runat="server" Value=false/>
But I have the same problem here where the value is placed within quotes and also it means I need to create two hiddenfields for ever row which isn’t the most efficient way of doing this. Thoughts?
It is not possible to have
<%= %>commands as part of an attribute when added via the mark-up.Can I recommend that instead of using the
forloop in the ASPX, you instead use the<asp:Repeater>control? This will also allow you to set theCommandAttributevalue from the code-behind.An example…
In your Init or Load in code behind…
Then…
UPDATE
Thinking about it, rather than using the code-behind setting of the
CommandArgument, I think (I haven’t tested this yet) you could actually do the following without needing thereceipts_ItemDataBoundfunction…UPDATE 2
All instances of
Container.DataItemin the above examples, have been changed into the tight-bound((WebReceiptSummary)Container.DataItem)