当任何数据寻呼机事件发生时,链接按钮会改变颜色

发布于 2024-09-14 07:38:52 字数 1793 浏览 3 评论 0原文

我有一个字母过滤器,由 26 个动态创建的链接按钮组成,在选择任何链接按钮时,它会根据字母表过滤用户的姓名,并将其颜色更改为橙​​色,以使其与其他链接按钮不同,它工作正常,但如果有更多数量的用户与特定字母表关联,并且在应用过滤器时,它会根据该字母表过滤用户,并在单击数据分页器下一页或任何其他页码时将其显示在列表视图中,链接按钮将其颜色更改为默认颜色,但我想保持突出显示,直到并且除非选择其他链接按钮 我的代码

protected void Page_Init(object sender, EventArgs e)
    {
        // Adding Dynamically linkbuttons for all alphabets(i.e. A-Z)
        for (char asciiValue = 'A'; asciiValue <= 'Z'; asciiValue++)
        {
            LinkButton lbtnCharacter = new LinkButton();
            lbtnCharacter.ID = "lbtnCharacter" + asciiValue;
            divAlphabets.Controls.Add(lbtnCharacter);

            // Setting the properties of dynamically created Linkbutton.
            lbtnCharacter.Text = Convert.ToString(asciiValue);
            lbtnCharacter.CssClass = "firstCharacter";
            lbtnCharacter.ToolTip = "Show Tags starting with '" + Convert.ToString(asciiValue) + "'";
            lbtnCharacter.CommandArgument = Convert.ToString(asciiValue);
            lbtnCharacter.Command += new CommandEventHandler(lbtnCharacter_Command);
        }
    }



// For assigning default color to linkbutton text in page load
        foreach (var ctrl in divAlphabets.Controls)
        {
            if (ctrl is LinkButton)
            ((LinkButton)ctrl).CssClass = "firstCharacter";
        }

void lbtnCharacter_Command(object sender, CommandEventArgs e)
        {
            // Storing the values of pressed alphabet in viewstate.
            ViewState["Selected_Character"] = e.CommandArgument;
            LinkButton lbtnSelected = (LinkButton)divAlphabets.FindControl("lbtnCharacter" + e.CommandArgument);
            lbtnSelected.CssClass = "firstCharacter highlighted";
            txtTagFilter.Text = string.Empty;

            BindTagList();
        }

i have a alphabetic filter consist of 26 dynamically created link button on selecting any link button it is filtering the name of user's on the basis of alphabet and changing its color to orange to make it different from other linkbuttons it is working fine but if there are more number of user associated with a particular alphabet and on applying filter it is filtering the user on the basis of that alphabet and showing them in a list view on clicking the data pager next page or any other page number the link button changes its color to default color but i want to keep that highlighted until and unless other link button is selected
my code

protected void Page_Init(object sender, EventArgs e)
    {
        // Adding Dynamically linkbuttons for all alphabets(i.e. A-Z)
        for (char asciiValue = 'A'; asciiValue <= 'Z'; asciiValue++)
        {
            LinkButton lbtnCharacter = new LinkButton();
            lbtnCharacter.ID = "lbtnCharacter" + asciiValue;
            divAlphabets.Controls.Add(lbtnCharacter);

            // Setting the properties of dynamically created Linkbutton.
            lbtnCharacter.Text = Convert.ToString(asciiValue);
            lbtnCharacter.CssClass = "firstCharacter";
            lbtnCharacter.ToolTip = "Show Tags starting with '" + Convert.ToString(asciiValue) + "'";
            lbtnCharacter.CommandArgument = Convert.ToString(asciiValue);
            lbtnCharacter.Command += new CommandEventHandler(lbtnCharacter_Command);
        }
    }



// For assigning default color to linkbutton text in page load
        foreach (var ctrl in divAlphabets.Controls)
        {
            if (ctrl is LinkButton)
            ((LinkButton)ctrl).CssClass = "firstCharacter";
        }

void lbtnCharacter_Command(object sender, CommandEventArgs e)
        {
            // Storing the values of pressed alphabet in viewstate.
            ViewState["Selected_Character"] = e.CommandArgument;
            LinkButton lbtnSelected = (LinkButton)divAlphabets.FindControl("lbtnCharacter" + e.CommandArgument);
            lbtnSelected.CssClass = "firstCharacter highlighted";
            txtTagFilter.Text = string.Empty;

            BindTagList();
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

看春风乍起 2024-09-21 07:38:52

我希望我理解你的问题。

您正在命令处理程序中设置 Selected_Character 项,然后设置按钮的类以突出显示它。仅当单击按钮时才会触发此操作,而不是在您移至下一页时触发。为什么不把这两个操作分开呢。如果 Selected_Character 匹配,则在预渲染时设置链接按钮的类。这样,即使您翻页,链接按钮也会保持突出显示状态。

我还将您选择的字符设置为查询字符串参数,如果有人复制并粘贴链接到您的页面,按钮将不会突出显示,并且不会显示正确的数据。

希望这有帮助。

编辑:尚未测试以下内容,但也许它会帮助您开始。

void lbtnCharacter_Command(object sender, CommandEventArgs e)
{
    // redirect to self with tag as qs parameter
    Response.Redirect(string.Format("{0}?tag={1}", Request.Url.GetLeftPart(UriPartial.Path), e.CommandArgument));
}

protected void Page_PreRender(object sender, EventArgs e) 
{
    if (Request.QueryString["tag"] != null) {
        LinkButton lbtnSelected = (LinkButton)divAlphabets.FindControl("lbtnCharacter" + Request.QueryString["tag"]);
        lbtnSelected.CssClass = "firstCharacter highlighted";
    }
}

注意:您还需要更改 BindTagList 以也使用查询字符串。我假设您在页面加载事件中调用它。

I hope I understood your question.

You are setting your Selected_Character item in the command handler and then setting the class of the button to highlight it. This only gets fired when the button is clicked, not when you move to the next page. Why not separate these two operations. Set the class of the link button on prerender if the Selected_Character matches. That way even when you page the link button will stay highlighted.

I would also set your selected character as a query string parameter, if someone copies and pastes a link to your page the button would not highlight and the correct data would not display.

Hope this helps.

Edit: Haven't tested the below but maybe it will get you started.

void lbtnCharacter_Command(object sender, CommandEventArgs e)
{
    // redirect to self with tag as qs parameter
    Response.Redirect(string.Format("{0}?tag={1}", Request.Url.GetLeftPart(UriPartial.Path), e.CommandArgument));
}

protected void Page_PreRender(object sender, EventArgs e) 
{
    if (Request.QueryString["tag"] != null) {
        LinkButton lbtnSelected = (LinkButton)divAlphabets.FindControl("lbtnCharacter" + Request.QueryString["tag"]);
        lbtnSelected.CssClass = "firstCharacter highlighted";
    }
}

N.B You will also need to change your BindTagList to use the query string also. I'm assuming you call this in the page load event.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文