如何在数据网格按钮设置的CssClass [英] How to set CssClass on button in DataGrid

查看:242
本文介绍了如何在数据网格按钮设置的CssClass的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataGrid中ButtonColumn:

I have a ButtonColumn in a DataGrid:

<asp:ButtonColumn HeaderText="Edit" ButtonType="PushButton" Text="Edit" />

我如何设置它的CSS类?

How do I set it's CSS class?

我可以看到这样做的唯一方法,是挂钩的RowDataBound事件:

The only way I can see to do it, is hooking to the RowDataBound event:

Protected Sub dgSchedule_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgSchedule.ItemDataBound
    If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
        DirectCast(e.Item.Cells(6).Controls(0), Button).CssClass = "confirmButton"

    End If
End Sub

我只是觉得必须有一个更合适的方法。如果我添加/删除列,我必须回到这里,记得要改变,会发生什么列6 ...

I just feel like there must be a neater way. What happens if I add/remove columns, I'll have to come back here and remember to change column 6...

我试图用一个 TemplateColumn中和往常一样 ASP:按钮 - 这个工作,但然后单击它并没有火,我需要消防网格的ItemCommand事件。

I tried using a TemplateColumn and a usual asp:Button - This worked, but then clicking it did not fire the ItemCommand event of the grid which I need to fire.

推荐答案

我已经用一个GridView,而不是一个DataGrid解决了这个。其实不知道为什么,我在第一时间使用DataGrid中。

I have resolved this by using a GridView instead of a DataGrid. Actually not sure why I used a DataGrid in the first place.

这给出了一个附加属性 ControlStyle-的CssClass

This gives an additional property ControlStyle-CssClass

例如。

<asp:ButtonField HeaderText="Edit" ButtonType="Button" Text="Edit" ControlStyle-CssClass="confirmButton" />

这篇关于如何在数据网格按钮设置的CssClass的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆