none
Gridview footer dropdownlist will not reload after insert RRS feed

  • Question

  • I have the following:
    1 - Gridview with a footer used to insert data.
    2 - The footer has a dropdownlist that is loaded via a stored procedure. 
    3 - There is also a Insert button in the footer that call a method.
    4 - The Gridview is configured to use a datasource control.

    Both the Gridview and the dropdownlist in the footer load correctly when the page loads. The insert data also works and the gridview refreshes with the new entry.
    However, after a record is inserted using the SQLdatasource INSERT command, the Gridview will add the record to the list, but the dropdown list in the footer is blank and never reloads.  I tried several suggestions on the internet with no luck.  Here is my code:

    Gridview:
      <FooterTemplate>
                          <asp:Button ID="btnInsert" runat="server" Text="Insert" OnClick="btnInsert_Click" />
      </FooterTemplate>

    <FooterTemplate>
                            <asp:DropDownList ID="ddlSelectPlayer" runat="server"
                           DataTextField="JerseyNo" DataValueField="PlayerId" AutoPostBack="True">
                           </asp:DropDownList>
    </FooterTemplate>

    SQLDatasource control:

    InsertCommand="INSERT INTO [tblStats] ([Made2Pt], [Missed2pt], [Made3pt], [Foul], [Missed3pt], [Steal], [Orb], [Drb], [Assist], [TurnOver], [Block], [GameId], [CoachId], [PlayerId], [Scorer]) VALUES (@Made2Pt, @Missed2pt, @Made3pt, @Foul,     @Missed3pt, @Steal, @Orb, @Drb, @Assist, @TurnOver, @Block, @GameId, @CoachId, @PlayerId, @Scorer)"
    SelectCommand="SELECT [StatId], [Made2Pt], [Missed2pt], [Made3pt], [Foul], [Missed3pt], [Steal], [Orb], [Drb], [Assist], [TurnOver], [Block], [GameId], [CoachId], [PlayerId], [Scorer] FROM [tblStats]"

    btnInsert_Click event:

        //Used with the SQLDataSource1 control
        protected void btnInsert_Click(object sender, EventArgs e)
        {

    SqlDataSource1.InsertParameters["PlayerId"].DefaultValue =
                ((DropDownList)StatGridview.FooterRow.FindControl("ddlSelectPlayer")).SelectedValue;
            SqlDataSource1.Insert();
            DropDownList ddlJerseyRefresh = ((DropDownList)StatGridview.FooterRow.FindControl("ddlSelectPlayer"));
            ddlJerseyRefresh.DataBind();

    also, I tested by adding a label control outside the gridview so I know the method is working.  However, I cannot get data to reload in the footer.

    Thursday, January 3, 2019 3:21 AM

Answers

  • Hi PCTony,

    This forum discusses and ask question about data platform development using ADO.NET DataSet and LINQ to DataSet, since your issue is more related to asp.net web form, I would suggest that you could post your issue on asp.net forum for suitable support.

    https://forums.asp.net/18.aspx/1?Web+Forms

    Thanks for your understanding.

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by PCTony Thursday, January 3, 2019 10:59 PM
    Thursday, January 3, 2019 5:58 AM
    Moderator