I am attempting to bind a GridView to a DataSet, but it throws a Stack overflow error. When I debug it, it runs to the DataBind line just fine (it seems like its getting the right records from the server and everything), but after executing the DataBind, it jumps to the top of the method and reruns the entire method, which results in an stack overflow.
I can’t understand why this isn’t working. I’ve done something very similar with a DataTable before and it worked fine.
Here is how I’m binding
public void CreateGrid(String str)
{
try
{
sqlConnection = new SqlConnection();
sqlConnection.ConnectionString = ConfigurationManager.ConnectionStrings["MY_CONNECTION_STRING"].ConnectionString;
sqlConnection.Open();
DataSet dt = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(str, sqlConnection);
adapter.Fill(dt);
sqlConnection.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.GetType().Name + ":" + ex.Message);
}
if (dt.Tables.Count > 0)
{
Grid.DataSource = dt;
Grid.DataBind();
}
}
And here is my HTML part
<asp:GridView runat="server" ID="Grid" AutoGenerateColumns="false"
OnDataBinding="RebindGrid" AllowPaging="True" PageSize="10" AllowSorting="True" CellPadding="5"
OnPageIndexChanging="Grid_PageIndexChanging"
OnSorting="Grid_Sorting"
Width="100%" CssClass="mGrid">
<Columns>
<asp:BoundField DataField="ID" ItemStyle-Width="0%"
HeaderText="" Visible="false" SortExpression="ID"/>
</Columns>
</asp:GridView>
This looks like a problem
Every time data is bound, you rebind. We would have to see the code for RebindGrid.