如何通过ASP.NET GridView onClientClick标记引用当前行中的字段。
但是,我在String.Format
中对文本“条形码”进行了硬编码 <asp:GridView ID="ItemsScannedGridView" runat="server"
AutoGenerateColumns="False" DataKeyNames="ID"
DataSourceID="SqlDataSourceItems"
CssClass="ScannedBarcodes">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" OnClientClick=<%# String.Format("return confirm('Are you sure you wish to delete barcode {0}?');", "barcode" ) %> />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" Visible="False" />
<asp:ImageField DataAlternateTextField="MATCH"
DataAlternateTextFormatString="{0}" DataImageUrlField="MATCH"
DataImageUrlFormatString="~/images/icons/{0}.png" HeaderText="Match">
</asp:ImageField>
<asp:BoundField DataField="BARCODE" HeaderText="Barcode"
SortExpression="BARCODE" Visible="False" />
<asp:BoundField DataField="DESCRIPTION" HeaderText="Description"
SortExpression="DESCRIPTION" />
</Columns>
</asp:GridView>
<%# String.Format("return confirm('Are you sure you wish to delete barcode {0}?');", "barcode" ) %> />
我尝试用Eval("barcode")
替换“条形码”,但它没有用。
答案 0 :(得分:1)
<asp:Button ID="DeleteButton"
runat="server"
CommandName="Delete"
Text="Delete"
OnClientClick=<%# String.Format("return confirm('Are you sure you wish to delete barcode {0}?');", Eval("BARCODE") ) %> />