从数据库中选择,从项目中制作图标

发布于 2024-09-10 04:13:13 字数 644 浏览 4 评论 0原文

我想做的基本上就是这张照片所显示的内容。 替代文本

当我从树视图中选择某些内容时,它会将一个参数传递给 linq 命令,该命令从数据库中选择一些数据。对于选择中的每个项目,我想制作一个图标和一个文本来表示该项目是文件夹还是文件。 当我推送图标或链接时,我希望它执行与推送树视图相同的操作,将参数传递给 linq 命令,该命令再次从数据库中选择并填充占位符。

我现在这样做的方法是在 runtima 中制作一个包含 ImageButton 和 LinkBut​​ton 的面板。然后我将面板添加到 ContentPlaceHolder。 问题在于,每次我选择新内容时它都会执行此操作,而且如果按下图标或链接按钮(仅从树视图中按下图标或链接按钮),我也无法使其工作。

我可以使用一些控制器和 CSS 来获得图标的外观吗? 还有其他更好的方法吗?

这与 Windows 中的资源管理器使用的系统基本相同,树视图仅显示文件夹,但窗口显示文件夹和文件。当我单击一个文件夹时,该文件夹将打开,主窗口中将填充该文件夹内的项目。如果我单击一个文件,编辑器将打开并显示该文件的内容。

What I'm trying to do is basicly what this photo shows.
alt text

When I select something from the treeview it passes a parameter to a linq command that selects some data from the database. For every item in the selection I want to make a Icon and a text that represents if the item is a folder or a file.
When I push the Icon or the Link i want it to do the same as i would push the treeview, pass a parameter to a linq command that selects again from the database and populates the placeholder.

The way I'm doing this now is to make at runtima a Panel that holds the ImageButton and LinkButton. Then i add the Panel to the ContentPlaceHolder.
The problem with this that it does it every time i select something new and also i cant get it to work if the push the icon or the linkbutton, only the from the treeview.

Could i use some controller and css to get this look for the Icons ?
Is there another better way ?

This is basicly the same system as the Explorer uses in Windows, Treeview shows only the folder but the window shows the folders and files. When i click a folder that folder opens up and the main window is populated with items that are inside that folder. If i click a file a editor opens up with the contents of the file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

老子叫无熙 2024-09-17 04:13:13

不确定我是否 100% 理解你的问题,但我想我明白了要点。

我假设您首先需要文件夹,然后是文件。我将在此区域中创建两个中继器,一个用于保存文件夹图像和链接按钮,另一个用于文件图像和链接按钮。

将 linq 命令分解为两个查询,一个用于获取文件夹,另一个用于获取文件。然后只需将中继器绑定到相应的中继器即可。

下面是一些可以帮助您入门的代码:

<asp:Repeater ID="rptFolders" runat="server" OnItemCommand="rptFolders_ItemDataBound">
    <ItemTemplate>
        <div>
            <asp:ImageButton ID="btnImage" runat="server" />
            <asp:LinkButton ID="btnLink" runat="server" />
        </div>
    </ItemTemplate>
</asp:Repeater>

调用 DataBind() 后的代码:

protected void rptFolders_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        Book book = (Book)e.Item.DataItem; //Or whatever your passing

        ImageButton btnImage = e.Item.FindControl("btnImage");
        LinkButton btnLink = e.Item.FindControl("btnLink");

        btnLink.Text = book.Name;

        btnLink.Click += new EventHandler(FolderClicked);
        btnImage.Click += new ImageClickEventHandler(FolderClicked);
    }
}

显然,您可以使用 Click 事件执行任何您想要的操作,只需将这些添加到其中即可。

我可能会创建一个文件夹和文件控件并使用它们而不是图像按钮/链接按钮组合,这样我就可以存储有关文件夹/文件的更多信息以便稍后访问它们,而无需执行另一个查询来获取 ID 或其他内容。但有一百万种方法,选择你认为最好的一种。

如果您需要此解决方案的更多指导,或者我不明白您的问题,请告诉我。

快乐编码...

Not sure I understand you question 100% but I think I got the gist.

I'm assuming that you want the folders first, then the files. I would create two repeaters in this area, one to hold the Folder Image and link buttons, and the other for the file image and link buttons.

Break your linq command into two queries, one to get the folders and one for files. Then just bind the repeaters to the corresponding repeaters.

Here's a bit of code to get you started:

<asp:Repeater ID="rptFolders" runat="server" OnItemCommand="rptFolders_ItemDataBound">
    <ItemTemplate>
        <div>
            <asp:ImageButton ID="btnImage" runat="server" />
            <asp:LinkButton ID="btnLink" runat="server" />
        </div>
    </ItemTemplate>
</asp:Repeater>

And the code behind after calling DataBind():

protected void rptFolders_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        Book book = (Book)e.Item.DataItem; //Or whatever your passing

        ImageButton btnImage = e.Item.FindControl("btnImage");
        LinkButton btnLink = e.Item.FindControl("btnLink");

        btnLink.Text = book.Name;

        btnLink.Click += new EventHandler(FolderClicked);
        btnImage.Click += new ImageClickEventHandler(FolderClicked);
    }
}

You can obviously do whatever you want with Click Events, just added those in for good measure.

I would probably create a Folder and File Control and use those instead of the imagebutton / linkbutton combo, this way I could store more information about the Folder / File to access them later without having to do another query to get the ID or what not. But there are a million approaches to this, pick the one you think is best.

Let me know if you need more guidance w/ this solution, or if I didn't understand your question.

Happy Coding...

茶色山野 2024-09-17 04:13:13

抱歉,必须添加为另一个答案。下面是文件夹用户控件的快速示例。

创建您的控件...按照您想要的格式。

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="FolderButton.ascx.cs" Inherits="FolderButton" %>
<div>
    <asp:ImageButton ID="btnImage" runat="server" ImageUrl="yourfolder.jpg" />
    <asp:LinkButton ID="btnTitle" runat="server" />
</div>

将属性和单击事件添加到后面的代码中(不要忘记在单击图像和链接按钮时触发单击事件):

public partial class FolderButton : System.Web.UI.UserControl
{
    public int DatabaseId { get; set; }
    public string Name { get; set;}  // you can even set your linkbutton text here. 

    public event EventHandler Click;
}

创建文件夹按钮控件的转发器:

 <asp:Repeater ID="rptFolders" runat="server" OnItemDataBound="rptFolders_ItemDataBound">
            <ItemTemplate>
                <uc1:FolderButton ID="FolderButton1" runat="server" />
            </ItemTemplate>
        </asp:Repeater>

在数据绑定上设置文件夹 ID:

protected void rptFolders_ItemDataBound(object sender, RepeaterItemEventArgs e)        
{        
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)        
    {        
        Book book = (Book)e.Item.DataItem; //Or whatever your passing        

        FolderButton btnFolder = e.Item.FindControls("FolderButton1");

        btnFolder.Name=book.Name;
        btnFolder.DatabaseId=book.Id;

        btnFolder.Click += new EventHandler(FolderClicked);        
    }        
}     

最后,您可以执行任何操作想了解该活动请点击:

     void FolderClicked(object sender, EventArgs e)
{
     int id = ((FolderButton)sender).DatabaseId;

     /// Do something with your Id
}

如果有任何不清楚的地方,请告诉我。这只是一个快速徒手示例,因此请原谅任何拼写错误或不良做法...代码仅用于演示目的。

Sorry had to add as another Answer. Here's a quick sample of the folder user control.

Create your Control... Format however you want.

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="FolderButton.ascx.cs" Inherits="FolderButton" %>
<div>
    <asp:ImageButton ID="btnImage" runat="server" ImageUrl="yourfolder.jpg" />
    <asp:LinkButton ID="btnTitle" runat="server" />
</div>

Add Properties and Click Event to the Code Behind (don't forget to fire the click event when your image and link buttons are clicked):

public partial class FolderButton : System.Web.UI.UserControl
{
    public int DatabaseId { get; set; }
    public string Name { get; set;}  // you can even set your linkbutton text here. 

    public event EventHandler Click;
}

Create your Repeater of the FolderButton Controls:

 <asp:Repeater ID="rptFolders" runat="server" OnItemDataBound="rptFolders_ItemDataBound">
            <ItemTemplate>
                <uc1:FolderButton ID="FolderButton1" runat="server" />
            </ItemTemplate>
        </asp:Repeater>

Set Folder Id on DataBinding:

protected void rptFolders_ItemDataBound(object sender, RepeaterItemEventArgs e)        
{        
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)        
    {        
        Book book = (Book)e.Item.DataItem; //Or whatever your passing        

        FolderButton btnFolder = e.Item.FindControls("FolderButton1");

        btnFolder.Name=book.Name;
        btnFolder.DatabaseId=book.Id;

        btnFolder.Click += new EventHandler(FolderClicked);        
    }        
}     

Lastly you can then do whever you want on the event Click:

     void FolderClicked(object sender, EventArgs e)
{
     int id = ((FolderButton)sender).DatabaseId;

     /// Do something with your Id
}

Let me know if anything is unclear. This is just a quick freehand sample, so forgive any typos or bad practices... code is just for demostration purposes only.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文