第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何處理用戶控件網(wǎng)格視圖的事件?

如何處理用戶控件網(wǎng)格視圖的事件?

C#
SMILET 2021-07-14 16:01:45
我有一個用戶控件作為網(wǎng)格視圖。我正在動態(tài)添加它......我已經(jīng)為數(shù)據(jù)源創(chuàng)建了方法,但我無法使用網(wǎng)格視圖的其他事件,如“Row_Data_Bound”等。我在網(wǎng)上看到過代碼,上面寫著創(chuàng)建委托并添加以下內(nèi)容protected void Simple_DGV_RowDataBound(object sender, GridViewRowEventArgs e)   {OnRowDataBound(e);}但我在這里收到一個錯誤,說當(dāng)前上下文中不存在名稱 OnRowDataBound任何人都可以幫助我訪問父頁面中用戶控件網(wǎng)格視圖的事件編輯:<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UserControl1.ascx.cs" Inherits="ProjectManagement.UserControl.User1" %><div><asp:GridView ID="ucGridView" runat="server" SkinID="gvSchedulerSkin" AllowSorting="false" OnRowDataBound="ucGridView_RowDataBound">   <RowStyle Width="20px" /> </asp:GridView></div>這是我的 ascx 頁面……我想在多個地方(在運行時)使用這個網(wǎng)格視圖,所以我創(chuàng)建了一個用戶控件……基本上我想從我的代碼中調(diào)用這個用戶控件,然后使用它的 rowdatabound 我想將數(shù)據(jù)與 gridview 綁定..我在網(wǎng)站上看到它說使用事件冒泡......但我不知道如何實現(xiàn)。那么你能幫我解決這個問題嗎..這樣我就可以像我一樣正常使用 rowdatabound提前謝謝
查看完整描述

1 回答

?
繁華開滿天機(jī)

TA貢獻(xiàn)1816條經(jīng)驗 獲得超4個贊

我在本地創(chuàng)建了一個項目,這沒問題。


我有一個名為 TestUserControl.ascx 的控件。我在設(shè)計模式下將一個 GridView 控件拖到用戶控件上,并將其命名為“grdControlsGrid”。


這生成了以下標(biāo)記。


<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestUserControl.ascx.cs" Inherits="TestASPNet.TestUserControl" %>

<asp:GridView ID="grdControlsGrid" runat="server">

</asp:GridView>

然后我通過在 runat="server" 之后向 hmtl 鍵入“OnRowDataBound=”來添加事件 OnRowDataBound。當(dāng)您點擊 equals 時,它會為您提供為此事件創(chuàng)建方法的選項。雙擊“創(chuàng)建方法”選項,這將為您將事件連接到方法。


<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestUserControl.ascx.cs" Inherits="TestASPNet.TestUserControl" %>

<asp:GridView ID="grdControlsGrid" runat="server" OnRowDataBound="grdControlsGrid_OnRowDataBound">

</asp:GridView>

根據(jù)下面的代碼,此代碼現(xiàn)在位于您的用戶控件中。


或者,您可以在用戶控件負(fù)載中自行連接事件。


 public partial class TestUserControl : System.Web.UI.UserControl

    {

        protected void Page_Load(object sender, EventArgs e)

        {

            //Manually Add event handler

            grdControlsGrid.RowDataBound += GrdControlsGrid_RowDataBound;

        }


        private void GrdControlsGrid_RowDataBound(object sender, GridViewRowEventArgs e)

        {

            //Manually bound event

        }


        protected void grdControlsGrid_OnRowDataBound(object sender, GridViewRowEventArgs e)

        {

            //Auto wired event

        }

    }

出于某種原因,當(dāng)通過標(biāo)記自動連接時,您會收到事件“OnRowDataBound”..但是在手動后面的代碼中完成時,您會得到“RowDataBound”。我的猜測是它們是相同的..但也許其他人可以闡明這一點。


希望有幫助。


查看完整回答
反對 回復(fù) 2021-07-17
  • 1 回答
  • 0 關(guān)注
  • 160 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號