What is the method for including a button column within a datagrid object?

I am looking to enhance my data grid object by adding a button column. The data table is filled in the aspx.cs file, and we are using the .Net Webform structure. Can anyone provide guidance on how to achieve this? Below is an example of my current grid setup:

        <div id="divSGKTecrube" runat="server">
            <iskurControls:IskurGridView runat="server"
                ID="ctlGridSgkTecrube"
                AutoGenerateColumns="False"
                EmptyDataText="Tecrübe Bilginiz Bulunmamaktadır."
                EnableViewState="true"
                CssClass="table table-bordered table-condensed text-small">
                <Columns>
                    <asp:BoundField DataField="ISYERISICILNO" HeaderText="İşyeri Sicil No">
                        <HeaderStyle HorizontalAlign="Left" />
                    </asp:BoundField>
                    <asp:BoundField DataField="ISYERIADI" HeaderText="İşyeri Adı">
                        <HeaderStyle HorizontalAlign="Left" />
                    </asp:BoundField>
                    <asp:BoundField DataField="MESLEKKODU" HeaderText="Meslek Kodu">
                        <HeaderStyle HorizontalAlign="Left" />
                    </asp:BoundField>
                    <asp:BoundField DataField="MESLEK" HeaderText="Meslek">
                        <HeaderStyle HorizontalAlign="Left" />
                    </asp:BoundField>
                    <asp:BoundField DataField="SURE" HeaderText="Süre">
                        <HeaderStyle HorizontalAlign="Right" />
                    </asp:BoundField>
                    <asp:BoundField DataField="BASLANGICTARIHI" HeaderText="Baş Tar">
                        <HeaderStyle HorizontalAlign="Right" />
                    </asp:BoundField>
                    <asp:BoundField DataField="BITISTARIHI" HeaderText="Bit Tar">
                        <HeaderStyle HorizontalAlign="Right" />
                    </asp:BoundField>
                    <asp:ButtonField Text="Example Button" CommandName="ExampleCommand" />
                </Columns>
                <PagerStyle CssClass="grid-PagerStyle"></PagerStyle>
                <SelectedRowStyle CssClass="grid-SelectedRowStyle"></SelectedRowStyle>
                <HeaderStyle CssClass="grid-HeaderStyle"></HeaderStyle>
                <EditRowStyle CssClass="grid-EditRowStyle"></EditRowStyle>
                <AlternatingRowStyle CssClass="grid-AlternatingRowStyle"></AlternatingRowStyle>
                <FooterStyle CssClass="grid-FooterStyle"></FooterStyle>
                <RowStyle CssClass="grid-RowStyle"></RowStyle>
                <EmptyDataRowStyle CssClass="grid-EmptyRow" />
            </iskurControls:IskurGridView>
            <div style="text-align: center">
                <kaleCustomControls:DataPager ID="DataPager1" runat="server" VisibleIfNoNeed="False" PagerButtons="NextPrevious" />
            </div>
        </div>

Answer №1

If you want to include a button column in your grid, follow these steps:

<Columns>
    <asp:TemplateField HeaderText="Actions">
        <ItemTemplate>
            <asp:Button ID="btnEdit" runat="server" Text="Edit" CommandName="EditRow" />
        </ItemTemplate>
    </asp:TemplateField>
</Columns>

To handle the commands in your aspx.cs file, make use of the RowCommand event of IskurGridView:

protected void ctlGridSgkTecrube_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "EditRow")
    {
        // Implement edit logic
        int rowIndex = Convert.ToInt32(e.CommandArgument);
        // Access data for the selected row
    }
    else if (e.CommandName == "DeleteRow")
    {
        // Implement delete logic
        int rowIndex = Convert.ToInt32(e.CommandArgument);
        // Delete data for the selected row
    }
}

Don't forget to add the RowCommand event handler to your IskurGridView:

<iskurControls:IskurGridView runat="server"
    ID="ctlGridSgkTecrube"
    AutoGenerateColumns="False"
    OnRowCommand="ctlGridSgkTecrube_RowCommand"
    <!-- ... -->
>
    <!-- Define columns here -->
</iskurControls:IskurGridView>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Select checkboxes by clicking a button that matches the beginning of a string in JavaScript

I have a form with a list of users and checkboxes below their names. Each user has a button that should select all checkboxes assigned to them. Below is the code for the dynamically created buttons and checkboxes. The included function takes the form name ...

Dealing with 404 errors encountered when making requests to external websites, utilizing either basic Javascript or JQuery

I have links in my application that redirect to external websites. For example, a link might look like this: <http://www.google.com'>>General Search<>. Users input the href and we dynamically create the link without any validation of it ...

Troubleshooting an Angular.js "Hello World" application that is malfunctioning

I've been trying to get a simple Hello World app working by following different tutorials, but it doesn't seem to be functioning correctly. I've double-checked my code and everything looks right to me. Could someone please assist me in troub ...

How do I initiate a custom button click event in React from an event handler in another component?

I have a unique React application that utilizes the Material UI framework for its user interface design. Specifically, I have developed a specialized button component that customizes the default Material UI button and integrates with Redux. Within the ren ...

Identifying JavaScript Bugs during Selenium Test Execution

During my selenium testing, I am looking for a way to identify and locate JavaScript errors on web pages. Currently, I am utilizing Selenium RemoteWebDriver, NUnit, and C#. I recently came across a method where you can integrate JavaScript into each page ...

Tips for seamlessly integrating XHP and ReactJS for a component's implementation

Imagine this scenario: a blog with a posts feed. Upon loading the page, three <PostCard>s are already loaded from the server-side. As the user scrolls down or clicks a Load more button, new post cards should be dynamically added to the page. We have ...

Removing an item from an array using AngularJS with Underscore or another method

Although my question may seem similar to others, it is unique! Please review to understand my specific situation. I am dealing with an array of objects that looks like this $scope.events =[ { $$hashKey: "009" _allDay:false _i ...

Using JavaScript in conjunction with IPFS to verify the 404 status from localhost:8080 and identify if the local IPFS node is active within a browser user script

As a newcomer to IPFS and JavaScript, I have successfully created a simple IPFS userscript that redirects addresses containing *://*/ipfs/* or *://*/ipns/* to http://localhost:8080/<IPFS_HASH>. However, there is an issue when the local IPFS node is ...

Tips for removing or changing the X-Powered-By header in a Sails.js application

Running a Sails.js application results in the automatic addition of the HTTP header X-Powered-By: "Sails <sailsjs.org>" to every response. Is there a way to prevent or modify this header? ...

NextJS does not support the rendering of the map function

Currently, I am getting acquainted with NextJS by creating a basic blog. I have successfully passed the data through props and can see it logged in the console within the map function. However, I am facing an issue where the HTML content does not display i ...

Troubleshooting the issue with utilizing the ng-repeat directive to loop through images in Angular JS

Embarking on my initial website development journey with Java and Spring Boot, I've hit a stumbling block in the front-end realm. Being a newbie, I'm struggling to identify and resolve the issue at hand. Problem title: How do I ...

How can I convert the JSON array response from the API, which is of type string, back into an array?

Is there a way to change a string type array back into an array? var arr = '[ "abc", "def"]'; console.log(typeof arr) ==> String How can I convert it back into an array format? I'm receiving this string-formatted array from an API r ...

Searching for dates within a range on DataTables using CodeIgniter

Can someone assist me in displaying data within a selected date range? Here is the code snippet I have so far: Below is the code for displaying the data tables: View <div class="box-body"> <div class="table-responsive"> ...

Obtaining a cloned HTML object using jQuery in C# the correct way

In my webpage, there is a div with various input elements inside. I want to duplicate the entire HTML content of this div so that I can store it in my database. When I retrieve this cloned HTML in the future, I want it to appear on another page exactly as ...

Trigger $q manually in AngularJS

My understanding of $q in AngularJS is that it runs every time I refresh my page, similar to using a function in ng-init. Here is the code for $q.all that I have: $q.all([$scope.getCart(), $scope.getCategory(), $scope.getMenu(), $scope.getRestaurant()]). ...

Switching from module.exports in Javascript to Typescript format

My Node-express code currently uses module.exports to export functions. As I am converting the code to TypeScript, I need to find out how to replace module.exports in typescript. Can you help me with this? ...

Encountering issues with Office.context.document.getFileAsync function

I am experiencing a strange issue where, on the third attempt to extract a word document as a compressed file for processing in my MS Word Task Pane MVC app, it crashes. Here is the snippet of code: Office.context.document.getFileAsync(Office.FileType.Co ...

Error message: Modal.dispose function not available in Bootstrap 5 Symfony 5.3 issue detected

I have been working on creating a modal using Symfony 5 and Bootstrap 5. I want the form fields to be cleared when the modal is closed. Below are the relevant files. I am encountering an error when trying to close the modal: Uncaught TypeError: myModal.dis ...

`Using Twitter Bootstrap in mobile app development with javascript`

I have been utilizing Twitter Bootstrap 2.3 on one of my websites and I appreciate its responsiveness and use of media queries for mobile devices. However, I have noticed a lack of mobile-specific features, particularly linked listviews. In order to addres ...

Top method for incorporating Ember.js with outside code (such as Android's WebView)

Can someone advise on the best approach to developing an Ember.js app that needs to interact with external code, such as being called from an Android app through a WebView or other sources outside of the Ember Application's scope? In such cases, havi ...