Click here to Skip to main content
15,924,452 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
<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
        }
Posted
Comments
Your codes are not posted correctly.
Please Improve.
Member 9782903 23-Feb-13 12:06pm    
I have resubmitted code. OnTextChanged Event does not fire. Have a break point but it is never reached.

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
 
Share this answer
 
Comments
Thomas Daniels 23-Feb-13 12:07pm    
You can improve your question using the "Improve question" button.
Issue was with the page load event. Added if(!Page.IsPostBack) for page load event which allowed Text Changed event to fire.
 
Share this answer
 
hi !!!!! Check this link

TextBox Change Event Inside GridView[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900