嵌套的griview ASP.NET C# [英] Nested griview ASP.NET C#
问题描述
您好。我正在尝试使用加号和减号按钮创建嵌套的gridview。当我点击按钮时,gridview没有到达正确的位置。有人可以检查我是否缺少一些东西。
这里的javascript也引用了jquery脚本
Hi. I am trying to make a nested gridview with plus and minus button. When I click on the button, the gridview does not go to its proper place. Can someone please check if I lack something here.
Here is the javascript that also referes to a jquery script
<link rel="shortcut icon" href="http://server15/DefaultDesign/favicon.png" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function pageLoad() {
$(function () {
$("[src*=minus-level1]").each(function () {
$(this).closest("tr").after("<tr><td style='border:1px solid #CCC;'></td><td style='border:1px solid #CCC;' colspan = '999999'>" + $(this).next().html() + "</td></tr>");
$(this).next().remove()
});
}
这是我的gridview设计
Here is my gridview design
<asp:GridView id="gvTransactionsMain" runat="server" CellPadding="3" AutoGenerateColumns="false" OnRowDataBound="gvTransactions_RowDataBound" Width="1006px" EmptyDataText="No Transaction found in the database.">
<Columns>
<asp:TemplateField ItemStyle-Width="16px" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle">
<ItemTemplate>
<asp:ImageButton ID="imgLevel1" runat="server" CommandArgument="Show" ImageUrl="~/Images/GridViewButtons/plus-level1.png" Width="16px" Height="16px" OnClick="imgLevel1_Click" />
<asp:HiddenField ID="hdnTrxNum" runat="server" Value='<%# DataBinder.Eval(Container.DataItem,"TrxNum") %>' />
<asp:Panel ID="pnlLevel1" runat="server" Style="position:relative;" Visible="false">
<div style="padding:5px">
<asp:GridView ID="gvTransactionsDet" runat="server" CellPadding="3" AutoGenerateColumns="false" EmptyDataText="No Transaction found in the database.">
<Columns>
<asp:TemplateField HeaderText="Trx Date" ItemStyle-Width="70px" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblDate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"TrxDate","{0:MM/dd/yyyy}") %>'></asp:Label>
<asp:HiddenField ID="hdnTransNumber" runat="server" Value='<%# Eval("TrxNum") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</Column>
</asp:GridView>
这是处理加号按钮的imgLevel1_Click事件
Here is the imgLevel1_Click event that handles the plus button
protected void imgLevel1_Click(object sender, EventArgs e)
{
ImageButton imgShowHide = sender as ImageButton;
GridViewRow row = imgShowHide.NamingContainer as GridViewRow;
if (imgShowHide.CommandArgument == "Show")
{
imgShowHide.CommandArgument = "Hide";
imgShowHide.ImageUrl = "~/Images/GridViewButtons/minus-level1.png";
row.FindControl("pnlLevel1").Visible = true;
}
else
{
row.FindControl("pnlLevel1").Visible = false;
imgShowHide.ImageUrl = "~/Images/GridViewButtons/plus-level1.png";
imgShowHide.CommandArgument = "Show";
}
}
我的尝试:
我尝试了上面的代码,第二级gridview出现在带有加号/减号按钮的第一列。
What I have tried:
I tried the above codes and it the 2nd level gridview appears on the first column with the plus/minus button.
推荐答案
( function (){
( [src * = minus-level1])。each( function (){
("[src*=minus-level1]").each(function () {
( this )。nearest( tr )。after( < tr>< td style ='border:1px solid #CCC; '>< / td>< td style ='border:1px solid #CCC;'colspan ='999999'> +
(this).closest("tr").after("<tr><td style='border:1px solid #CCC;'></td><td style='border:1px solid #CCC;' colspan = '999999'>" +
这篇关于嵌套的griview ASP.NET C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!