GridView滑鼠停留變色和用戶端單擊處理事件

來源:互聯網
上載者:User
 

在使用C#寫CRM時遇到一個問題,GridView綁定了了資料後,我想在滑鼠停留到GridView資料行時,行變色反白該行,並且滑鼠點擊該行時,將該條目的資料顯示在GridView下面的控制項自動將該行對應的資料顯示出來。

我的實現步驟是:

1.增加GridView的GVSelect_RowDataBound事件

protected void GVSelect_RowDataBound(object sender, GridViewRowEventArgs e)

    {

        if (e.Row.RowType == DataControlRowType.DataRow)

        {

            //當滑鼠停留時更改背景色

            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#8EC26F'");

            //當滑鼠移開時還原背景色

            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");

            //設定懸浮滑鼠指標形狀為"小手"

            e.Row.Attributes["style"] = "Cursor:hand";

 

            //單擊/雙擊 事件

            e.Row.Attributes.Add("OnClick", "ClickEvent('" + e.Row.Cells[0].Text + "')");

            //註:OnClick參數是指明為按一下滑鼠時間,後個是調用javascript的ClickEvent函數

        }

}

2在頁面的HTML裡添加javascript函數,用來響應滑鼠點擊事件,因為ASP用戶端不能主動調用服務端的函數,我在這裡添加一個LinkButton,將其text設定為空白,然後在ClickEvent(cId)函數中,調用這個LinkButton的單擊事件。

<script language="javascript">

    function ClickEvent(cId)

    {

        //調用LinkButton的單擊事件,btnBindData是LinkButton的ID

        document.getElementById("btnBindData").click();

    }

</script>

3.添加LinkButton的響應事件

   protected void btnBindData_Click(object sender, EventArgs e)

{

         //在這裡對你需要的資料資訊進行輸出

         SetClientInfo();//我的處理函數

}

 

GridView滑鼠停留變色和單擊處理事件,當滑鼠在GridView的行上停留時,將該行變色,當單擊該行時,做相應處理,記得要在<gridview ></gridview> 之間 加上RowDataBound=GVSelect_RowDataBound 屬性

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.