Datagrid driving me mad....
-
I have the following datagrid: (Taken from aspx page) Book this room I have this code in the code behind file.... Dim TempDate As Date = ArrivalDate.SelectedDate.AddDays(NumberofNights.SelectedIndex - 1) Dim start_stay As SqlClient.SqlParameter Dim end_stay As SqlClient.SqlParameter start_stay = New SqlClient.SqlParameter end_stay = New SqlClient.SqlParameter start_stay.ParameterName = "@start_stay" end_stay.ParameterName = "@end_stay" start_stay.SqlDbType = SqlDbType.SmallDateTime end_stay.SqlDbType = SqlDbType.SmallDateTime SqlCommand.CommandType = CommandType.StoredProcedure SqlCommand.CommandText = "availability" SqlCommand.Parameters.Add(start_stay) SqlCommand.Parameters.Add(end_stay) Dim Reader As SqlClient.SqlDataReader SqlCommand.Parameters("@start_stay").Value = ArrivalDate.SelectedDate.ToLongDateString SqlCommand.Parameters("@end_stay").Value = TempDate.ToLongDateString SqlConn.Open() Reader = SqlCommand.ExecuteReader If Reader.HasRows Then AvailableNotificationLabel.Text = "The following rooms are available, please tick the box next to the room(s) you require and click next" AvailableResults.Visible = True AvailableResults.DataSource = Reader AvailableResults.DataBind() Else AvailableNotificationLabel.Text = "Sorry, we have no availability on the dates you requested." P2Next.Enabled = False End If Reader.Close() SqlCommand.Dispose() SqlConn.Close() I get this error when databind is called:- DataBinder.Eval: 'System.Web.UI.WebControls.DataGridItem' does not contain a property with the name roomnumber. Roomnumber is a field that is return
-
I have the following datagrid: (Taken from aspx page) Book this room I have this code in the code behind file.... Dim TempDate As Date = ArrivalDate.SelectedDate.AddDays(NumberofNights.SelectedIndex - 1) Dim start_stay As SqlClient.SqlParameter Dim end_stay As SqlClient.SqlParameter start_stay = New SqlClient.SqlParameter end_stay = New SqlClient.SqlParameter start_stay.ParameterName = "@start_stay" end_stay.ParameterName = "@end_stay" start_stay.SqlDbType = SqlDbType.SmallDateTime end_stay.SqlDbType = SqlDbType.SmallDateTime SqlCommand.CommandType = CommandType.StoredProcedure SqlCommand.CommandText = "availability" SqlCommand.Parameters.Add(start_stay) SqlCommand.Parameters.Add(end_stay) Dim Reader As SqlClient.SqlDataReader SqlCommand.Parameters("@start_stay").Value = ArrivalDate.SelectedDate.ToLongDateString SqlCommand.Parameters("@end_stay").Value = TempDate.ToLongDateString SqlConn.Open() Reader = SqlCommand.ExecuteReader If Reader.HasRows Then AvailableNotificationLabel.Text = "The following rooms are available, please tick the box next to the room(s) you require and click next" AvailableResults.Visible = True AvailableResults.DataSource = Reader AvailableResults.DataBind() Else AvailableNotificationLabel.Text = "Sorry, we have no availability on the dates you requested." P2Next.Enabled = False End If Reader.Close() SqlCommand.Dispose() SqlConn.Close() I get this error when databind is called:- DataBinder.Eval: 'System.Web.UI.WebControls.DataGridItem' does not contain a property with the name roomnumber. Roomnumber is a field that is return
A couple of things to check. It appears that you are trying to assign a int, float or char datatype to the "Checked" value of the checkbox. This should be a boolean datatype. In order to properly do this, you either need to add a helper function or add a new column to the query for HasRoom. If you use a helper function, you will want to pass the roomnumber value to it and if it is not null, return true. Function HasRoom(roomnumber as int) If roomnumber = '' then return false else return True End Function Then you would call this from the datagrid. Checked=<%# HasRoom(Databinder.Eval(container.dataitem, "roomnumber)) %> Hope this helps. Jeremy Oldham