locked
autopostback of textchange inside gridview RRS feed

  • Question

  • User-1037683814 posted

    I have textboxes within a gridview that need to post back with changes for recalculation. What handles the post back? The gridview rowcommand? How do I setup the triggers?

    Below is a sample of my code.

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:GridView ID="materialGridView" runat="server"
                        AutoGenerateColumns="false" >
                        <Columns>
                            <asp:BoundField DataField="MaterialTypeName" HeaderText="Material Type" />
                            <asp:TemplateField>
                                <HeaderTemplate>
                                    Quantity
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:TextBox ID="quantityTextBox" runat="server" Width ="50"
                                                 OnTextChanged="recalculateMaterialCost" AutoPostBack="true"></asp:TextBox>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField>
                                <HeaderTemplate>
                                    Material
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:DropDownList ID="materialDropDownList" runat="server" Width="200">
                                    </asp:DropDownList>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField>
                                <HeaderTemplate>
                                    Color
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:TextBox ID="colorTextBox" runat="server" Width="100" Enabled="false" ></asp:TextBox>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField>
                                <HeaderTemplate>
                                    RBK
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:RadioButton id="rbkRadioButton" runat="server" AutoPostBack="true" />
                                    <asp:TextBox ID="rbkPriceTextBox" runat="server" Width="50"
                                                 OnTextChanged="recalculateMaterialCost" AutoPostBack="true"></asp:TextBox>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField>
                                <HeaderTemplate>
                                    Wimsatt
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:TextBox ID="wimsattPriceTextBox" runat="server" Width="50"
                                                 OnTextChanged="recalculateMaterialCost" AutoPostBack="true"></asp:TextBox>
                                    <asp:RadioButton id="wimsattRadioButton" runat="server" AutoPostBack="true" />
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID ="quantityTextBox" EventName ="TextChanged" />
                    <asp:AsyncPostBackTrigger ControlID ="rbkPriceTextBox" EventName ="TextChanged" />
                    <asp:AsyncPostBackTrigger ControlID ="wimsattPriceTextBox" EventName ="TextChanged" />
    
                    <asp:AsyncPostBackTrigger ControlID ="rbkRadioButton" EventName ="CheckedChanged" />
                    <asp:AsyncPostBackTrigger ControlID ="wimsattRadioButton" EventName ="CheckedChanged" />
                </Triggers>
            </asp:UpdatePanel>

    Sunday, March 8, 2015 1:21 PM

All replies

  • User-1037683814 posted

    After more searching I think I have the postback part down to some extent. I added the following to the RowDataBound event:

                Dim asyn As New AsyncPostBackTrigger
    
                asyn.ControlID = e.Row.FindControl("quantityTextBox").UniqueID
                asyn.EventName = "TextChanged"
                materialUpdatePanel.Triggers.Add(asyn)
    
                asyn = New AsyncPostBackTrigger
                asyn.ControlID = e.Row.FindControl("materialDropDownList").UniqueID
                asyn.EventName = "TextChanged"
                materialUpdatePanel.Triggers.Add(asyn)
    
                asyn = New AsyncPostBackTrigger
                asyn.ControlID = e.Row.FindControl("materialDropDownList").UniqueID
                asyn.EventName = "SelectedIndexChanged"
                materialUpdatePanel.Triggers.Add(asyn)
    
                asyn = New AsyncPostBackTrigger With {.ControlID = e.Row.FindControl("wimsattPriceTextBox").UniqueID, .EventName = "TextChanged"}
                materialUpdatePanel.Triggers.Add(asyn)
    
                asyn = New AsyncPostBackTrigger
                asyn.ControlID = e.Row.FindControl("rbkRadioButton").UniqueID
                asyn.EventName = "CheckedChanged"
                materialUpdatePanel.Triggers.Add(asyn)
    
                asyn = New AsyncPostBackTrigger
                asyn.ControlID = e.Row.FindControl("wimsattRadioButton").UniqueID
                asyn.EventName = "CheckedChanged"
                materialUpdatePanel.Triggers.Add(asyn)

    The thing I don't get now is what event handles the postback. It doesn't appear to be the RowCommand of the GridView.

    Sunday, March 8, 2015 5:13 PM
  • User-1716253493 posted

    Try this

        protected void materialGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                TextBox quantityTextBox = (TextBox)e.Row.FindControl("quantityTextBox");
                ScriptManager1.RegisterAsyncPostBackControl(quantityTextBox);
    
    
    
    
    
    
    
    
            }
        }

    Sunday, March 8, 2015 8:34 PM
  • User-1037683814 posted

    That looks like it causes a post back, but I don't see an event that catches or handles the post back. the gridview's eventcommand event does not get fired with the postback

    Sunday, March 8, 2015 8:58 PM