这是VB项目中的HTML,它被移植到一个新的C#app:
<asp:DataGrid id="DG1" runat="server" HorizontalAlign="center" AutoGenerateColumns="False" width="850" AllowSorting="True" OnSortCommand="LawSortEvent" ShowFooter="true" onItemDataBound="LawDG_ItemDataBound" FooterStyle-Font-Bold="True" >
<Columns>
<asp:BoundColumn DataField="ID" HeaderText="" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
<asp:BoundColumn DataField="afecategory" SortExpression="afecategory" HeaderText="Code" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Right" />
<asp:BoundColumn DataField="transdate" DataFormatString="{0:MM/dd/yyyy}" SortExpression="transdate" HeaderText="Date" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
<asp:BoundColumn DataField="company" SortExpression="company" HeaderText="Vendor" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
<asp:BoundColumn DataField="description" SortExpression="description" HeaderText="Desc" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Left" />
<asp:BoundColumn DataField="systemtype" SortExpression="systemtype" HeaderText="System" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
<asp:BoundColumn DataField="apinvoice" SortExpression="apinvoice" HeaderText="AP Inv" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Right" />
<asp:BoundColumn DataField="amount" SortExpression="amount" DataFormatString="{0:C}" HeaderText="Total" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Right" />
<asp:templatecolumn headertext="" ItemStyle-HorizontalAlign="Center" >
<itemtemplate>
<asp:ImageButton id="btnViewInvoice" runat="server"
ImageURL="/images/glass2.png"
OnCommand="dgViewInvoice"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "apinvoice") %>'
commandname='<%# DataBinder.Eval(Container.DataItem, "vendornum") %>'
AlternateText="View Invoice"
Visible='<%# (DataBinder.Eval(Container.DataItem, "systemtype") <> "GL") %>'
/>
</itemtemplate>
</asp:templatecolumn>
</Columns>
</asp:Datagrid>
我的问题在于ImageButton - 我不知道如何在C#中编写它,因为我不确定它想要做什么。
我发现最接近解释其中一些内容的是What's the deal with Databinder.Eval and Container.DataItem?,但我一直在尝试不同的方式来更改我的文字,使其在过去的30分钟内无效。
每次我更改文本时,错误消息都会更改为我尝试做的不同。
答案 0 :(得分:0)
我明白了。
<asp:templatecolumn headertext="" ItemStyle-HorizontalAlign="Center" >
<itemtemplate>
<asp:ImageButton id="btnViewInvoice" runat="server"
ImageURL="/images/glass2.png"
OnCommand="dgViewInvoice"
CommandArgument='<%# Eval("apinvoice") %>'
commandname='<%# Eval("vendornum") %>'
AlternateText="View Invoice"
Visible='<%# Eval("systemtype") != "GL") %>'
/>
</itemtemplate>
</asp:templatecolumn>