[英]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.