I have a ASP.NET DataGrid databinded from datatable after SQL query. The DataGrid is populated with organization employee personal info. Every row contains "Send Greeting" button. I would like to disable or hide this button if the "Email Address" cell in that row, if Email Address is empty.
My ASP code:
<table dir="rtl">
<tr>
<asp:Label ID="lbl1" runat="server" CssClass="bDayLable" Text="Select a rpw and click on button to send greeting"></asp:Label>
</tr>
<tr>
<td colspan="2">
<div id="divMyPath" runat="server"></div>
<div id="divResults" runat="server">
<asp:DataGrid ID="grdResult" runat="server" BorderColor="#CCCCCC" BorderWidth="2px" Font-Bold="False" Font-Italic="False" Font-Names="Segoe UI" Font-Overline="False" Font-Size="13px" Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Right" AutoGenerateColumns="False" Cellpadding="2" CellSpacing="2" AllowPaging="True" PageSize="4" AllowSorting="True" OnPageIndexChanged="grdResult_PageIndexChanging">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<%-- <img src="\\blabla\pictures\<%# Eval("Employeeno")%>.JPG" class="phoneBookImage" />--%>
<img src="http://intranet.somedomain.com/UserProfiles/pictures/<%# Eval("Employeeno")%>.JPG" class="phoneBookImage" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Employee Name">
<ItemTemplate>
<%# Eval("firstname") & " " & Eval("surname")%>
</ItemTemplate>
</asp:TemplateColumn>
<%-- <asp:BoundColumn DataField="EmailAdd" HeaderText="Email" DataFormatString="{0:n2}"></asp:BoundColumn>--%>
<asp:TemplateColumn HeaderText="Email">
<ItemTemplate>
<a href='mailto:<%# Eval("EmailAdd")%>'> <%# Eval("EmailAdd")%> </a>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Greeting">
<ItemTemplate>
<asp:Button ButtonType="Button" ID="btnSendGreeting" runat="server" CssClass="btnSendGreeting" Text="Send Greeting" Visible="true" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<FooterStyle BackColor="#00CC00" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" />
<HeaderStyle BackColor="Gray" Font-Bold="True" Font-Italic="False" Font-Names="Segoe UI" Font-Overline="False" Font-Size="Small" Font-Strikeout="False" Font-Underline="False" ForeColor="White" HorizontalAlign="Center" VerticalAlign="Middle" />
<SelectedItemStyle BackColor="#CCFFCC" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" />
</asp:DataGrid>
</div>
</td>
</tr>
My code behind contains the function to fill the DataGrid from Data Table. Thanks in advance!!!
Try to set the Enabled (or Visible) property like this:
<asp:Button ButtonType="Button" ID="btnSendGreeting" runat="server" CssClass="btnSendGreeting" Text="Send Greeting" Enabled='<%# Eval("EmailAdd") != null && !String.IsNullOrEmpty(Eval("EmailAdd").ToString()) %>' />
You can put all sorts of expressions between '<%# %>'.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.