我在Data Repeater
内使用Link Button
和repeater
。我想更改点击button
的颜色,但它不起作用。这是我的代码。
<asp:Repeater ID="rptPager" runat="server">
<ItemTemplate>
<asp:LinkButton Font-Size="Larger" BackColor="Orange" ForeColor="White" ID="lnkPage" runat="server" Text='<%#Eval("Text") %>' CommandArgument='<%# Eval("Value") %>'
CssClass=" btn"
OnClick="Page_Changed"></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
protected void Page_Changed(object sender, EventArgs e)
{
int pageIndex = int.Parse((sender as LinkButton).CommandArgument);
LinkButton lnk = (LinkButton)sender;
lnk.ForeColor = System.Drawing.Color.Red;
lnk.BackColor = System.Drawing.Color.Red;
this.GetImagesPageWise(pageIndex);
}
答案 0 :(得分:0)
这样做。为Current Page LinkButton创建类
.Active
{
color:red;
font:bold 12px Tahoma;
}
然后按以下步骤更改Repeater
<asp:Repeater ID="rptPager" runat="server">
<ItemTemplate>
<asp:LinkButton ID="lnkPage" runat="server" Text='<%#Eval("Text") %>' CommandArgument='<%# Eval("Value") %>'
Enabled='<%# Eval("Enabled") %>' OnClick="Page_Changed" CssClass='<%# Convert.ToBoolean(Eval("Enabled")) == true ? "LBR" : "Active" %>'></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
答案 1 :(得分:0)
<ul class="pagination">
<asp:Repeater ID="rptPager" runat="server">
<ItemTemplate>
<li class="<%#GetStatus(Eval("Enabled").ToString(),Eval("Text").ToString())%>">
<asp:LinkButton ID="lnkPage" runat="server" Text='<%#Eval("Text") %>' CommandArgument='<%# Eval("Value") %>'
Enabled='<%# Eval("Enabled") %>' OnClick="Page_Changed">
</asp:LinkButton>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
Protected Function GetStatus(ByVal Enable As Boolean, ByVal linkName As String) As String
Try
If Enable = 0 And linkName <> "First" And linkName <> "Last" Then
Return "active"
Else
Return ""
End If
Catch ex As Exception
Return ""
End Try
End Function