【问题标题】:OnRowUpdating event and TextBox_TextChanged Event not firedOnRowUpdating 事件和 TextBox_TextChanged 事件未触发
【发布时间】:2017-04-04 06:52:41
【问题描述】:

我用一个链接按钮显示网格,如果我点击它,它将显示一个像对话框(弹出窗口)一样的 GridView。那个网格是,

<asp:GridView ID="HistoryGrid" runat="server" AutoGenerateColumns="false" AllowSorting="True"
        CellPadding="4" ForeColor="Black" AllowPaging="True" Font-Size="9pt" BackColor="White"
        BorderColor="#DEDFDE" Width="100%" BorderWidth="1px" GridLines="Vertical" PageSize="10" 
        OnRowEditing="HistoryGrid_RowEditing" OnRowCancelingEdit="HistoryGrid_RowCancelingEdit" OnRowUpdating="HistoryGrid_RowUpdating"
        OnRowUpdated="HistoryGrid_RowUpdated" OnRowDataBound="HistoryGrid_RowDataBound" >

HistoryGrid 有一个 Column 包含 TextBox。

<Columns>
        <asp:TemplateField><EditItemTemplate>
                <asp:TextBox ID="DateTxt" CssClass="datepick" runat="server" AutoPostBack="true" OnTextChanged="DateTxt_TextChanged" Font-Size="8.3pt" ></asp:TextBox>
                </EditItemTemplate></asp:TemplateField>

现在的问题是 TextBox_TextChanged 事件和 HistoryGrid_RowUpdating 事件没有触发。

代码背后

protected void DateTxt_TextChanged(object sender, EventArgs e)
{
 //code
}

protected void HistoryGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
 //code
}

【问题讨论】:

  • 检查 AutoEventWireup 在您的页面指令中是否为真。
  • 是的,已经是真的了

标签: c# asp.net gridview textbox


【解决方案1】:

使用ItemTemplate 而不是EditItemTemplate:

<asp:TemplateField>
    <ItemTemplate>
      <asp:TextBox ID="DateTxt" CssClass="datepick" runat="server" AutoPostBack="true" OnTextChanged="DateTxt_TextChanged" Font-Size="8.3pt" ></asp:TextBox>
    </ItemTemplate>
</asp:TemplateField>

【讨论】:

  • 感谢您的回答。不管是什么,如果我更改了 TextBox 中的文本,gridView(Popup) 就会关闭。并且事件不会被触发
猜你喜欢
  • 2012-08-25
  • 2023-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-31
  • 2013-04-09
  • 2015-07-25
相关资源
最近更新 更多