選擇例子
前端代碼:
<asp:ListView ID="ListView1" runat="server"
onselectedindexchanging="ListView1_SelectedIndexChanging">
<LayoutTemplate>
<table id="Table1" runat="server" border="0" style="">
<tr runat="server" id="itemPlaceholder" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<%#Eval("ID") %>
</td>
<td>
<asp:Label ID="idLabel" runat="server" Text='<%# Eval("name") %>' />
</td>
<td>
<asp:Label ID="xLabel" runat="server" Text='<%# Eval("age") %>' />
</td>
<td>
<asp:Button ID="SelectButton" CommandName="Select" runat="server" Text="選擇" />
</td>
</tr>
</ItemTemplate>
<SelectedItemTemplate>
<tr style="background-color:Blue">
<td>
<%#Eval("ID") %>
</td>
<td>
<asp:Label ID="idLabel" runat="server" Text='<%# Eval("name") %>' />
</td>
<td>
<asp:Label ID="xLabel" runat="server" Text='<%# Eval("age") %>' />
</td>
<td>
<asp:Button ID="SelectButton" CommandName="Select" runat="server" Text="選擇" />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
後台代碼:
protected void ListView1_SelectedIndexChanging(object sender, ListViewSelectEventArgs e)
{
ListView1.SelectedIndex = e.NewSelectedIndex;
Bind();
}