在ASP.NET中显示链接按钮组中的选定链接按钮,可以使用以下步骤:
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">LinkButton 1</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" OnClick="LinkButton2_Click">LinkButton 2</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" OnClick="LinkButton3_Click">LinkButton 3</asp:LinkButton>
protected void LinkButton1_Click(object sender, EventArgs e)
{
// 处理链接按钮1的点击事件
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
// 处理链接按钮2的点击事件
}
protected void LinkButton3_Click(object sender, EventArgs e)
{
// 处理链接按钮3的点击事件
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
// 设置链接按钮1的样式为选定
LinkButton1.CssClass = "selected";
// 设置其他链接按钮的样式为未选定
LinkButton2.CssClass = "";
LinkButton3.CssClass = "";
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
// 设置链接按钮2的样式为选定
LinkButton2.CssClass = "selected";
// 设置其他链接按钮的样式为未选定
LinkButton1.CssClass = "";
LinkButton3.CssClass = "";
}
protected void LinkButton3_Click(object sender, EventArgs e)
{
// 设置链接按钮3的样式为选定
LinkButton3.CssClass = "selected";
// 设置其他链接按钮的样式为未选定
LinkButton1.CssClass = "";
LinkButton2.CssClass = "";
}
.selected {
background-color: #007bff;
color: #fff;
}
</style>
这样,当用户点击某个链接按钮时,该链接按钮将被选定,其他链接按钮将取消选定。
领取专属 10元无门槛券
手把手带您无忧上云