ASP.NET Listview->点击行向>执行操作 [英] ASP.NET Listview->Click Row->Perform action

查看:121
本文介绍了ASP.NET Listview->点击行向>执行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助,下面的内容。

I need some help with the following.

我有一个列表视图,我充满了code-背后:

I have a list view that I fill with code-behind:

Linq-> SQL:

Linq->Sql:

        ListView1.DataSource = from x in database.ITEMS
                               select x;
        ListView1.DataBind();

项内容:


  • ID

  • 名称

  • 数量

我只显示的字段的名称:

I only show the name of the fields:

        <tr>
            <td>
                <asp:Label ID="nameLabel" runat="server" Text='<%# Eval("Name") %>' />
            </td>
        </tr>

假设我在数据库中有25行,我充满了25行列表视图。接下来是什么,我需要帮助。用户需要点击25名(完整的行)中的一个,并重新导向到该行的内容被显示的页面。因此,可以说有人点击汽车总动员,他会被重定向,他将看到:你有选择的车,汽车有19的ID和6数量

Assuming I have 25 rows in the database, I fill the list view with 25 rows. Next is what I need help with. The user needs to click one of the 25 names (complete row) and redirects to a page where the content of that row is showed. So lets say someone clicks on "Cars", he'll be redirected and he will see: You have selected Cars, Cars has an ID of 19 and a Quantity of 6.

我已经浏览互联网,但我无法找到解决方案,我能理解。我是怎样的一个小白,当谈到列出的观点和其它数据显示方法。

I have browsed the Internet already but I am having trouble finding solutions that I can understand. I am kind of a noob when it comes to list views and other data displaying methods.

我的2个问题:


  1. 如何,我开始当我点击一行(而不是一个按钮或该行中的链接)一个事件?

  2. 当我点击一行,并开始活动,我怎么能检查被点击哪一个?

  1. How do I start a event when I click a row (and not a button or a link in that row)?
  2. When I click a row and start a event, how can I check which one was clicked?

我希望有人能向我解释这是怎么在一个用户友好的小白样的方式完成或重定向我一个教程讨论我的问题的,并以用户友好的方式。先谢谢了。

I hope someone can explain to me how this is done in a user friendly noob kind of way or redirect me to a tutorial discussing my issue's and also in a user friendly way. Thanks in advance.

推荐答案

确定 - 我不知道这是否是去与最好的方法(我会感兴趣的其他什么想)......但是这会工作

Ok - I am not sure if this is the best way to go with this (I'll be interested what other think)... but this will work .

更新您的列表视图,以这样的:

Update your listview to something like this:

        <script type="text/javascript">
            // simple redirect to your detail page, passing the selected ID 
            function redir(id) {
                window.location.href = "mydetailpage.aspx?id=" + id;
            }
        </script>
        <table>
        <asp:ListView ID="ListView1" runat="server">
            <ItemTemplate>
                <tr onclick="redir('<%# Eval("ID") %>');">
                    <td>
                        <asp:Label ID="nameLabel" runat="server" Text='<%# Eval("Name") %>' />
                    </td>
                </tr>
            </ItemTemplate>
        </asp:ListView>
        </table>

然后创建另一个页面显示您的详细信息(例如mydetailpage.aspx) - 这应该重新查询数据库和显示等领域,给出了查询字符串传递的ID

Then create another page to show your detail (e.g. mydetailpage.aspx) - this should requery your database and show the other fields, given the id passed in the querystring.

这篇关于ASP.NET Listview-&gt;点击行向&GT;执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆