Articles in this section
Category / Section

How to place icons in command column buttons instead of text in ASP.NET WebForms?

1 min read

In command column buttons by default, the text such as Edit/Delete/Save/Cancel will be displayed. We can also place the icons in those buttons.

Let us see how to place icons in command column buttons.

Grid Initialization

JS

 
$("#Grid").ejGrid({
            dataSource: window.employeeView,
            allowPaging: true,
            allowSelection: false,
            enableRowHover: false,
            editSettings:{ allowEditing:true, allowDeleting:true },
            columns: [               
                      { field: "EmployeeID", headerText: 'Employee ID', isPrimaryKey:true },
                      { field: "FirstName", headerText: 'First Name'},
                      { field: "LastName", headerText: 'Last Name'},
                      {
                          headerText: "Manage Records",
                          commands: [
                              { type: ej.Grid.UnboundType.Edit, buttonOptions: { contentType: "imageonly", prefixIcon:"e-icon e-edit" } },
                              { type: ej.Grid.UnboundType.Delete, buttonOptions: { contentType: "imageonly", prefixIcon: "e-icon e-delete" } },
                              { type: ej.Grid.UnboundType.Save, buttonOptions: { contentType: "imageonly", prefixIcon: " e-icon e-save" } },
                              { type: ej.Grid.UnboundType.Cancel, buttonOptions: { contentType: "imageonly", prefixIcon: " e-icon e-cancel" } }
                          ],
                          isUnbound: true
                      }
            ]       
        });
 

 

MVC

 
@(Html.EJ().Grid<object>("Grid")
.Datasource((IEnumerable<object>)ViewBag.datasource)
.AllowPaging()
    .EditSettings(e => e.AllowEditing().AllowDeleting())
    .Columns(col =>
    {
 
            col.Field("EmployeeID").HeaderText("Employee ID").IsPrimaryKey(true).Add();
            col.Field("FirstName").HeaderText("First Name").Add();
            col.Field("LasttName").HeaderText("Last Name").Add();
            col.HeaderText("Manage Records").IsUnbound(true).Commands(commands =>
            {
                commands.Type(UnboundType.Edit).ButtonOptions(new ButtonProperties()
                {
                    ContentType = ContentType.ImageOnly,
                    PrefixIcon = "e-icon e-edit"
                }).Add();
                commands.Type(UnboundType.Delete).ButtonOptions(new ButtonProperties()
                {
                    ContentType = ContentType.ImageOnly,
                    PrefixIcon = "e-icon e-delete"
                }).Add();
                commands.Type(UnboundType.Save).ButtonOptions(new ButtonProperties()
                {
                    ContentType = ContentType.ImageOnly,
                    PrefixIcon = "e-icon e-save"
                }).Add();
                commands.Type(UnboundType.Cancel).ButtonOptions(new ButtonProperties()
                {
                    ContentType = ContentType.ImageOnly,
                    PrefixIcon = "e-icon e-cancel"
                }).Add();
            }).Width(75).Add();
        }))
 

 

ASPX

 
<ej:Grid ID="Grid" runat="server" AllowPaging="true" AllowSelection="false" EnableRowHover="false">           
            <Columns>
                <ej:Column Field="EmployeeID" HeaderText="Employee ID" IsPrimaryKey="true"/>
                <ej:Column Field="FirstName" HeaderText="First Name"/>
                <ej:Column Field="LastName" HeaderText="Last Name"/>
                <ej:Column HeaderText="Manager Recors">
                    <Commands>
                        <ej:Commands Type="edit">
                            <ButtonOptions ContentType ="ImageOnly" PrefixIcon="e-icon e-edit" />
                        </ej:Commands>
                        <ej:Commands Type="delete">
                            <ButtonOptions ContentType ="ImageOnly" PrefixIcon="e-icon e-delete" />
                        </ej:Commands>
                        <ej:Commands Type="save">
                            <ButtonOptions ContentType ="ImageOnly" PrefixIcon="e-icon e-save" />
                        </ej:Commands>
                        <ej:Commands Type="cancel">
                            <ButtonOptions ContentType ="ImageOnly" PrefixIcon="e-icon e-cancel" />
                        </ej:Commands>
                    </Commands>
                </ej:Column>
            </Columns>
        </ej:Grid>
 

 

The result will be as follows.

Figure 1: Command column with icon before editing

 

Figure 2: Command column with icon after editing

Using custom icons

The icons showed in the above examples are available in the Syncfusion`s default theme packages. We can also use our own custom icons in the command buttons.

For example, to use the Font-Awesome icons in the command button, include the reference to the Font-Awesome icons CSS file in your page.

 
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
 

 

And then specify the corresponding icon class in the prefixIcons property of the buttonOptions.

$("#Grid").ejGrid({
            dataSource: window.employeeView,
            allowPaging: true,
            allowSelection: false,
            enableRowHover: false,
            editSettings: { allowEditing: true, allowDeleting: true },
            columns: [
                      { field: "EmployeeID", headerText: 'Employee ID', isPrimaryKey: true },
                      { field: "FirstName", headerText: 'First Name' },
                      { field: "LastName", headerText: 'Last Name' },
                      {
                          headerText: "Manage Records",
                          commands: [
                              { type: ej.Grid.UnboundType.Edit, buttonOptions: { contentType: "imageonly", prefixIcon: "fa fa-pencil-square-o" } },
                              { type: ej.Grid.UnboundType.Delete, buttonOptions: { contentType: "imageonly", prefixIcon: "fa fa-times" } },
                              { type: ej.Grid.UnboundType.Save, buttonOptions: { contentType: "imageonly", prefixIcon: "fa fa-floppy-o" } },
                              { type: ej.Grid.UnboundType.Cancel, buttonOptions: { contentType: "imageonly", prefixIcon: "fa fa-times" } }
                          ],
                          isUnbound: true
                      }
            ]
        });
 

 

In such a way, you can assign the CSS class of the corresponding icon in the PrefixIcons property of the ASP.Net MVC Grid and ASP.Net Grid to show the icons in the custom button.

The output result is as follows.

Figure 3: Grid with custom icon in command button before edit

Figure 4: Grid with custom icon in command button after edit

 

Note:

‚ÄčA new version of Essential Studio for ASP.NET is available. Versions prior to the release of Essential Studio 2014, Volume 2 will now be referred to as a classic versions.The new ASP.NET suite is powered by Essential Studio for JavaScript providing client-side rendering of HTML 5-JavaScript controls, offering better performance, and better support for touch interactivity. The new version includes all the features of the old version, so migration is easy.

The Classic controls can be used in existing projects; however, if you are starting a new project, we recommend using the latest version of Essential Studio for ASP.NET. Although Syncfusion will continue to support all Classic Versions, we are happy to assist you in migrating to the newest edition.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls. If you have any queries or require clarifications, please let us know in the comments section below.

You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment