<%@ Page Title="" Language="C#" MasterPageFile="~/Pages/Site.Master" AutoEventWireup="true" CodeBehind="Test.aspx.cs" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
Enter ID<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:LinkButton ID="LinkButtonSearch" runat="server"
onclick="LinkButtonSearch_Click" >Search</asp:LinkButton>
<br /><asp:Label ID="LabelMessage" runat="server" ForeColor="Red"></asp:Label>
<asp:GridView ID="GridView1" runat="server"
EnableModelValidation="True">
</asp:GridView>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Footer" runat="server">
</asp:Content>
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LinkButtonSearch_Click(object sender, EventArgs e)
{
SqlConnection theConn = null;
LabelMessage.Text = "";
try
{
theConn = LEANifyUtils.GetSqlConnection();
SqlCommand theCmd = new SqlCommand(null, theConn);
theCmd.CommandText = "";
SqlDataReader theRdr = theCmd.ExecuteReader(CommandBehavior.CloseConnection);
DataTable dt = new DataTable();
dt.Load(theRdr);
if (dt.Rows.Count == 0)
{
LabelMessage.Text = "Sorry! Project not found.";
}
GridView1.DataSource = dt;
GridView1.AutoGenerateColumns = true;
GridView1.DataBind();
}
catch (Exception eGen)
{
LabelMessage.Text = "Failed";
}
finally{
//close connection
}
}
I will explain again what I'm trying to achieve. In master page I have linkbutton named export to export the gridview to excel and I have set visibile property to false so it won't be visible in any pages. Till now it's ok. If I enter input in the textbox and click on Search linkbutton the gridview will be loaded/present. I need to know how to make the export linkbutton visible in test page if the gridview contain values. I have tried using if(GridView1.rows.count>0) Page.Master.FindControl("LinkButtonExport").visible=true; after gridviewbind but that doesn't work (no errors too). Hope this will be more clear.