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.