绑定GridView中的模板列

aspX:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDataBound="GridView1_RowDataBound"> <Columns> <asp:BoundField DataField="Field1" HeaderText="字段1" /> <asp:TemplateField HeaderText="删除"> <ItemTemplate> <asp:LinkButton ID="delete" runat="server" OnClick="delete_Click" OnClientClick="return confirm('删除?')">删除</asp:LinkButton> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>

C#:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { DataRowView row = (DataRowView)e.Row.DataItem; LinkButton deleteButton = e.Row.FindControl("delete") as LinkButton; } }

你可能感兴趣的:(绑定GridView中的模板列)