How hide specific rows link in Gridview

Posted by Self-Innovator under ASP.NET on 12/12/2012 | Points: 10 | Views : 6096 | Status : [Member] | Replies : 4
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
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;
}
}
}


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...

Join Hands Change lives
Thanks & Regards
Straight Edge Society



Responses

Posted by: Ranjeet_8 on: 12/12/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Try this...
Gridview Design

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="CusName" runat="server" Text='<%#Eval("YourColumnName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="BalanceAmt" runat="server" Text='<%#Eval("YourColumnName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkInstallments" runat="server">Installment</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Add this code on .CS page

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
Label lblBalanceAmount = (Label)e.Row.FindControl("BalanceAmt");
if (lblBalanceAmount != null)
{
if (lblBalanceAmount.Text.Trim() == "0")
{
LinkButton lnkInstallment = (LinkButton)e.Row.FindControl("lnkInstallments");
lnkInstallment.Visible = false;
}
}
}


Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Self-Innovator on: 12/12/2012 [Member] Bronze | Points: 25

Up
0
Down
hi rajjeet...
i have a dataset where i need to loop through the columns of the datatable with the column name as balance amount if that specific coulmn value is < 0 then i need to hide the link of only for that row...go through my previous posting with design....pls any sokn

Join Hands Change lives
Thanks & Regards
Straight Edge Society

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 12/12/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
@Self-Innovator
Bind your Balance Amount column with label control n then run the above code.
it will work.
or share your page with attachment.

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 12/13/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
@Self-Innovator
Plz Mark as Answer if post helps you.

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response