datagrid文本字段,触发GridView1_RowCommand事件

时间:2016-04-29 19:25:58

标签: asp.net datagrid

我有一个数据网格,我希望将文件显示为文本并触发命令事件,这样我就可以像asp:ButtonField那样处理服务器端了。

我的失败代码是:

<asp:ButtonField CommandName="CallHist" 
ButtonType="Button" Text ="<%#GetJobs(Eval("currStatus"))%>" >
</asp:ButtonField>

我收到错误:

  

a中不允许使用直译内容(&#39;&#34;&gt;&#39;)   &#39; System.Web.UI.WebControls.ButtonField&#39;

我正在尝试更改现有的workign ButtonFields:

<asp:ButtonField CommandName="editRecord" ControlStyle-Height="16px" ControlStyle-Width ="16px" ButtonType="image" ImageUrl="images/edit-icon.png">
                                            </asp:ButtonField>

                                            <asp:ButtonField CommandName="deleteRecord" ControlStyle-Height="16px" ControlStyle-Width ="16px" ButtonType="Image"  ImageUrl="images/close-icon.png">
                                            </asp:ButtonField>

我也尝试使用<asp:TemplateField>

,但没有运气

如何获取显示数据的字段并成为可点击/触发的事件?

1 个答案:

答案 0 :(得分:1)

ButtonField不支持绑定表达式。您可以使用其TemplateField中的LinkBut​​ton或Button ItemTemplate替换它。在Text属性的数据绑定表达式中,您应该用单引号替换外部双引号,以避免与内部双引号冲突:

<asp:TemplateField>
    <ItemTemplate>
        <asp:LinkButton runat="server" CommandName="CallHist" Text='<%# GetJobs(Eval("currStatus")) %>' CommandArgument='<%# Eval("ID") %>' />
    </ItemTemplate>
</asp:TemplateField>