We help IT Professionals succeed at work.

asp.net, GridView, C#

Webboy2008 used Ask the Experts™
Two questions based on the following aspx codes in c#

1. If CertificateStatusDescription = "Active" then
  PrintCertificate Visible = true
  PrintCertificate Visible = False

2. <asp:Button runat="server" ID="PrintCertificate"  Text="Print" />
     How can I carry ApplicationId And Add OnClick Event...so inside of Onclick Event,
 I can add some codes there?


<asp:GridView ID="GridView_CertificateHistory" runat="server"
    AutoGenerateColumns="False" CellPadding="4"
    DataSourceID="SqlDataSource_CertificateHistory" ForeColor="#333333"
    GridLines="None" Width="800"
    <RowStyle BackColor="#EFF3FB" />
        <asp:BoundField DataField="HolderFirstName" HeaderText="First Name"
            SortExpression="HolderFirstName" />
        <asp:BoundField DataField="HolderLastName" HeaderText="Last Name"
            SortExpression="HolderLastName" />
        <asp:BoundField DataField="ApplicationId" HeaderText="ApplicationId"
            SortExpression="ApplicationId" />
        <asp:BoundField DataField="Created_Date" HeaderText="Created Date"
            SortExpression="Created_Date" />
        <asp:BoundField DataField="CertificateStatusDescription"
            HeaderText="Certificate Status"
            SortExpression="CertificateStatusDescription" />            
        <asp:BoundField DataField="MemberId" Visible="false" HeaderText="MemberId"
            SortExpression="MemberId" />
                <asp:Button runat="server" ID="PrintCertificate"  Text="Print" />
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <EditRowStyle BackColor="#2461BF" />
    <AlternatingRowStyle BackColor="White" />
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Update your template field with following:

<asp:TemplateField>                                            <ItemTemplate>                                                                                                 
        <asp:LinkButton ID="PrintCertificate" runat="server" 
        Visible='Convert.ToBoolean(<%# Convert.ToString(Eval("CertificateStatusDescription")) == 'Active' ? true : false %>)' Text="Print" CommandArgument="ApplicationId" />

Open in new window

Now Print button will be visible automatically with matching condition and if it visible, you will get ApplicationId as its CommandArgument in Click event, because we have passed CommandArgument="ApplicationId" for the same button.

Hope this helps you.


1. Your code has alert message:Parser Error Message: The server tag is not well formed.
2. Please show me how to carry the applicationId, and open new url
For first one:
Make 'Active' to "Active". (Single quote to double)

Can you pl.explain more what exactly you want to do on click of this Print button?
So that we can provide you appropriate solution.


Follow your instruction for the first one and get the following error msg.

Cannot create an object of type 'System.Boolean' from its string representation 'Convert.ToBoolean(<%# Convert.ToString(Eval("CertificateStatusDescription")) == "Active" ? true : false %>)' for the 'Visible' property.
Try by updating following line:

Convert.ToBoolean(<%# Convert.ToString(Eval("CertificateStatusDescription")) == "Active" ? "true" : "false" %>)

Basic idea behind it, is nothing but we will assign Boolean value to Visible property depending upon "CertificateStatusDescription" value.


An alert message shown....are you sure you know how to resolve this?

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Cannot create an object of type 'System.Boolean' from its string representation 'Convert.ToBoolean(<%# Convert.ToString(Eval("CertificateStatusDescription")) == "" ? "true" : "false" %>' for the 'Visible' property.