Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I ahve an gridview where i am displaying a balance amount of the users if the balance amount of the specific users is ZERO then i have to disable the installment link.Here is my code...It is not working for specific
this is on
GridView RowDatabound EVENT
C#
Label lblInstallments = ((Label)e.Row.FindControl("lblInstallments"));

        dt = m.fillplanmapping();

        if (dt.Rows.Count > 0)

        {



            for (int i = 0; i < dt.Rows.Count; i++)

            {

                int amt = Convert.ToInt32(dt.Rows["balanceamount"].ToString());

                if (amt > 0)

                {

                    lblInstallments.Visible = true;

                }

                else

                {

                    lblInstallments.Visible = false;

                }

            }

        }

Error: I am getting links to all the rows where i have a balanceamount as ZERO for row 3 & 4 how to ge this...any soln...
Posted
Comments
kk2014 12-Dec-12 3:17am    
hiplease paste your .aspx page and .aspx.cs page code. i mean paste whole code. so i can trace it easily...
kk2014 12-Dec-12 3:25am    
and i don't fine your link hide code. you are hiding your label only...

1 solution

Hi kakadiya...
Please have a look in my code & my requirement is to display a link in a gridview only for those customers whose balance amount is greater than zero...

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
Label lblInstallments = ((Label)e.Row.FindControl("lblInstallments"));
dt = m.fillplanmapping();
if (dt.Rows.Count > 0)
{

for (int i = 0; i < dt.Rows.Count; i++)
{
int amt = Convert.ToInt32(dt.Rows[i]["balanceamount"].ToString());
if (amt > 0)
{
lblInstallments.Visible = true;
}
else
{
lblInstallments.Visible = false;
}
}
}
}

.aspx page

XML
<asp:GridView ID="GridView1" runat="server" DataKeyNames="id"
             AutoGenerateColumns="False" AllowPagig="True"  HeaderStyle-BackColor="#FFAA2B" HeaderStyle-ForeColor="White" RowStyle-BackColor="#FFE8C4" AlternatingRowStyle-BackColor="#FFD393"
             onpageindexchanging="GridView1_PageIndexChanging"  GridLines=Horizontal
             CellPadding="6" CellSpacing="3" onrowdeleting="GridView1_RowDeleting"
             onrowdatabound="GridView1_RowDataBound" AllowPaging="True"
              PageSize="50"
             >
             <Columns>

                <asp:BoundField HeaderText="CustomerID" DataField="customerid"
                     ItemStyle-HorizontalAlign="Center" ItemStyle-Width="100"  >


                 </asp:BoundField>

          <asp:BoundField HeaderText="Plan Name" DataField="planname"
                     ItemStyle-HorizontalAlign="Center" ItemStyle-Width="250"  >


                 </asp:BoundField>
                   <asp:BoundField HeaderText="Plan Price (In Rs.)" DataField="planprice"
                     ItemStyle-HorizontalAlign="Center" ItemStyle-Width="150"  >


                 </asp:BoundField>
                 <asp:BoundField HeaderText="Balance Amount (In Rs.)" DataField="balanceamount"
                     ItemStyle-HorizontalAlign="Center" ItemStyle-Width="150"  >


                 </asp:BoundField>

                          <asp:BoundField HeaderText="Membership Date"
                     DataField="membershipdate" ItemStyle-HorizontalAlign="Center"
                     ItemStyle-Width="200"  >

                 </asp:BoundField>

                                      <asp:BoundField HeaderText="ReceiptNumber"
                     DataField="receiptno" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="350"
                >

                 </asp:BoundField>

         <asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="75" HeaderText="Installments">
         <ItemTemplate>
         <a href="planmapping.aspx?id=<%#Eval("id") %>">
         <asp:Label ID="lblInstallments" runat="server" Text="Add Installments"></asp:Label>
         </a>
         </ItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="75"  HeaderText="Edit"  >
             <ItemTemplate>
                  <a href="planmapping.aspx?id=<%# Eval("id") %>" >
                      <asp:Label ID="Label3" runat="server" Text="Edit"></asp:Label>
                  </a>
             </ItemTemplate>




         </asp:TemplateField>

            <asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="75"  HeaderText="View"  >
             <ItemTemplate>
                  <a href="viewplandetails.aspx?id=<%# Eval("id") %>" onclick="return hs.htmlExpand(this, { objectType: 'iframe' } )">
                      <asp:Label ID="Label4" runat="server" Text="View"></asp:Label>
                  </a>
             </ItemTemplate>



         </asp:TemplateField>


               <asp:TemplateField>
               <ItemTemplate>
               </ItemTemplate>
               </asp:TemplateField>
                <asp:CommandField ButtonType="Link" HeaderText="Delete"
                     ShowDeleteButton="True"  />
             </Columns>

         </asp:GridView>
 
Share this answer
 
Comments
kk2014 12-Dec-12 5:10am    
i think your .aspx code is not completed...
u wrote
Label lblInstallments = ((Label)e.Row.FindControl("lblInstallments"));
where is lblInstallments in gridview?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900