【问题标题】:Add an onClick to an Infragistics WebDataGrid将 onClick 添加到 Infragistics WebDataGrid
【发布时间】:2018-09-21 17:38:12
【问题描述】:

我有一个 Infragistics WebDataGrid,我想在每次单击单元格时触发一个服务器端事件。我知道我可以制作一个按钮并为其添加一个 onclick,但我希望部分或所有数据单元格可点击。 我也看到了这个(https://www.infragistics.com/community/forums/f/ultimate-ui-for-asp-net/108226/onclick-event-for-webdatagrid),但我需要事件来触发服务器端。

【问题讨论】:

    标签: c# infragistics webdatagrid


    【解决方案1】:

    您可以尝试以下方法:

    1. 处理"Click"客户端事件并调用__doPostBackjs函数触发回发。 Page_Load 服务器事件将帮助您确定回发是否是由点击引起的。需要考虑的事项,客户端事件 "Click" 将在网格内的每次点击时触发,请查看提供的 API link 了解更多信息。
    2. 激活选择行为,并处理 CellSelectionChanged 客户端事件。从这里使用__doPostBack 的方法。

    Grid 是非常强大的控件,具有丰富的 API 和行为,因此我们可以采用不同的方式来实现这一点。

    片段:

    ..
    <script>
            function client_click(sender, evtArgs) {
                // First Approach
                __doPostBack('myRequest', "someValue");
            }
    
            function WDG_Selection_CellSelectionChanged(sender, eventArgs)
            {
                // Second Approach
                __doPostBack('myRequest', "someValue");
            }
    </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ScriptManager runat="server" ID="ScriptManager1"></asp:ScriptManager>
        <div>
            <ig:WebDataGrid runat="server" ID="WDG" AutoGenerateColumns="False" Width="600px">
                <ClientEvents Click="client_click" />
                <Columns>
                    <ig:BoundDataField DataFieldName="CategoryId" Key="CategoryId">
                        <Header Text="CategoryId">
                        </Header>
                    </ig:BoundDataField>
                    <ig:BoundDataField DataFieldName="CategoryName" Key="CategoryName">
                        <Header Text="CategoryName">
                        </Header>
                    </ig:BoundDataField>
                    <ig:BoundDataField DataFieldName="Description" Key="Description">
                        <Header Text="Description">
                        </Header>
                    </ig:BoundDataField>
                </Columns>
                <Behaviors>
                    <ig:EditingCore>
                        <Behaviors>
                            <ig:CellEditing>
                                <CellEditingClientEvents EnteringEditMode="entering_edit_mode" />
                            </ig:CellEditing>
                        </Behaviors>
                    </ig:EditingCore>
                    <ig:Selection>
                        <SelectionClientEvents CellSelectionChanged="WDG_Selection_CellSelectionChanged" />
                    </ig:Selection>
                </Behaviors>
            </ig:WebDataGrid>
    
    
    ..
    

    c#

    protected void Page_Load(object sender, EventArgs e)
    {
        string parameter = Request["__EVENTARGUMENT"];
    

    ...

    【讨论】:

    • 而 evtArgs/eventArgs 会让我找出点击了哪个单元格?
    • 没错! “evtArgs.get_item()”将为您提供 Cell 元素:“$IG.GridCell {_row: $IG.GridRow, _flags: null, _props: Array(0), _element: td, _owner: $IG.WebDataGrid, ... }" "evtArgs.get_type()" 会给你点击的项目类型 "cell"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-15
    相关资源
    最近更新 更多