GridView Question

Discussion in 'ASP .Net' started by sjsean, Jul 25, 2010.

  1. sjsean

    sjsean Guest

    If you have suggestions on how to display I'm all ears...just learning
    gridview, detailsview, etc. and not sure how to make them display data
    in "my" layout/format. Still accustomed to using asp classic.

    I have placed a gridview on my page and want it to display address
    information. However, sometimes the address information field in the
    database will be null and I don't want the page to show a blank space.

    Modified this from a page on the net, but it either shows all the
    information including the blank line or it shows nothing and all of
    this is depends on row.cells(0).visible = false

    Example:

    Name
    address1
    address2
    city, state zip
    telephone

    for the most part address 2 would be blank/null so it should "hide".

    Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e
    As System.EventArgs) Handles GridView1.DataBound
    Dim row As GridViewRow
    For Each row In GridView1.Rows

    If String.IsNullOrEmpty(row.Cells(0).Text) Then
    row.Cells(0).Visible = False


    End If
    Exit Sub
    Next
    End Sub

    <asp:GridView ID="GridView1" runat="server"
    AutoGenerateColumns="False"
    DataSourceID="SqlDataSource1" GridLines="None">
    <Columns>
    <asp:TemplateField>

    <ItemTemplate>
    <b><asp:Label ID="Label4" runat="server" Text='<%#
    Bind("location_nickname") %>'></asp:Label></b><br />
    <asp:Label ID="Label5" runat="server" Text='<%#
    Bind("location_add1") %>'></asp:Label><br />
    <asp:Label ID="Label6" runat="server" Text='<%#
    Bind("location_add2") %>'></asp:Label><br />
    <asp:Label ID="Label1" runat="server" Text='<%#
    Bind("location_city") %>'></asp:Label>,
    <asp:Label ID="Label2" runat="server" Text='<%#
    Bind("location_state") %>'></asp:Label><br />
    <asp:Label ID="Label3" runat="server" Text='<%#
    Bind("location_zip") %>'></asp:Label><br />
    </ItemTemplate>

    </asp:TemplateField>
    </Columns>
    </asp:GridView>
     
    sjsean, Jul 25, 2010
    #1
    1. Advertising

  2. sjsean

    mick0987b Guest

    Not tested this but something like this in your label should work:

    Visible='<%# Not(Eval("location_add2") is DBNull.Value)%>'


    On Jul 25, 1:34 am, sjsean <> wrote:
    > If you have suggestions on how to display I'm all ears...just learning
    > gridview, detailsview, etc. and not sure how to make them display data
    > in "my" layout/format.  Still accustomed to using asp classic.
    >
    > I have placed a gridview on my page and want it to display address
    > information.  However, sometimes the address information field in the
    > database will be null and I don't want the page to show a blank space.
    >
    > Modified this from a page on the net, but it either shows all the
    > information including the blank line or it shows nothing and all of
    > this is depends on row.cells(0).visible = false
    >
    > Example:
    >
    > Name
    > address1
    > address2
    > city, state zip
    > telephone
    >
    > for the most part address 2 would be blank/null so it should "hide".
    >
    >     Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e
    > As System.EventArgs) Handles GridView1.DataBound
    >         Dim row As GridViewRow
    >         For Each row In GridView1.Rows
    >
    >             If String.IsNullOrEmpty(row.Cells(0).Text) Then
    >                 row.Cells(0).Visible = False
    >
    >             End If
    >             Exit Sub
    >         Next
    >     End Sub
    >
    >     <asp:GridView ID="GridView1" runat="server"
    > AutoGenerateColumns="False"
    >         DataSourceID="SqlDataSource1" GridLines="None">
    >         <Columns>
    >             <asp:TemplateField>
    >
    >                 <ItemTemplate>
    >                     <b><asp:Label ID="Label4" runat="server" Text='<%#
    > Bind("location_nickname") %>'></asp:Label></b><br />
    >                     <asp:Label ID="Label5" runat="server" Text='<%#
    > Bind("location_add1") %>'></asp:Label><br />
    >                     <asp:Label ID="Label6" runat="server" Text='<%#
    > Bind("location_add2") %>'></asp:Label><br />
    >                     <asp:Label ID="Label1" runat="server" Text='<%#
    > Bind("location_city") %>'></asp:Label>,
    >                     <asp:Label ID="Label2" runat="server" Text='<%#
    > Bind("location_state") %>'></asp:Label><br />
    >                     <asp:Label ID="Label3" runat="server" Text='<%#
    > Bind("location_zip") %>'></asp:Label><br />
    >                 </ItemTemplate>
    >
    >             </asp:TemplateField>
    >         </Columns>
    >     </asp:GridView>
     
    mick0987b, Jul 26, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nalaka

    GridView in a GridView

    Nalaka, Nov 11, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    6,640
    Nalaka
    Dec 5, 2005
  2. Replies:
    3
    Views:
    5,132
  3. Carlos Albert

    GridView in a GridView

    Carlos Albert, Dec 5, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    518
    Carlos Albert
    Dec 6, 2005
  4. =?Utf-8?B?bWdvbnphbGVzMw==?=

    GridView Hierarchical View - Gridview in Gridview

    =?Utf-8?B?bWdvbnphbGVzMw==?=, May 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    18,024
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    May 9, 2006
  5. Cirene
    Replies:
    1
    Views:
    384
    gnewsgroup
    Nov 4, 2007
Loading...

Share This Page