【发布时间】:2011-06-19 05:42:43
【问题描述】:
我向this question 询问了 ASP.Net 中 GridView 控件的奇怪行为(我使用的是 C#)。
对于我的 GridView 中的每一行,都有一个“编辑”和“删除”链接。例如,编辑有这个javascript:__doPostBack('gvwServers','Edit$0') - 所以很明显服务器会发现有人点击了0 的gvwServers 的编辑行。
很公平。如果我单击编辑链接,我会收到一个回发,并且 GridView 被重绘,编辑按钮被替换为“更新”和“取消”按钮。标准行为。现在 - “取消”按钮有这个链接 javascript:__doPostBack('gvwServers','Cancel$0') - 正是我所期望的取消行 0 的 gvwServers。但是更新按钮有javascript:__doPostBack('gvwServers$ctl02$ctl00','')。这似乎没有任何意义。这似乎是我的例程处理更新未被触发的原因。
为什么 ASP 没有输出正确的回发参数?
我的代码可以在上面的链接中找到。
<asp:GridView ID="gvwServers" runat="server" class="gvwServers"
AutoGenerateColumns="false" OnRowEditing="gvwServers_Edit"
onrowcancelingedit="gvwServers_Cancelling" onrowdeleting="gvwServers_Deleting"
onrowupdated="gvwServers_Updated" onrowupdating="gvwServers_Updating"
AutoGenerateEditButton=true AutoGenerateDeleteButton=true>
<columns>
<asp:CommandField ShowEditButton="true" />
<asp:CommandField ShowDeleteButton="true" />
<asp:BoundField DataField="intServerID" visible="false" />
<asp:TemplateField HeaderText = "Server Name">
<ItemTemplate>
<asp:Label ID="lblServerName" runat="server" Text='<%# Bind("txtName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtServerName_Edit" runat="server" Text='<%# Bind("txtName") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Key">
<ItemTemplate>
<asp:Label ID="lblAppKey" runat="server" Text='<%# Bind("txtApplicationKey") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtAppKey_Edit" runat="server" Text='<%# Bind("txtApplicationKey") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Connection String">
<ItemTemplate>
<asp:Label ID="lblConnString" runat="server" Text='************'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtConnString_Edit" Width="300px" Height="100px" Text='<%# Bind("txtConnectionString")%>' TextMode="MultiLine" ></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</columns>
</asp:GridView>
【问题讨论】:
-
你能显示你所有的gridview代码吗? (上面的链接只显示编辑/删除)可能是一些简单的忽略。
-
@Wil 已更新标记
标签: c# asp.net gridview postback markup