c# - Get Repeater Label in the current "row" being accessed -
i have following repeater:
<asp:repeater id="rptleaverequests" runat="server" onitemdatabound="rptleaverequests_itemdatabound"> <itemtemplate> <table id="tableitem" runat="server"> <tr> <td style="width: 100px;"> <asp:label id="lbldate" runat="server" text='<%#eval("date", "{0:dd/m/yyyy}") %>'></asp:label> </td> <td style="width: 100px;"> <asp:label id="lblhours" runat="server" text='<%#eval("hours") %>'></asp:label> </td> <td style="width: 200px;"> <asp:label id="lblperiod" runat="server" text='<%#eval("amorpm") %>'></asp:label> </td> <td style="width: 200px; font-size:10px;"> <asp:label id="lblnote" runat="server" text='<%#eval("note") %>'></asp:label> </td> <td style="50px"> <asp:radiobuttonlist id="rbtverified" runat="server" > <asp:listitem value="1">accept</asp:listitem> <asp:listitem value="2">reject</asp:listitem> </asp:radiobuttonlist> </td> <td> <asp:textbox id="txtnotes" runat="server" ></asp:textbox> </td> </tr> </table>
i trying data in each label (ex: convert.tostring((label)item.findcontrol("date")) ) returning empty string, doing wrong:
foreach (repeateritem item in rptleaverequests.items) { var rdblist = item.findcontrol("rbtverified") radiobuttonlist; switch (rdblist.selectedvalue) { case "1": if (new leavelogic().addleaveemployee(convert.tostring((label)item.findcontrol("date")), convert.todouble((label)item.findcontrol("hours")), convert.tostring((label)item.findcontrol("amorpm")), "vacational leave", convert.toint32(context.user.identity.name), convert.tostring((label)item.findcontrol("note"))) { response.redirect(request.rawurl); } break;
i believe it's not working because aren't finding controls. findcontrol
return null if can't find control, , convert.tostring
return empty string if object value null.
from can see, searching wrong string id. instead of date
, should lbldate
.
if in debug build mode, keep in mind asp.net loves change control names @ runtime, "lbldate" control might not "lbldate". can try debugging on browser , inspect elements' ids actual ids.
also, want instead if want label's actual data (notice .text
):
((label)item.findcontrol("lbldate")).text
Comments
Post a Comment