I am using Data Repeater
and Link Button
inside repeater
. I want to change the color of clicked button
but it is not working . Here is my code.
<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);
}
Do this way. Create class for Current Page LinkButton
.Active
{
color:red;
font:bold 12px Tahoma;
}
Then Change the Repeater as following
<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>
<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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.