Hiya, I wonder if anyone can help me with this code.
What I am trying to do, is to read records from a database and display them on a gridview. However my last column of the grid is a templateField which I display an imageButton to do something once clicked.
My problem is :
How to display the ImageButton only when a particularly Cell of the grid is value true.
I was trying to set the ImageButton to false when the value was False, but it is not working
Any help please
*******************************************************
private void BindCustomDateBookings()
{
try
{
//Gets the date chosen by the user
var customDate = Convert.ToDateTime(txtDatePicker.Text);
//Creates a connection to the database
SqlConnection connectionViewBookings = new SqlConnection(connectionString);
//Query builder
SqlDataAdapter dataAdapterViewBookings = new SqlDataAdapter(queryCustomDateBookings, connectionViewBookings);
dataAdapterViewBookings.SelectCommand.Parameters.AddWithValue("@customDate", customDate);
//Create the data that will hold the result of DB
DataSet dataSetViewTodaysBookings = new DataSet();
//open, save results and close connection
connectionViewBookings.Open();
dataAdapterViewBookings.Fill(dataSetViewTodaysBookings);
connectionViewBookings.Close();
//fill the grid with results
GridViewCustomDate.DataSource = dataSetViewTodaysBookings.Tables[0];
GridViewCustomDate.DataBind();
}
catch (SqlException SqlExceptionTomorrow)
{
Response.Write(@"<SCRIPT LANGUAGE=""JavaScript"">alert('Could not connect to the database This date bookings')</SCRIPT>");
}
}//Ends Bind Custom Date bookings
***********************************************************
And the grid view has the following coded
<asp:GridView ID="GridViewCustomDate" runat="server" AutoGenerateColumns="False" CssClass="viewBookingTable" GridLines="None"
HeaderStyle-CssClass="gridViewHeader">
<HeaderStyle CssClass="gridViewHeader" />
<RowStyle CssClass="GridViewRowStyle" />
<AlternatingRowStyle CssClass="GridViewAlternatingRowStyle " />
<Columns>
<asp:BoundField DataField="bookingID" ItemStyle-CssClass="displayGridViewID"
HeaderStyle-CssClass="displayGridViewID" >
<HeaderStyle CssClass="displayGridViewID" />
<ItemStyle CssClass="displayGridViewID" />
</asp:BoundField>
<asp:BoundField DataField="visitorName" HeaderText="Visitor Name" />
<asp:BoundField DataField="contactNo" HeaderText="contactNo" />
<asp:BoundField DataField="hostName" HeaderText="Host Name" />
<asp:BoundField DataField="roomName" HeaderText="Room Name" />
<asp:BoundField DataField="timeIn" HeaderText="Time In" />
<asp:BoundField DataField="smartCardNo" HeaderText="Smart Card No" />
<asp:TemplateField HeaderText="Required Access">
<ItemTemplate>
<asp:ImageButton ID="btnGetRequiredAccessCustomDate" runat="server"
ImageUrl="~/images/buttons/clickMe.png"
onclick="btnGetRequiredAccessCustomDate_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>