自定义GridView的删除按钮 [英] Custom GridView delete button
问题描述
我如何自定义自动生成的命令按钮,如: 删除
?
How can I customize automatically generated command button, e.g. Delete
?
我想添加一个客户端确认上删除,并在同一时刻,我想会在设定 AutoGenerateDeleteButton =真正的
生成此按钮。是否有可能?
I want to add a client confirmation on deleting and in the same moment I want this button would be generated on setting AutoGenerateDeleteButton="true"
. Is it possible??
我可以添加自定义按钮是这样的:
I can add a custom button this way:
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton runat="server" CommandName="Delete" OnClientClick="return confirm('Delete?')">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
但将不会自动本地化,并会在设置不产生 AutoGenerateDeleteButton =真正的
!
推荐答案
我宁愿推荐使用的RowDataBound事件,而不是preRender事件。
I would rather recommend using the RowDataBound-event instead of the PreRender-event.
在那里,你可以很容易地访问您的要素的具体排。 (我认为解决凯尔西发布可能与分页问题(也许只是结合AJAX))
There you can easily have access to your Elements in the specific row. (I think the solution Kelsey posted might have problems with paging (maybe just combined with ajax))
给LinkButton的ID和subsribe到的RowDataBound事件。
Give the Linkbutton an ID and subsribe to the RowDataBound-event.
void gv_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton _foo = e.Row.FindControl("LINKBUTTONID") as LinkButton;
if(_foo != null)
{
_foo.OnClientClick = "insert localized text here";
}
}
}
这篇关于自定义GridView的删除按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!