Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement gridview row selection to add colors and events

Shulou Source: shulou.com Published: 2022-06-03 07:50:05 09月23日 Update

This article focuses on "how to add colors and events to gridview row selection". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to add colors and events to gridview row selection.

In the gridview list, need to add the following effect, if after time change color, remove when reverting to the previous color, row selection by adding dark, so as to know which row is selected, especially when there is a lot of list data, the flag is very important, while triggering the selected row event, then how to add color in the row selection, while also starting our event? If we access e.Row.Attributes.Add ("onclick") and bind it twice, we find that only one of them can be triggered, but we can actually put the other into one.

Here are specific examples:

The copy code is as follows:

Protected void EditGridview_RowDataBound (object sender, GridViewRowEventArgs e)

{

If (e.Row.RowTypewriter = DataControlRowType.DataRow)

{

/ / save the background color of the current line and attach a color when the mouse is on it.

E.Row.Attributes.Add ("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='inactivecaptiontext',this.style.fontWeight='';this.style.cursor='hand';")

/ / restore the background color to its previous color when the mouse leaves

E.Row.Attributes.Add ("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';")

/ / darken the color flag when the mouse is clicked

E.Row.Attributes.Add ("onclick", "setvalue (); if (window.oldtrending null) {window.oldtr.runtimeStyle.cssText='';} this.runtimeStyle.cssText='background-color:#e6c5fc';window.oldtr=this")

}

}

Js Code:

The copy code is as follows:

Function setvalue () {

Alert ('row click event, change color at the same time')

}

At this point, I believe you have a deeper understanding of "how to add colors and events to gridview row selection". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Color event code at the same time time mouse content logo background discoloration learning practical deeper important examples interest practicality practical simple operation effect Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Docker Huawei Xiaomi vpn