朋友们,我想更改单击按钮(asp.net)中的标签div的类,但该div位于转发器内,我怎样才能找到它?并换班级? 实际上,我想更改引导列类。 希望我已经很好地表达了意思,谢谢大家。
当然,假设这个标记:
<style>
.myhighlight {
background-color:lightblue;
font:bold;
}
</style>
<h3>Hotels</h3>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:HiddenField ID="hPK" runat="server"
Value='<%# Eval("ID") %>'
/>
<div id="mystylediv" runat="server">
<div style="float: left; width: 30%">
<asp:Label ID="lblHotelName" runat="server"
Text='<%# Eval("HotelName") %>'
Font-Size="X-Large">
</asp:Label>
<br />
<asp:Label ID="lblDescription" runat="server"
Text='<%# Eval("Description") %>'>
</asp:Label>
</div>
<div style="float: left">
<asp:Button ID="cmdSel" runat="server"
Text="Select"
CssClass="btn"
OnClick="cmdSel_Click" />
</div>
<div style="clear: both">
</div>
<hr />
</div>
</ItemTemplate>
</asp:Repeater>
因此,对于单行按钮单击,我们有以下代码:
Protected Sub cmdSel_Click(sender As Object, e As EventArgs)
Dim btn As Button = sender
Dim rRow As RepeaterItem = btn.NamingContainer
Dim hPK As HiddenField = rRow.FindControl("hPK")
Dim intPK As Integer = hPK.Value
Session("RowPK") = intPK ' save row selected database PK for later
Dim MyDiv As HtmlControl = rRow.FindControl("mystylediv")
MyDiv.Attributes.Add("class", "myhighlight")
End Sub
因此,当页面加载并单击该行的按钮时,我们会看到: