Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 510
  • Last Modified:

Scrollable Grid

How do I make a standard GridView scrollable in ASP.NET?
0
NigelRocks
Asked:
NigelRocks
  • 9
  • 9
5 Solutions
 
nmarunCommented:
Enclose your gridview between a div tag:

<div style="overflow:scroll; height:100px">

</div>
0
 
NigelRocksAuthor Commented:
Didn't work.  See attached code.
    <div style="overflow:scroll; height:100px">
    <asp:GridView ID="gridProducts" runat="server" 
        onselectedindexchanged="gridProducts_SelectedIndexChanged" 
        
            style="z-index: 1; left: 19px; top: 74px; position: absolute; height: 465px; width: 1028px; bottom: 0px; right: -7px;" 
            AutoGenerateSelectButton="True" Height="5px">
        <RowStyle Font-Size="Medium" Height="25px" />
        <Columns>
            <asp:CheckBoxField />
        </Columns>
        <HeaderStyle Height="5px" />
    </asp:GridView>
    </div>

Open in new window

0
 
nmarunCommented:
Remove this from the gridview and try:
style="z-index: 1; left: 19px; top: 74px; position: absolute; height: 465px; width: 1028px; bottom: 0px; right: -7px;"
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
NigelRocksAuthor Commented:
Do I put this in the DIV tag or the GridView tag?
0
 
nmarunCommented:
Make this as your div tag and remove the 'style' parameter from the gridview.
<div style="overflow:scroll; z-index: 1; left: 19px; top: 74px; position: absolute; height: 465px; width: 1028px; bottom: 0px; right: -7px">
0
 
NigelRocksAuthor Commented:
Any reason why this code would make my DropDownList disappear?
 
 
0
 
nmarunCommented:
The DDL might have been stuck under the div tag. Please post your html code.
0
 
NigelRocksAuthor Commented:
I deleted the references to the DropDownList (ddlProductCategory) and put it back in.  However, now the selected event for that control is not firing.
 
 

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Order_Create.aspx.cs" Inherits="OrderCreate" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        #form1
        {
            height: 577px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
 
    
    
 
<div style="overflow:scroll; z-index: 1; left: 19px; top: 74px; position: absolute; height: 465px; width: 1028px; bottom: 0px; right: -7px">
    <asp:GridView ID="gridProducts" runat="server" 
        onselectedindexchanged="gridProducts_SelectedIndexChanged" 
            AutoGenerateSelectButton="True" Height="68px" Width="416px">
        <RowStyle Font-Size="Medium" Height="25px" />
        <Columns>
            <asp:CheckBoxField />
        </Columns>
        <HeaderStyle Height="5px" />
    </asp:GridView>
    <asp:DropDownList ID="ddlProductCategory" runat="server" 
        onselectedindexchanged="ddlProductCategory_SelectedIndexChanged"         
        style="z-index: 1; left: 620px; top: 76px; position: absolute; height: 35px; width: 258px">
    </asp:DropDownList>
</div>
    
    
 
    <p>
        <asp:Button ID="btnCheckout" runat="server" onclick="btnCompleteOrder_Click" 
            style="z-index: 1; left: 966px; top: 40px; position: absolute; right: 80px" 
            Text="Checkout" />
    </p>
    <asp:RadioButton ID="radAllProducts" runat="server" 
        oncheckedchanged="radAirCards_CheckedChanged" 
        style="z-index: 1; left: 316px; top: 28px; position: absolute; margin-bottom: 0px; height: 21px;" 
        Text="All Products" GroupName="radProductCategory" Visible="False" />
    <asp:RadioButton ID="radLocal" runat="server" 
        style="z-index: 1; left: 195px; top: 35px; position: absolute" 
        Text="Local" oncheckedchanged="radLocal_CheckedChanged" 
        GroupName="radProductCategory" />
    <asp:RadioButton ID="radUSATelephone" runat="server" 
        style="z-index: 1; left: 432px; top: 73px; position: absolute" 
        Text="USA Telephone" GroupName="radProductCategory" Visible="False" />
    <asp:RadioButton ID="radLongDistance" runat="server" 
        style="z-index: 1; left: 200px; top: 66px; position: absolute" 
        Text="Long Distance" GroupName="radProductCategory" Visible="False" />
    <asp:RadioButton ID="radBlackberries" runat="server" 
        oncheckedchanged="radBlackberries_CheckedChanged" 
        style="z-index: 1; left: 1002px; top: 74px; position: absolute" 
        Text="Blackberries" GroupName="radProductCategory" Visible="False" />
    <p>
 
        
        
        <asp:RadioButton ID="radCloseCallAdvantage" runat="server" 
            style="z-index: 1; left: 422px; top: 30px; position: absolute" 
            Text="CloseCall Advanage" GroupName="radProductCategory" Visible="False" />
    <asp:RadioButton ID="radAirCards" runat="server" 
        oncheckedchanged="radAirCards_CheckedChanged" 
        style="z-index: 1; left: 705px; top: 47px; position: absolute; margin-bottom: 0px" 
        Text="Air Cards" GroupName="radProductCategory" Visible="False" />
    <asp:RadioButton ID="radWireless0" runat="server" 
        style="z-index: 1; left: 849px; top: 80px; position: absolute" 
        Text="Wireless" GroupName="radProductCategory" Visible="False" />
        <asp:RadioButtonList ID="radList" runat="server" 
            
            style="z-index: 1; left: 605px; top: 83px; position: absolute; height: 27px; width: 168px" 
            Visible="False">
        </asp:RadioButtonList>
    </p>
 
    </form>
</body>
</html>

Open in new window

0
 
nmarunCommented:
You are positioning the controls individually with absolute positioning. You need to re-arrange these controls so they don't overlap over each other. When I changed the position to relative, I could see a lot more controls, but again some of them are still overlapping.

A better way would be place these controls in a <table>.
0
 
NigelRocksAuthor Commented:
I didn't have to do any of that before I added the <DIV> tag.  Is this really that difficult?  I think it's time to try another IDE.
0
 
NigelRocksAuthor Commented:
This is in the HTML:

<asp:DropDownList ID="ddlProductCategory" runat="server"
onselectedindexchanged="ddlProductCategory_SelectedIndexChanged"
style="z-index: 1; left: 620px; top: 76px; position: absolute; height: 35px; width: 258px">
</asp:DropDownList>
 
This is in the code-behind:

protected void ddlProductCategory_SelectedIndexChanged(object sender, EventArgs e)
{
int productCategoryID;
string sql;
productCategoryID = Convert.ToInt32(ddlProductCategory.SelectedItem.Value);
//Load products into GridView
sql = "SELECT * FROM PRODUCT WHERE Product_Category_ID_FK=" + productCategoryID;
WebFormControls.Grids.PopulateGridView(Program.closeCallDatabase, sql, gridProducts);
//gridProducts.Columns[1].HeaderStyle.Width = 0;
//FormatProductGrid();
}
 
 
Yet, nothing happens when I select from this list.  Why?
0
 
nmarunCommented:
Change your html to:
<asp:DropDownList ID="ddlProductCategory" runat="server" AutoPostBack="true"
onselectedindexchanged="ddlProductCategory_SelectedIndexChanged"
style="z-index: 1; left: 620px; top: 76px; position: absolute; height: 35px; width: 258px">
</asp:DropDownList>
0
 
nmarunCommented:
I guess even other IDE's will give you similar results. Here's why this din't happen before:

You had placed every control in absolute position and when you added the div tag, this messed up the positioning for every other control. That's why you have to change the positioning for other controls.
0
 
NigelRocksAuthor Commented:
if I don't use absolute position, my controls lock to the grid and I can't move them around when I first create them.
 
0
 
NigelRocksAuthor Commented:
The grid still doesn't scroll.
 
0
 
NigelRocksAuthor Commented:
Now that I've taken the style off the grid, it won't move.  Do people actually design UIs in .NET?  How???
0
 
nmarunCommented:
Nigel, Here's what you need to do:

Start simple: Add only a few controls on the aspx page and see if you can get the div tag to add scroll bars. Make sure you set the DataSource property of gridProducts, if not the gridview will not be rendered. I have this page and I see the scroll bars:

<div style="overflow:scroll; height:150px;">
    <table>
        <tr>
            <td>
                <asp:GridView ID="gridProducts" runat="server" 
                        AutoGenerateSelectButton="True" Height="68px" Width="416px">
                    <RowStyle Font-Size="Medium" Height="25px" />
                    <Columns>
                        <asp:CheckBoxField />
                    </Columns>
                    <HeaderStyle Height="5px" />
                </asp:GridView>
            </td>
        </tr>
        <tr>
            <td>
                <asp:DropDownList ID="ddlProductCategory" runat="server" />
            </td>
        </tr>
    </table>
</div>
 
//code-behind
protected void Page_Load(object sender, EventArgs e)
{
    DataTable dt = new DataTable();
    dt.Rows.Add(dt.NewRow());
    dt.Rows.Add(dt.NewRow());
    dt.Rows.Add(dt.NewRow());
    dt.Rows.Add(dt.NewRow());
    dt.Rows.Add(dt.NewRow());
    dt.Rows.Add(dt.NewRow());
    dt.Rows.Add(dt.NewRow());
    dt.Rows.Add(dt.NewRow());
    dt.Rows.Add(dt.NewRow());
    dt.Rows.Add(dt.NewRow());
 
    gridProducts.DataSource = dt;
    gridProducts.DataBind();
}

Open in new window

0
 
nmarunCommented:
I'm not sure what you mean by 'it won't move'. Are you saying you want users to be able to move controls around the page?
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 9
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now