简体   繁体   English

单击显示GridView数据

[英]Display gridview data on click

I have a gridview that becomes quite long with some information that could be somewhat hidden. 我的gridview变得很长,其中包含一些可能被隐藏的信息。

Here's my asp: 这是我的asp:

<asp:GridView ID="gvLogBody" runat="server" CssClass="Grid" AllowPaging="true" AllowSorting="true" PageSize="10" AutoGenerateColumns="true">
</asp:GridView>

And here's my code behind: 这是我的代码背后:

DataSet ds = new DataSet();
ds.Tables.Add("LogBody");
ds.Tables["LogBody"].Columns.Add("timeStamp");
ds.Tables["LogBody"].Columns.Add("name");
ds.Tables["LogBody"].Columns.Add("message");
foreach (LogObject l in logLines)
{
    ds.Tables["LogBody"].Rows.Add(l.TimeStamp, l.Name, l.Message);
}
gvLogBody.DataSource = ds.Tables["LogBody"].DefaultView;
gvLogBody.DataBind();

This gives me a gridview that looks like this: 这给了我一个GridView,看起来像这样:

____________________________________________________________________________________________
|timeStamp|                      name                     |            message             |
+---------+-----------------------------------------------+--------------------------------+
|01-01-01 | someLongAndQuiteUnnecesaryNameThatIWishToHide | someMessageThatIsMoreImportant |
+---------+-----------------------------------------------+--------------------------------+

What I want is something like this: 我想要的是这样的:

_________________________________________________________
|timeStamp|    name     |            message             |
+---------+-------------+--------------------------------+
|01-01-01 | clickToShow | someMessageThatIsMoreImportant |
+---------+-------------+--------------------------------+

And once the user clicks the text, it expands / opens a popup or something. 一旦用户单击文本,它就会展开/打开弹出窗口或其他内容。

How can this be done? 如何才能做到这一点?

This piece of code will help you out. 这段代码将帮助您。

<asp:GridView ID="gvLogBody" runat="server" CssClass="Grid" AllowPaging="true" AllowSorting="true" PageSize="10" AutoGenerateColumns="false">
                    <Columns>
                        <asp:BoundField DataField="timeStamp" HeaderText="timeStamp" />
                        <asp:TemplateField HeaderText="name">
                            <ItemTemplate>
                                <input type="button" value="clickToShow" onclick="alert('<%#Eval("name") %>')" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="message" HeaderText="message" />
                    </Columns>
                </asp:GridView>

Why not use jQueryUI Dialog for good look and feel of popup 为什么不使用jQueryUI对话框以获得良好的弹出窗口外观

<head runat="server">
     <link rel="stylesheet" href="//code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.0/jquery-ui.js"></script>

  <script>
      function openPopup(name) {

          $('#<%= lblName.ClientID %>').text(name);
          $("#dialog").dialog();
          return false;
      };
  </script>
</head>

then in body 然后在体内

<asp:GridView ID="gvLogBody" runat="server" CssClass="Grid" AllowPaging="true" AllowSorting="true" PageSize="10" AutoGenerateColumns="false">
                    <Columns>
                        <asp:BoundField DataField="timeStamp" HeaderText="timeStamp" />
                        <asp:TemplateField HeaderText="name">
                            <ItemTemplate>
                                <a href="#" onclick='javascript:return openPopup("<%#Eval("name") %>");'>
                                <%#Eval("name")%>
                            </a>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="message" HeaderText="message" />
                    </Columns>
                </asp:GridView>
 <div id="dialog" title="Basic dialog">
        <asp:Label ID="lblName" runat="server" ></asp:Label>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在单击按钮时显示gridview - display gridview on button click 在GridView中显示数据 - display data in gridview 网格视图中没有显示任何数据 - No data is being display in the gridview 在Gridview中显示表数据 - Display Table data in Gridview 高图数据gridview上的每一行在按钮上显示不同的数据点击打开模式 - Highchart data each row on gridview to display different data on button click open modal 按钮点击访问GridView的数据 - accessing data of a GridView on button click 如何在.net中的单击事件上使用新窗口代替新选项卡显示gridview数据? - How to use new window instead of new tab display gridview data on click event in .net? 如何通过使用asp.net上的会话在GridView中在单击按钮时从一页显示数据到另一页 - How to display data from one page to another in gridview on button click by using session on asp.net 在单击按钮时如何在GridView中显示通过TextBox输入的值而不将数据保存到数据库? - How to display values entered via a TextBox in a GridView on button-click without saving the data to the database? 需要在下面的GridView中选择2个DropDowns on their Button Click后实时显示数据而不使用数据库 - Need to display data in GridView below after Selection of 2 DropDowns on their Button Click without using database in real time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM