I have this itemtemplate for a gridview column that is pulling data from a SQL database. My Ques开发者_如何学Pythontion is how would I perform a check to see if my field ActivityFile has a value (which means a file is in the db) and then display the LinkButton at which point I generate code to download the file (already done and works).
<ItemTemplate>
<asp:LinkButton ID="DownloadFileBtn" runat="server" visible="false">Download File</asp:LinkButton>
<br />
<a href="<%# Eval("ActivityLink") %>"><asp:Label ID="Label4" runat="server" Text='<%# Bind("ActivityLink") %>'></asp:Label></a>
</ItemTemplate>
you have to use GridView RowDataBound
Event for that
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
System.Data.DataRowView dr = (System.Data.DataRowView)e.Row.DataItem;
if (Convert.ToBoolean(dr["columnName"].ToString()))
{
LinkButton LinkButton = (LinkButton)e.Row.Findcontrol("LinkButton");
LinkButton.Visible = false;
}
}
}
精彩评论