Server Error in '/' Application.

Object cannot be cast from DBNull to other types.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Object cannot be cast from DBNull to other types.

Source Error:


Line 145:    Protected Sub SqlDataSource_PageIndex_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs)
Line 146:        ' Set page of gridview equal to the output parameter of the stored procedure
Line 147:        GridView1.PageIndex = Convert.ToInt32(e.Command.Parameters("@Page_Index").Value)
Line 148:    End Sub
Line 149:

Source File: \\boswinfs03\home\users\web\b796\whl.ihsla\Games.aspx    Line: 147

Stack Trace:


[InvalidCastException: Object cannot be cast from DBNull to other types.]
   System.DBNull.System.IConvertible.ToInt32(IFormatProvider provider) +60
   ASP.games_aspx.SqlDataSource_PageIndex_Selected(Object sender, SqlDataSourceStatusEventArgs e) in \\boswinfs03\home\users\web\b796\whl.ihsla\Games.aspx:147
   System.Web.UI.WebControls.SqlDataSourceView.OnSelected(SqlDataSourceStatusEventArgs e) +126
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +2929
   System.Web.UI.WebControls.SqlDataSource.Select(DataSourceSelectArguments arguments) +29
   ASP.games_aspx.Recalc_PageIndex() in \\boswinfs03\home\users\web\b796\whl.ihsla\Games.aspx:164
   ASP.games_aspx.Page_Load(Object sender, EventArgs e) in \\boswinfs03\home\users\web\b796\whl.ihsla\Games.aspx:19
   System.Web.UI.Control.OnLoad(EventArgs e) +108
   System.Web.UI.Control.LoadRecursive() +90
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1533


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4690.0