Click here to Skip to main content
14,697,262 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello i have table(gridview) one of the columns has 2 type of value empty or leased
i want to hide all rows when they have column inside template field label with empty value


* name of the column aprtmentstatus

id name of the label [Label28]

What I have tried:

Quote:

<asp:Panel ID="Panel1" runat="server">
 <asp:Label ID="Label31" runat="server" BorderColor="Black"
BorderStyle="Dashed" Font-Bold="True" Font-Names="Adobe Devanagari"
Font-Size="70px" ForeColor="#CC0000" Text="ON-GOING CONTRACTS عقود جارية">
<asp:GridView ID="GridView1" runat="server"
AllowSorting="True" AutoGenerateColumns="False" BackColor="White"
BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4"
DataSourceID="SqlDataSource1" Height="822px" HorizontalAlign="Center"
ondatabinding="GridView1_DataBinding" onrowdatabound="GridView1_RowDataBound"
onselectedindexchanged="GridView1_SelectedIndexChanged1"
onselectedindexchanging="GridView1_SelectedIndexChanging" PageSize="7"
ShowFooter="True" style="font-size: x-large; " Width="2000px">
<AlternatingRowStyle Font-Bold="True" />
<columns>
<asp:BoundField DataField="Spare1" HeaderText="Spare1" ReadOnly="True"
SortExpression="Spare1" />
<asp:BoundField DataField="Spare2" HeaderText="Spare2" ReadOnly="True"
SortExpression="Spare2" />
<asp:BoundField DataField="Spare3" HeaderText="Spare3" ReadOnly="True"
SortExpression="Spare3" />
<asp:BoundField DataField="Spare4" HeaderText="Spare4" ReadOnly="True"
SortExpression="Spare4" />
<asp:BoundField DataField="Spare5" HeaderText="Spare5" ReadOnly="True"
SortExpression="Spare5" />
<asp:BoundField DataField="Spare6" HeaderText="Spare6" ReadOnly="True"
SortExpression="Spare6" />
<asp:BoundField DataField="details" HeaderText="تفاصيل Details" ReadOnly="True"
SortExpression="details" />
<asp:BoundField DataField="note" HeaderText="ملاحظات Note" ReadOnly="True"
SortExpression="note" />
<asp:TemplateField HeaderText="وثائق Documents" SortExpression="documents">
<edititemtemplate>
<asp:Label ID="Label15" runat="server" Text='<%# Eval("documents") %>'>

<itemtemplate>
<asp:Label ID="Label15" runat="server" Text='<%# Bind("documents") %>'>




<asp:BoundField DataField="termsofpaymneten" HeaderText="termsofpaymneten"
ReadOnly="True" SortExpression="termsofpaymneten" />
<asp:TemplateField HeaderText="طريقة الدفع Terms of Paymnet"
SortExpression="termsofpaymnet">
<edititemtemplate>
<asp:Label ID="Label14" runat="server" Text='<%# Eval("termsofpaymnet") %>'>

<itemtemplate>
<asp:Label ID="Label14" runat="server" Text='<%# Bind("termsofpaymnet") %>'>


<asp:Label ID="Label29" runat="server" Text='<%# Eval("termsofpaymneten") %>'>


<asp:BoundField DataField="aprtmentstatusen" HeaderText="aprtmentstatusen"
ReadOnly="True" SortExpression="aprtmentstatusen" />
<asp:TemplateField HeaderText="حالة الشقة Aprtment_Status"
SortExpression="aprtmentstatus">
<edititemtemplate>
<asp:Label ID="Label13" runat="server" Text='<%# Eval("aprtmentstatus") %>'>

<itemtemplate>
<asp:Label ID="Label13" runat="server" Text='<%# Bind("aprtmentstatus") %>'>


<asp:Label ID="Label28" runat="server" Text='<%# Eval("aprtmentstatusen") %>'>


<asp:BoundField DataField="amountdateen" HeaderText="amountdateen"
ReadOnly="True" SortExpression="amountdateen" />
<asp:TemplateField HeaderText="تاريخ الاستحقاق Amount_Date"
SortExpression="amountdate">
<edititemtemplate>
<asp:Label ID="Label16" runat="server" Text='<%# Eval("amountdate") %>'>

<itemtemplate>
<asp:Label ID="Label16" runat="server" Text='<%# Bind("amountdate") %>'>


---------------

<asp:Label ID="Label30" runat="server" Text='<%# Eval("amountdateen") %>'>


<asp:BoundField DataField="amountleft" HeaderText="المبلغ المستحق Amount_Left"
ReadOnly="True" SortExpression="amountleft" />
<asp:BoundField DataField="amountpaid" HeaderText="المبلغ المدفوع Amount_Paid"
SortExpression="amountpaid" />
<asp:BoundField DataField="rent" HeaderText="الايجار Amount_Rent"
ReadOnly="True" SortExpression="rent" />
<asp:BoundField DataField="noofpayemtsen" HeaderText="noofpayemtsen"
ReadOnly="True" SortExpression="noofpayemtsen" />
<asp:TemplateField HeaderText="عدد الدفعات No OF Payemts"
SortExpression="noofpayemts">
<edititemtemplate>
<asp:Label ID="Label12" runat="server" Text='<%# Eval("noofpayemts") %>'>

<itemtemplate>
<asp:Label ID="Label12" runat="server" Text='<%# Bind("noofpayemts") %>'>


<asp:Label ID="Label27" runat="server" Text='<%# Eval("noofpayemtsen") %>'>


<asp:BoundField DataField="sourceen" HeaderText="sourceen" ReadOnly="True"
SortExpression="sourceen" />
<asp:TemplateField HeaderText="مصدر الهوية ID_Source" SortExpression="source">
<edititemtemplate>
<asp:Label ID="Label11" runat="server" Text='<%# Eval("source") %>'>

<itemtemplate>
<asp:Label ID="Label11" runat="server" Text='<%# Bind("source") %>'>


<asp:Label ID="Label26" runat="server" Text='<%# Eval("sourceen") %>'>


<asp:BoundField DataField="iddateen" HeaderText="iddateen" ReadOnly="True"
SortExpression="iddateen" />
<asp:TemplateField HeaderText="تاريخ الهوية ID Date" SortExpression="iddate">
<edititemtemplate>
<asp:Label ID="Label10" runat="server" Text='<%# Eval("iddate") %>'>

<itemtemplate>
<asp:Label ID="Label10" runat="server" Text='<%# Bind("iddate") %>'>


-------------

<asp:Label ID="Label25" runat="server" Text='<%# Eval("iddateen") %>'>


<asp:BoundField DataField="idnumber" HeaderText="رقم الهوية ID_Number"
ReadOnly="True" SortExpression="idnumber" />
<asp:BoundField DataField="contractenen" HeaderText="contractenen"
ReadOnly="True" SortExpression="contractenen" />
<asp:TemplateField HeaderText="تاريخ نهاية العقد Contract_End"
SortExpression="contracten">
<edititemtemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Eval("contracten") %>'>

<itemtemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("contracten") %>'>


--------------

<asp:Label ID="Label24" runat="server" Text='<%# Eval("contractenen") %>'>


<asp:BoundField DataField="contractstarten" HeaderText="contractstarten"
ReadOnly="True" SortExpression="contractstarten" />
<asp:TemplateField HeaderText="تاريخ بداية العقد Contract_Start"
SortExpression="contractstart">
<edititemtemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Eval("contractstart") %>'>

<itemtemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("contractstart") %>'>


--------------

<asp:Label ID="Label23" runat="server" Text='<%# Eval("contractstarten") %>'>


<asp:BoundField DataField="contractnoen" HeaderText="contractnoen"
ReadOnly="True" SortExpression="contractnoen" />
<asp:TemplateField HeaderText="رقم العقد Contract No."
SortExpression="contractno">
<edititemtemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Eval("contractno") %>'>

<itemtemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("contractno") %>'>


<asp:Label ID="Label22" runat="server" Text='<%# Eval("contractnoen") %>'>


<asp:BoundField DataField="nationalityen" HeaderText="nationalityen"
ReadOnly="True" SortExpression="nationalityen" />
<asp:TemplateField HeaderText="الجنسية Nationality"
SortExpression="nationality">
<edititemtemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Eval("nationality") %>'>

<itemtemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("nationality") %>'>


<asp:Label ID="Label21" runat="server" Text='<%# Eval("nationalityen") %>'>


<asp:BoundField DataField="secondpartyen" HeaderText="secondpartyen"
ReadOnly="True" SortExpression="secondpartyen" />
<asp:TemplateField HeaderText="الطرف الثاني Second_Party"
SortExpression="secondparty">
<edititemtemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Eval("secondparty") %>'>

<itemtemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("secondparty") %>'>


<asp:Label ID="Label20" runat="server" Text='<%# Eval("secondpartyen") %>'>


<asp:BoundField DataField="firstpartyen" HeaderText="firstpartyen"
ReadOnly="True" SortExpression="firstpartyen" />
<asp:TemplateField HeaderText="الطرف الاول First_Party"
SortExpression="firstparty">
<edititemtemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("firstparty") %>'>

<itemtemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("firstparty") %>'>


<asp:Label ID="Label19" runat="server" Text='<%# Eval("firstpartyen") %>'>


<asp:BoundField DataField="apartemetnnoen" HeaderText="apartemetnnoen"
ReadOnly="True" SortExpression="apartemetnnoen" />
<asp:TemplateField HeaderText="رقم الشقة Apartemetn No."
SortExpression="apartemetnno">
<edititemtemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Eval("apartemetnno") %>'>

<itemtemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("apartemetnno") %>'>


<asp:Label ID="Label18" runat="server" Text='<%# Eval("apartemetnnoen") %>'>


<asp:BoundField DataField="Bulidingnoen" HeaderText="Bulidingnoen"
ReadOnly="True" SortExpression="Bulidingnoen" />
<asp:TemplateField HeaderText="رقم العمارة Buliding No."
SortExpression="Bulidingno">
<edititemtemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Bulidingno") %>'>

<itemtemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Bulidingno") %>'>


<asp:Label ID="Label17" runat="server" Text='<%# Eval("Bulidingnoen") %>'>




<asp:TemplateField HeaderText="الرقم No." SortExpression="No">
<edititemtemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("No") %>'>

<itemtemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("No") %>'>



<EmptyDataRowStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center"
VerticalAlign="Middle" />
<HeaderStyle BackColor="#990000" Font-Bold="True" Font-Size="XX-Large"
ForeColor="White" HorizontalAlign="Center" VerticalAlign="Middle" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<RowStyle BackColor="White" Font-Bold="True" Font-Size="18pt"
ForeColor="#330099" HorizontalAlign="Center" VerticalAlign="Middle"
BorderStyle="None" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399"
HorizontalAlign="Center" VerticalAlign="Middle" />
<SortedAscendingCellStyle BackColor="#FEFCEB" HorizontalAlign="Center"
VerticalAlign="Middle" />
<SortedAscendingHeaderStyle BackColor="#AF0101" HorizontalAlign="Center"
VerticalAlign="Middle" />
<SortedDescendingCellStyle BackColor="#F6F0C0" HorizontalAlign="Center"
VerticalAlign="Middle" />
<SortedDescendingHeaderStyle BackColor="#7E0000" HorizontalAlign="Center"
VerticalAlign="Middle" />


Posted
Updated 17-Apr-17 4:01am
Comments
[no name] 17-Apr-17 8:19am
   
You can use RowDataBound Event to check for that particular columns "empty" value and hide that row
Learn.net37 17-Apr-17 8:37am
   
can u give me sample just to do it
thank u
[no name] 17-Apr-17 8:52am
   
Will give you idea how to access RowDataBound event and data. You can make row hide here -

http://www.c-sharpcorner.com/UploadFile/1e050f/rowdatabound-event-in-gridview-in-Asp-Net/

1 solution

You can use of RowDataBound event to iterate with data rows to check your empty value and make that row hide per below.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
        //Use your column value below
        string str = e.Row.Cells[0].Text.ToString();
        // or you can try str == String.Empty in below condition as necessary.
        if(String.IsNullOrEmpty(str))
        {
            e.Row.Visible = false;
        }
    }
}
   
v2
Comments
Learn.net37 17-Apr-17 9:45am
   
no man maybe u didnt understand, i don't mean empty = (null)
i mean string Empty
[no name] 17-Apr-17 10:18am
   
String.IsNullOrEmpty will check for empty or null value for provided string variable.

I think you are checking for any particular cell value is empty then you want that row to hide, did I get correctly?
Learn.net37 17-Apr-17 12:24pm
   
no sir u still didnt understand , i mean if this value appear ex : ("leased")
hide the entire row
[no name] 17-Apr-17 13:09pm
   
Can't you update the condition you need in above code and try?
Learn.net37 17-Apr-17 13:39pm
   
if label 18="Leased" ----> this is word (leases)
row.visible="false"

something like that
[no name] 17-Apr-17 13:53pm
   
Are you looking for this -

if (e.Row.RowType == DataControlRowType.DataRow)
{
//put your control name here to get and then check for your value
Label lbl = e.Row.FindControl("Label1") as Label;
if (lbl.Text == "Leased")
{
e.Row.Visible = false;
}
}
Learn.net37 17-Apr-17 14:42pm
   
yes sir this what i need but what is control name ( u meam gridview id or sqldatasource id ?)
[no name] 17-Apr-17 15:09pm
   
Control is asp:GridView.
Learn.net37 17-Apr-17 15:31pm
   
thank u sir its working now god bless u 5 stars

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