newbie question regarding Gridview

Discussion in 'ASP .Net' started by Durango2008, Apr 1, 2008.

  1. Durango2008

    Durango2008 Guest

    Hello I have a form that uses a Gridview to display data obtained from the
    database.
    The problem I am having is that the data I receive is tremendous amount of
    text.
    Each cell basically gets elongated vertically and hence the page streches
    due to this large amount of data.
    My solution is to create uniform sized cells where when you click the cell a
    multi-line textbox at the bottom will display the full data for the user to
    read through.

    My problem is the sizing of each cell.
    I am trying to set the width and height of the TemplateField so that each
    cell can be resized to a smaller size, but it does not seem to be working.
    I have also tried resizing the control items (asp:label, asp:textbox) that
    reside within the TemplateField items, but still not change.

    Here is a simplified version of code that shows what my Gridview looks like:

    <asp:panel ID="panelGV" runat="server">
    <asp:GridView ID="GridView1" runat="server" DatasourceID="sqldataABC" >
    <Columns>
    <asp:TemplateField HeaderText="Function" >
    <EditItemTemplate>
    <asp:TextBox ID="functionTB" runat="server" text="'<%# Bind("Function")
    %>'/>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:Label ID="FunctionLbl" runat="server" text="'<%# Bind("Function") %>'/>
    </ItemTemplate>
    </asp:TemplateField>
    ..
    ..
    ..
    </Columns>
    </asp:GridView>

    If anyone has any suggestion/advice I'd appreciate it.

    thank you.
     
    Durango2008, Apr 1, 2008
    #1
    1. Advertisements

  2. Hi. Use textboxes for the ItemTemplate as well. So you'll be using textboxes
    for all your data, whether you want to edit it or just display it. Textboxes
    are one-line only, and if you use css to set the width, they even truncate
    the contents to fit the width of the textbox. The problem of appearance can
    be overcome by using css to make the textbox look like a normal cell. Change
    the border-type to solid, change the background-color and the font, make the
    textbox readonly, and even onselectstart="return false" so you can't
    highlight the contents. Depending on the browser, table cells and spans may
    not be as good as textboxes in terms of keeping a fixed size.

    If you want, you could also set the title/Tooltip to the same as the
    contents (like Windows Explorer does if the column is not wide enough for
    the text). Hope this helps. If anything's unclear, just say

    Justin Dutoit
     
    Justin Dutoit, Apr 2, 2008
    #2
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.