2
Answers

Hide button based on SQL query

Mike

Mike

14y
2k
1

Hi
I am trying to write a c# asp.net web app that shows which SQL jobs are running. The web app has start and stop buttons but I only want to show the start button if the job is stopped or show the stop button if the job is currently running. So how do I hide buttons based on the results of a SQL query.
Thanks
Mike

Attachment: codesnippet.zip

Answers (2)
2
Madhu K

Madhu K

NA 2k 446k 14y
 Initially make the buttons visibility as false.

<asp:Button ID="StartJob" runat="server"  Text="Start" CommandName="Start_Cleanup" Visible="false" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"/>
    <asp:Button ID="StopJob" runat="server"  Text="Stop" CommandName="Stop_Cleanup" Visible="false" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"/>

In Row DataBound Event

check the database for whether the job is running or stopped
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
       // Button btnStart = e.Row.FindControl("Button1") as Button;
      // Button btnStop = e.Row.FindControl("Button2") as Button;
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if(job is running)
             {
                btnStop.Visible = true;

              }
else
{
   btnStart.Visible = true;
}

}
Accepted
0
Mike

Mike

NA 57 0 14y
This put me on the right track, thanks alot Madhu. :)