最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

c# - ASP.NET an expandable grid view? - Stack Overflow

matteradmin5PV0评论

I've found a lot of different examples on the internet, but nothing seems to do what I'm after.

I have a DB view that generates something like this:

---------------------------------------------------
Company | Code | Total | Available | Used | Needed
---------------------------------------------------
One     |  1   |   10  |     8     |   2  |   3
One     |  2   |   5   |     5     |   0  |   5
Two     |  1   |   5   |     2     |   3  |   0
Two     |  2   |   8   |     4     |   4  |   9
Two     |  3   |   0   |     0     |   0  |   0
---------------------------------------------------

But I'm really after something to summarise all the rows by Company, and be able to expand to view details as needed.

Similar to:

------------------------------------------------------
    Company        | Total | Available | Used | Needed
------------------------------------------------------
[+] One            |   15  |     13    |   2  |   8
------------------------------------------------------
[-] Two       Code |   13  |     6     |   7  |   9
------------------------------------------------------
            |  1   |   5   |     2     |   3  |   0
            |  2   |   8   |     4     |   4  |   9
            |  3   |   0   |     0     |   0  |   0
------------------------------------------------------

I've tried building a gridview within a gridview to poor result.

I have a view which generates the panys and the summary information if it can't be done with JavaScript which is how I assumed it could be done.

I'm just looking for a free control or some bright idea in how I can otherwise acplish this. New to ASP.NET so there might be something simple I'm missing.

Thanks

I've found a lot of different examples on the internet, but nothing seems to do what I'm after.

I have a DB view that generates something like this:

---------------------------------------------------
Company | Code | Total | Available | Used | Needed
---------------------------------------------------
One     |  1   |   10  |     8     |   2  |   3
One     |  2   |   5   |     5     |   0  |   5
Two     |  1   |   5   |     2     |   3  |   0
Two     |  2   |   8   |     4     |   4  |   9
Two     |  3   |   0   |     0     |   0  |   0
---------------------------------------------------

But I'm really after something to summarise all the rows by Company, and be able to expand to view details as needed.

Similar to:

------------------------------------------------------
    Company        | Total | Available | Used | Needed
------------------------------------------------------
[+] One            |   15  |     13    |   2  |   8
------------------------------------------------------
[-] Two       Code |   13  |     6     |   7  |   9
------------------------------------------------------
            |  1   |   5   |     2     |   3  |   0
            |  2   |   8   |     4     |   4  |   9
            |  3   |   0   |     0     |   0  |   0
------------------------------------------------------

I've tried building a gridview within a gridview to poor result.

I have a view which generates the panys and the summary information if it can't be done with JavaScript which is how I assumed it could be done.

I'm just looking for a free control or some bright idea in how I can otherwise acplish this. New to ASP.NET so there might be something simple I'm missing.

Thanks

Share Improve this question asked Aug 21, 2009 at 21:26 JakJak 752 silver badges7 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

You might have better luck with the ListView control.

Matt Berseth has a post on using the ListView control to create this functionality.

Here is a sample with an Accordion, but you could use something else:

Markup:

<ajax:Accordion ID="Accordion1" runat="Server" 
    SelectedIndex="0" 
    HeaderCssClass="accordionHeader"
    HeaderSelectedCssClass="accordionHeaderSelected" 
    ContentCssClass="accordionContent"
    AutoSize="None" FadeTransitions="true" 
    TransitionDuration="250" FramesPerSecond="40"
    RequireOpenedPane="false" SuppressHeaderPostbacks="true">
    <HeaderTemplate><%# Eval("Key")%></HeaderTemplate>
    <ContentTemplate>
    <asp:ListView runat="server" ID="MyListView" DataSource='<%# Eval("Values") %>'> 
        <LayoutTemplate> 
            <table style="width:75%"> 
                <tr> 
                    <th>Code</th> 
                    <th>Total</th>
                </tr> 
                <asp:PlaceHolder ID="itemPlaceholder" runat="server" /> 
            </table> 
        </LayoutTemplate> 
        <ItemTemplate>
            <tr> 
                <td><%# Eval("Code")%></td> 
                <td><%# Eval("Total")%></td>
            </tr> 
        </ItemTemplate> 
    </asp:ListView> 

    </ContentTemplate>
</ajax:Accordion>

Code-behind:

public class Company
{
    public string CompanyName;
    public int Code, Total;
    public Company(string pany, int code, int total)
    {
        this.CompanyName = pany; this.Code = code;
        this.Total = total;
    }
}

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        var Companies = new Company[] {
            new Company("One", 1, 10),
            new Company("Two", 1, 5),
            new Company("Two", 2, 8)
        };

        Accordion1.DataSource = Companies
            .GroupBy(c => c.CompanyName, c => new { Code = c.Code, Total = c.Total },
            (k, enumerable) => new { Key = k, Values = enumerable });
        Accordion1.DataBind();

    }
}
Post a comment

comment list (0)

  1. No comments so far