使用者需求:在Repeater內使用CheckBox並且勾選時立即變更資料庫狀態。
<table>
<asp:repeater id="ContentRepeater" runat="server">
<ItemTemplate>
<tr>
<td>
<asp:Literal ID="ltContentId" runat="server"
Text='<%# DataBinder.Eval(Container, "DataItem.ContentId") %>'>
</asp:Literal>
</td>
<TD>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged='cbCoaching_OnCheckedChanged'/>
</td>
</tr>
</ItemTemplate>
</asp:repeater>
</table>
Protected Sub cbCoaching_OnCheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
'取得在repeater內的那一欄資料。
Dim chk As CheckBox = DirectCast(sender, CheckBox)
Dim item As RepeaterItem = DirectCast(chk.NamingContainer, RepeaterItem)
Dim ltContentId As Literal = DirectCast(item.FindControl("ltContentId"), Literal)
response.write ("ltContentId =" <ContentId & "<BR>")
End Sub
參考資料:
http://stackoverflow.com/questions/6997948/handling-the-checkedchanged-event-of-inner-repeater-checkbox-control-in-asp-net
http://stackoverflow.com/questions/25308247/how-to-get-the-repeater-item-in-a-checkbox-checkedchanged-event
0 意見: