我正在尝试将FindControl()作为GridView OnRowUpdated事件中的隐藏字段。
protected void gridviewPersonPhoto_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
//string strFileName = (the name of the file that needs to be deleted by System.IO
//which i will know after I FindControl() the HiddenField in the deleted row that contains the name)
}
<asp:GridView id="gridviewPersonPhoto" DataKeyNames"PersonPhotoId"
DataSourceId="sqldatasourcePersonPhoto" OnRowDeleted="gridviewPersonPhoto_RowDeleted">
<TemplateField>
<ItemTemplate>
<asp:HiddenField ID="hiddenfieldFileName value='<%#Eval("FileName")%>' />
<asp:Button ID="buttonDelete" CommandName="Delete" />
</ItemTemplate>
<ItemTemplate>
<asp:Image ID="imgPhoto" ImageUrl='<%# "~/pub/photo/"+(Eval("FileName")) %>' runat="server" />
</ItemTemplate>
</TemplateField>
</asp:GridView>
答案 0 :(得分:2)
在Row_Deleted事件中尝试此代码。
GridViewRow gvRow= (GridViewRow)(((Button)e.CommandSource).NamingContainer);
HiddenField HF = gvRow.FindControl("hiddenfieldFileName") as HiddenField;