GridView not Showing Headers When there are No Rows

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Harclerode

    GridView not Showing Headers When there are No Rows

    Hi,

    I'm trying to get my DataGrid to show headers and footers when no rows are
    returned from the datasource. Below is code that shows the first
    TemplateField. Is there an easy way to get at least the footer to show? I
    want to be able to insert a new row using the footer. Thanks...

    <asp:GridView ID="gvMaterials " runat="server"
    AutoGenerateCol umns="False"
    DataSourceID="d sMaterials" ShowFooter="Tru e" Width="100%"
    AutoGenerateEdi tButton="True">
    <Columns>
    <asp:TemplateFi eld HeaderText="Mat erial:">
    <FooterTemplate >
    <asp:TextBox ID="txtDescript ion"
    runat="server"> </asp:TextBox>
    </FooterTemplate>
    <EditItemTempla te>
    <asp:TextBox ID="txtDescript ion" runat="server"
    Text='<%# Bind("Descripti on") %>'></asp:TextBox>
    </EditItemTemplat e>
    <ItemTemplate >
    <asp:Label ID="lblDescript ion" runat="server" Text='<%#
    Bind("Descripti on") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateFie ld>
    [etc...]

    --
    My BizTalk blog:
    A place for me to store and share some notes about technical stuff I'm working with at the moment. The views expressed on this blog are mine alone and do not necessarily reflect the views of my employer.



  • Marc Gravell

    #2
    Re: GridView not Showing Headers When there are No Rows

    What is the actual data-source - i.e. the object you give to
    dsMaterials?

    I'm going to go out on a limb and guess that it is an ArrayList?

    To get metadata, it needs some clue to the data. There are various
    ways it can do this - the simplest is a typed indexer - i.e. a "public
    T this[int index] {get;}" for some T (doesn't have to be generics...).

    In the absense of a typed indexer, the metadata of the first item is
    used. If there aren't any items, you're scuppered.

    (there are also things like ITypedList and IListSource that are taken
    into account, but these are more complex)

    Comment

    • Marc Gravell

      #3
      Re: GridView not Showing Headers When there are No Rows

      Oops; I forgot to say! If you are using an ArrayList, the easiest way
      to fix this is to use a List<Tor BindingList<T>, or perhaps even
      just an array: T[]

      If you aren't using ArrayList, then tell us what you *are* using as
      the data-source.

      Marc

      Comment

      • Steve Harclerode

        #4
        Re: GridView not Showing Headers When there are No Rows

        I'm using a SqlDataSource that calls a stored procedure -- which contains a
        simple "SELECT * FROM Tablex WHERE ...".

        Thanks,
        Steve

        "Marc Gravell" <marc.gravell@g mail.comwrote in message
        news:decd1a39-6c12-4a55-800b-b516b321d1c2@x3 5g2000hsb.googl egroups.com...
        What is the actual data-source - i.e. the object you give to
        dsMaterials?
        >

        Comment

        • Marc Gravell

          #5
          Re: GridView not Showing Headers When there are No Rows

          Hmmm... I would have expected to work. I'm sorry, but I don't know. If
          you don't get any other takers, I would recommend posting on an asp
          group, since there will be many GridView experts there...

          Marc

          Comment

          • Sunil Lakshkar

            #6
            RE:Gridview does not display when no rows

            HI Steve,

            Gridview does not display anything if database is returning zero number of rows.
            In case you still want to display it then you can enter some dummy rows in an arraylist or dataset and then connect it to gridview and then hide that dummy row in grid , it will display only header and footer now.

            Comment

            • Steve Harclerode

              #7
              Re: RE:Gridview does not display when no rows

              Thanks for your input, Sunil. I'll try that.

              - Steve

              <Sunil Lakshkarwrote in message news:2008519130 27laksh.sunil@g mail.com...
              HI Steve,
              >
              Gridview does not display anything if database is returning zero number of
              rows.
              In case you still want to display it then you can enter some dummy rows in
              an arraylist or dataset and then connect it to gridview and then hide that
              dummy row in grid , it will display only header and footer now.

              Comment

              Working...