Last post May 03, 2010 06:38 PM by sumitd
May 03, 2010 04:10 PM|csharpcoder|LINK
I'm drawing a blank on this.
I have a gridview and my 4th column will have a value of true or false, If all of my rows are false I need to show a button to send an email. What would be the best way to accomplish this? I only want to show the button if ALL rows = false in the column.
May 03, 2010 04:20 PM|ecbruck|LINK
Within the GridView.DataBound event handler, iterate through the Rows collection, retrieve the column value in question, and then determine if any of them are True. If not, then set the Visible property of your Button to True.
May 03, 2010 04:41 PM|PeteNet|LINK
two approaches: in the code, and (depending on how you're binding) using a separate query to return that value.
in the first case you would still be doing two iterations - once to find out whether there are any false and then another to set the button show/hide. but you could use the RowDataBound to find out and set the flag and then the DataBound to set the Button.
the second case would avoid two iterations. but it would depend on just how you've set up your datasource. you could probably use a Union query or two queries in one command and use NextResult() or plan two queries (or one separate query)
also, even if you use a SqlDataSource you could use an output parameter returning a value indicating true or false (with a second query following the first in the selectcommand) and then set the button in the RowDataBound.
May 03, 2010 04:58 PM|csharpcoder|LINK
that will work if any = true, I need it for all row. So if i have 4 rows and 3 = false and 1 = true, I don't want to see the button, if all 4 = true, then show me the button.
May 03, 2010 06:38 PM|sumitd|LINK
Add a gridview and a button which will be invisible initially
<asp:GridView ID="GridView1" OnRowDataBound="GridView1_DataBound" runat="server" AutoGenerateColumns="False">
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="Comments" HeaderText="Comments" />
<asp:Button ID="btnDisplay" runat="server" Text="Success" Visible="false" />
Add below lines of code in the class of codebehind file
static Boolean flag = false;
protected void Page_Load(object sender, EventArgs e)
GridView1.DataSource = GetData();
private DataTable GetData()
DataTable dt = new DataTable("Data");
protected void GridView1_DataBound(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
flag = true;
protected void Page_PreRender(object sender, EventArgs e)
btnDisplay.Visible = true;