Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6221713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:10:58+00:00 2026-05-24T08:10:58+00:00

Below is my gridview <asp:GridView ID=GridView1 runat=server AutoGenerateColumns=False EnableModelValidation=True onrowdatabound=GridView1_RowDataBound onrowcommand=GridView1_RowCommand onrowdeleting=GridView1_RowDeleting> <asp:TemplateField HeaderText=Amount

  • 0

Below is my gridview

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" EnableModelValidation="True" onrowdatabound="GridView1_RowDataBound" onrowcommand="GridView1_RowCommand" onrowdeleting="GridView1_RowDeleting"> 
  <asp:TemplateField HeaderText="Amount" HeaderStyle-ForeColor="DimGray" >
<ItemTemplate>
<asp:Label ID="lblamount" runat="server" Text='Label' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Price" HeaderStyle-ForeColor="DimGray" >
<ItemTemplate>
<asp:Label ID="lblprice" runat="server" Text='Label' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>

in the RowData_BoundEvent

  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
     if (e.Row.RowType == DataControlRowType.DataRow)
        {
     Label lbl2 = (Label)e.Row.FindControl("lblamount");
      if(amount>0) {lbl2.Text = amount;} else lbl2.Text = string.Empty;

      Label lbl3 = (Label)e.Row.FindControl("lblprice");
            if(price>0) {lbl3.Text = price;} else lbl3.Text = string.Empty;

If there is no value entered either in Amount or Price , I am trying not to display the values in the gridview if the amount is not greater than zero. But still, the grid displays Amount as Label and Price as Label if the condition does not satisfy.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:10:59+00:00Added an answer on May 24, 2026 at 8:10 am

    You should use the GridViewRow’s DataItem to get these values.

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
          // Retrieve the underlying data item. In this example
          // the underlying data item is a DataRowView object. 
          DataRowView rowView = (DataRowView)e.Row.DataItem;
    
          Double amount = (Double)(rowView["amount"]);
          Double price =  (Double)(rowView["price"]);
    
          Label lblamount= (Label)e.Row.FindControl("lblamount");
          Label lblprice = (Label)e.Row.FindControl("lblprice");
    
          lblamount.Text = amount > 0 ? amount.ToString() : String.Empty;
          lblprice.Text  = price  > 0 ? price.ToString()  : String.Empty;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to populate GridView below with images: <asp:GridView ID=GrdDynamic runat=server AutoGenerateColumns=False> <Columns> </Columns>
I have a gridview like below: <asp:GridView DataKeyNames=TransactionID AllowSorting=True AllowPaging=TrueID=grvBrokerage runat=server AutoGenerateColumns=False CssClass=datatable Width=100%
<asp:GridView ID=GridView1 runat=server> <Columns> <asp:TemplateField HeaderText=FileName> <ItemTemplate> <asp:HyperLink ID=HyperLink1 runat=server NavigateUrl= Text=></asp:HyperLink> </ItemTemplate> </asp:TemplateField>
I have a Jquery Accordion and I have a asp.net GridView below that. When
I have the GridView below. I am binding to a custom datasource in the
I'm instantiating an asp:Button inside a data-bound asp:GridView through template fields. Some of the
I am using ASP.NET C# on VS2005. I have a GridView table with a
I have the the GridView's column looking like that: <Columns> <asp:TemplateField HeaderText=Opcje> <ItemTemplate> <asp:LinkButton
I created a GridView in an ASP.NET application and used the Auto Format tool
Am running asp.net application.I try to build sample site using gridview.I got compilation error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.