C# 重复值表gridview
我试图在gridview中使用表,但我遇到了一个问题C# 重复值表gridview,c#,asp.net,gridview,C#,Asp.net,Gridview,我试图在gridview中使用表,但我遇到了一个问题 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication4.WebForm1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xh
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication4.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$("[src*=plus]").live("click", function () {
$(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>")
$(this).attr("src", "images/minus.png");
});
$("[src*=minus]").live("click", function () {
$(this).attr("src", "images/plus.png");
$(this).closest("tr").next().remove();
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" CssClass="Grid"
DataKeyNames="ABI" OnRowDataBound="OnRowDataBound" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<img alt = "" style="cursor: pointer" src="pics/plus.png" />
<asp:Panel ID="pnlOrders" runat="server" Style="display: none">
<asp:TextBox ID="gvOrders" runat="server" CssClass = "ChildGrid" Text="aa">
</asp:TextBox>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField ItemStyle-Width="150px" DataTextField="N017" HeaderText="Contact Name"/>
<asp:BoundField ItemStyle-Width="150px" DataField="N028" HeaderText="City" />
</Columns>
</asp:GridView>
</form>
</body>
</html>
当我展开并单击按钮字段时,页面将自动重新加载,文本框中有重复的值。
怎么了?考虑将ButtonField更改为TemplateField,您可以通过aspx designer将其转换。这使您能够更清楚地了解正在发生的事情,并控制改变行为。通过添加的控件,您可以决定是否真的需要一个asp.net按钮,该按钮在单击时自动绑定以进行回发,或者您是否只需要一个静态html,而可以使用javascript进行连接。我不完全清楚您想要实现什么-这也是为什么我不能用代码示例作为答案的原因。您是否在数据绑定gridview时检查IsPostBack属性?