开发者

GridView Conditional Button Visibility

开发者 https://www.devze.com 2023-02-20 12:05 出处:网络
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 (whic

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;
    }

  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号