简体   繁体   中英

Add an onClick to an Infragistics WebDataGrid

I have an Infragistics WebDataGrid and I want to fire a server side event every time a cell is clicked on. I know that I can make a button and add an onclick to that, but I want some or all the data cells to be clickable. I also saw this( https://www.infragistics.com/community/forums/f/ultimate-ui-for-asp-net/108226/onclick-event-for-webdatagrid ) but I need the event to fire server side.

You can try the following:

  1. Handle "Click" client event and call __doPostBack js function to trigger a postback. Page_Load server event will help you to determine whether the postback is caused by the click or not. Things to consider, client event "Click" will be fired on every click inside the Grid, have a look at the provided API link for more info.
  2. Activate Selection behavior, and handle CellSelectionChanged client event. From here use the approach with __doPostBack .

The Grid is very powerful control with a rich API and the behaviors, so we could thing of a different way to achieve this.

Snippet:

..
<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"];

...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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