C# 绑定到gridview中按钮的asp事件未触发
我知道其他地方也出现过类似的问题,但在查看了所有内容后,我发现没有任何帮助。我已经用头撞了好几个小时了。我在gridview中有一个asp:按钮,它不会启动;没有错误,没有其他失败,不会调用此事件 同一页面上的其他按钮(不在gridview中)起作用,而其他页面上gridview中的其他按钮(设置相同)起作用。我错过了什么,但是什么 相关。aspx(摘要): 母版页将整个内容包装在一个表单中,并添加scriptmanager等;另一个页面(共享同一母版页)可以使用此设置C# 绑定到gridview中按钮的asp事件未触发,c#,asp.net,button,gridview,updatepanel,C#,Asp.net,Button,Gridview,Updatepanel,我知道其他地方也出现过类似的问题,但在查看了所有内容后,我发现没有任何帮助。我已经用头撞了好几个小时了。我在gridview中有一个asp:按钮,它不会启动;没有错误,没有其他失败,不会调用此事件 同一页面上的其他按钮(不在gridview中)起作用,而其他页面上gridview中的其他按钮(设置相同)起作用。我错过了什么,但是什么 相关。aspx(摘要): 母版页将整个内容包装在一个表单中,并添加scriptmanager等;另一个页面(共享同一母版页)可以使用此设置 我在按钮本身上尝试了使用
我在按钮本身上尝试了使用OnClick和OnCommand的变体,没有任何更改。请注意,页面首先正确加载,这个gridview确实会被填充,等等。我已经用updatepanel>gridview>按钮将我能想到的所有东西与页面进行了比较,我看不到我遗漏了什么。救命啊 你在UpdatePanel之外尝试过吗?测试过你的代码片段,它可以工作。。。。您如何测试是否已到达
此gv_row命令。@VDWWD-Oooh,请稍候,您可能已经收到了。我试着查看函数是否在做它应该做的事情(一些SQL),但是数据没有改变(并且没有抛出错误)。所以我在页面上点击了一个文字并检查了更新,但没有看到任何变化,所以“事件未触发”。在你的提示下,这可能是两件事;页面未重新加载(所以文字更改但并没有显示),SQL出现问题(不是错误,但实际上也并没有进行更改)。经过测试,果然文字在变化,所以事件被触发。开始修复SQL,干杯!
<%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="thisPage.aspx.cs" Inherits="WebApplication2.thisPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<link href="../Content/jquery-ui.css" rel="stylesheet" />
<script src="../Scripts/jquery-ui.js"></script>
<asp:UpdatePanel runat="server" ID="thisPanel" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView runat="server" ID="thisGV" onrowcommand="thisGV_RowCommand">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID"/>
<asp:TemplateField>
<ItemTemplate>
<asp:Button runat="server" ID="confirmButton" CommandName="confirm" CommandArgument='<%# Container.DataItemIndex %>' Text="Confirm" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
No records found for those details, please try again.
</EmptyDataTemplate>
</asp:GridView>
</ContentTemplate>
<script>
$(document).ready(function () {
});
</script>
</asp:UpdatePanel>
public partial class Form8Exams : System.Web.UI.Page
{
int ID = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
loadGV();
}
}
protected void thisGV_RowCommand(Object sender, GridViewCommandEventArgs e)
{
//A bunch of things that don't get called
//Let me be clear; I've tested, and as far as I can tell
//it's not that the things here fail to work, but that
//this function doesn't get called at all.
}
protected void loadGV()
{
if (!Page.IsPostBack) // Added in desperation, but no change with or without.
{
hwHelper helper = new hwHelper();
DataTable dt = new DataTable();
dt = helper .dtget(ID, "");
if (dt.Rows.Count > 0)
{
thisGV.DataSource = dt;
thisGV.DataBind();
thisPanel.Update();
}
}
}
}