nTextChanged事件未触发AutoPostback设置为

nTextChanged事件未触发AutoPostback设置为

本文介绍了Gridview模板文本框onTextChanged事件未触发AutoPostback设置为True的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<asp:GridView ID="gvBillets" runat="server"  AutoGenerateColumns="false" OnRowDataBound="gvBillets_RowDataBound"  OnRowCommand="gvBillets_RowCommand"
                 DataKeyNames="BIN"  >
                    <Columns>
                        <asp:TemplateField HeaderText="Pri" ItemStyle-Width="20px" >
                            <ItemTemplate>
                               <asp:TextBox ID="tbPref" runat="server"  Width="20px" style="text-align:center" Text='<%# Eval("Preference") %>'   OnTextChanged="tbPref_TextChanged" AutoPostBack='true' ></asp:TextBox>
                                <itemstyle horizontalalign="Center"></itemstyle>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField ItemStyle-Width="40%" HeaderText="Details">
                            <ItemTemplate>
                                <a id="A3"  önclick="javascript:OpenBilletDetailsDialog('<%# Eval("bin") %>'); return false;"
                                    href=#><%# Eval("billet_name") %></a>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField ItemStyle-Width="40%" HeaderText="Unit Name" ReadOnly="true" DataField="unit_name" />
                        <asp:BoundField ItemStyle-Width="5%" HeaderText="RBSC" ReadOnly="true" DataField="rbsc" />
                        <asp:BoundField ItemStyle-Width="5%" HeaderText="Desig" ReadOnly="true" DataField="desig" />
                        <asp:BoundField ItemStyle-Width="5%" HeaderText="Rank" ReadOnly="true" DataField="rank_desc" />
                        <asp:ButtonField ButtonType="Link" CommandName="Remove"  ItemStyle-HorizontalAlign="Center"  ItemStyle-CssClass="linkoff"   HeaderText="Remove" Text="X"/>
                        <asp:BoundField DataField="BIN" Visible="false" ReadOnly="true" />


                    </Columns>
Here is the code behind.  Set Breakpoint but event never fires.

protected void tbPref_TextChanged(object sender, EventArgs e)
        {
            GridViewRow row = ((GridViewRow)((TextBox)sender).NamingContainer);
            TextBox Pri = (TextBox)row.FindControl("tbPref");
            //code to go here when pri is changed
        }

推荐答案

Here is repost of code.  tbPref_textchangedevent does not fire....

 <asp:gridview id="gvBillets" runat="server" autogeneratecolumns="false" onrowdatabound="gvBillets_RowDataBound" onrowcommand="gvBillets_RowCommand" xmlns:asp="#unknown">
                 DataKeyNames="BIN"  >
                    <columns>
                        <asp:templatefield headertext="Pri" itemstyle-width="20px">
                            <itemtemplate>
                               <asp:textbox id="tbPref" runat="server" width="20px" style="text-align:center" text="<%# Eval("Preference") %>" ontextchanged="tbPref_TextChanged" autopostback="true"></asp:textbox>
                                <itemstyle horizontalalign="Center"></itemstyle>
                            </itemtemplate>
                        </asp:templatefield>
                        <asp:templatefield itemstyle-width="40%" headertext="Details">
                            <itemtemplate>
                                <a id="A3" onclick="javascript:OpenBilletDetailsDialog('<%# Eval(" bin=") %>'); return false;">
                                    href=#><%# Eval("billet_name") %></a>
                            </itemtemplate>
                        </asp:templatefield>
                        <asp:boundfield itemstyle-width="40%" headertext="Unit Name" readonly="true" datafield="unit_name" />
                        <asp:boundfield itemstyle-width="5%" headertext="RBSC" readonly="true" datafield="rbsc" />
                        <asp:boundfield itemstyle-width="5%" headertext="Desig" readonly="true" datafield="desig" />
                        <asp:boundfield itemstyle-width="5%" headertext="Rank" readonly="true" datafield="rank_desc" />
                        <asp:buttonfield buttontype="Link" commandname="Remove" itemstyle-horizontalalign="Center" itemstyle-cssclass="linkoff" headertext="Remove" text="X" />
                        <asp:boundfield datafield="BIN" visible="false" readonly="true" />


                    </columns>
                </asp:gridview>

Here is code behind which does not fire.

   protected void tbPref_TextChanged(object sender, EventArgs e)
        {
            GridViewRow row = ((GridViewRow)((TextBox)sender).NamingContainer);
            TextBox Pri = (TextBox)row.FindControl("tbPref");
            //code to go here when pri is changed




这篇关于Gridview模板文本框onTextChanged事件未触发AutoPostback设置为True的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 15:25