<asp:GridView ID="gvData" runat="server" Width="100%" OnRowDataBound="gvData_RowDataBound" OnRowCommand="gvData_RowCommand" AutoGenerateColumns="False" OnRowCreated="gvData_RowCreated">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" AlternateText="Detail Data" CausesValidation="False"
CommandArgument='<%# Eval("iif01")%>' CommandName="ShowDetail" ImageUrl="/images/details_icon.gif" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="iif01" HeaderText="列名"></asp:BoundField>
<asp:BoundField DataField="iif02" HeaderText="列名"></asp:BoundField>
<asp:BoundField DataField="iif03" HeaderText="列名"></asp:BoundField>
<asp:BoundField DataField="iif05" HeaderText="列名"></asp:BoundField>
<asp:BoundField DataField="iif06" HeaderText="列名"></asp:BoundField>
<asp:BoundField DataField="iif07" HeaderText="列名"></asp:BoundField>
<asp:BoundField DataField="iif08" HeaderText="列名"></asp:BoundField>
<asp:ButtonField CommandName="del" Text="Text" HeaderText="列名"></asp:ButtonField>
<asp:ButtonField CommandName="cmd" Text="Text" HeaderText="列名"></asp:ButtonField>
</Columns>
</asp:GridView>
- 点击事件:OnRowCommand
- 分别在ImageButton和ButtonField中绑定了事件名:CommandName
- 其中ImageButton还增加了传递参数:CommandArgument,将gridview被点击的行的iif01值给了CommandArgument
- 在后台OnRowCommand 事件中,可以根据CommandName来判断用户点击的是ImageButton还是ButtonField
如果有描述不清楚的,大家可以留言,看到了就会回答