Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Datagrid driving me mad....

Datagrid driving me mad....

Scheduled Pinned Locked Moved ASP.NET
designhelplearning
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Robert Collyer
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • R Robert Collyer

      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

      J Offline
      J Offline
      Jeremy Oldham
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups