繁体   English   中英

将onClick添加到Infragistics WebDataGrid

[英]Add an onClick to an Infragistics WebDataGrid

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

您可以尝试以下方法:

  1. 处理“ Click”客户端事件,并调用__doPostBack js函数来触发回发。 Page_Load服务器事件将帮助您确定回发是否是由单击引起的。 要考虑的事情是,在网格内部的每次点击都会触发客户端事件“点击” ,请查看提供的API链接以获取更多信息。
  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"];

...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM