I need to execute a sql statement based on the boolean value in the column, ExemptSuperviors, however the value is not being written to the grid. Hence, I am not getting the value for the sql statement. How can I resolve this issue, please.
Even the boolean value cannot be displayed, I do need it for the sql statement.
I have:
' ExemptSupervior
.Columns.Add(New Infragistics.WebUI.UltraWebGrid.UltraGridColumn)
With .Columns(.Columns.Count - 1).Hidden = False.Header.Caption = "ExemptSupervior".Width = 25.IsBound = True.BaseColumnName = "ExemptSupervior".Key = "ExemptSupervior"End With
Along with:If e.Row.Cells(e.Row.Cells.IndexOf("ExemptSupervisor")).Value = "-1" Then <= Level of error
If (e.Row.Cells(e.Row.Cells.IndexOf("LunchTime")).Value = "3") Then do some stuff Else If (e.Row.Cells(e.Row.Cells.IndexOf("LunchTime")).Value = "6") Then do some other stuff End
I'm assuming that your "ExemptSupervisor" column becomes a Boolean value in your data source, which is likely why it's appearing as a checkbox. Assuming that this is the case, then you simply need to cast the value of your cell from an Object to a Boolean:
If CType(e.Row.Cells.FromKey("ExemptSupervisor").Value, Boolean) = False Then '<= Level of error
By the way, if you need your column to be stored in ViewState, I also suggest you add it to your grid in a different manner, as illustrated here:
' ExemptSupervior Dim colExempt As New Infragistics.WebUI.UltraWebGrid.UltraGridColumn(True).columns.Add(colExempt)With colExempt.Hidden = False.Header.Caption = "ExemptSupervior".Width = 25.IsBound = True.BaseColumnName = "ExemptSupervior".Key = "ExemptSupervior"End With
"ExemptSupervisor" is a boolean value in the database but nothing is appearing on the web grid, not a checkbox, simply an empty space. I did make the changes you suggested and again, no value is being written to the grid.
Using: If CType(e.Row.Cells.FromKey("ExemptSupervisor").Value, Boolean) = False Then I get the following error message: Object reference not set to an instance of an object
1> How do I write the Boolean value to the grid?2> How do I then capture the value to use it the the "If/Else/End" statement?
Thank you.
How are you pulling the data into .NET? What kind of data object are you using? Is the value coming into .NET as an actual boolean value? Does the database field accept null values?
If the value isn't being shown as a checkbox in the first place, then I'm suspecting that it's not coming into .NET as a boolean value either. That's the first thing we'll want to figure out.
I am using a stored procedure: Protected Sub BindugGridExceptions()
Dim SQLConnection As New SqlClient.SqlConnection Dim SQLGridCommand As New SqlClient.SqlCommand Dim SQLGridParam As SqlClient.SqlParameter
SQLConnection.ConnectionString = ConfigurationManager.ConnectionStrings("ACS").ConnectionString
SQLConnection.Open() SqlClient.SqlConnection.ClearPool(SQLConnection)
SQLGridCommand.Connection = SQLConnection SQLGridCommand.CommandType = CommandType.StoredProcedure SQLGridCommand.CommandText = "usp_ExcelReports"
With Me SQLGridParam = New SqlClient.SqlParameter SQLGridParam.ParameterName = "@LocationCode" 'DropDownList SQLGridParam.Value = .ddlLocation.SelectedValue SQLGridCommand.Parameters.Add(SQLGridParam)
SQLGridParam = New SqlClient.SqlParameter SQLGridParam.ParameterName = "@BeginDate" 'Calendar Object SQLGridParam.Value = .lblBeginDate.Text SQLGridCommand.Parameters.Add(SQLGridParam)
SQLGridParam = New SqlClient.SqlParameter SQLGridParam.ParameterName = "@EndDate" 'Calendar Object SQLGridParam.Value = .lblEndDate.Text SQLGridCommand.Parameters.Add(SQLGridParam)
Dim GridReader As System.Data.SqlClient.SqlDataReader GridReader = SQLGridCommand.ExecuteReader(CommandBehavior.CloseConnection)
If GridReader.HasRows Then
Do While (GridReader.Read()) Dim drRow As DataRow = .dsAttendance.Tables("usp_ExcelReports").NewRow For i As Int32 = 0 To .dsAttendance.Tables("usp_ExcelReports").Columns.Count - 1 drRow.Item(.dsAttendance.Tables("usp_ExcelReports").Columns(i).ColumnName) = GridReader(.dsAttendance.Tables("usp_ExcelReports").Columns(i).ColumnName) Next .dsAttendance.Tables("usp_ExcelReports").Rows.Add(drRow) Loop
.dsAttendance.Tables("usp_ExcelReports").AcceptChanges()
End If
.ugGridExceptions.DataSource = Me.dsAttendance.Tables("usp_ExcelReports").DefaultView .ugGridExceptions.DataBind()
SQLGridCommand.Dispose() SQLGridCommand = Nothing
SQLConnection.Close()
End With
End Sub
***
The database column ExemptSupervisors does not accept NULL values.
*****Protected Sub UltraWebGrid1_InitializeLayout(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebGrid.LayoutEventArgs) Handles ugGridExceptions.InitializeLayout
With Me.ugGridExceptionsMe.ugGridExceptions.DisplayLayout.Pager.AllowPaging = TrueMe.ugGridExceptions.DisplayLayout.NoDataMessage = "No employee records match your search criteria" 'message no showing up in the grid
Me.ugGridExceptions.DisplayLayout.Pager.PageSize = RecordsPerPage
.Columns.Clear() 'without columns.clear the first column is column 0 in the grid.
' UserID
.Columns.Add(New Infragistics.WebUI.UltraWebGrid.UltraGridColumn)With .Columns(.Columns.Count - 1).Width = 45.Hidden = False.Header.Caption = "User ID".IsBound = True.BaseColumnName = "UserID".Key = "UserID".AllowUpdate = Infragistics.WebUI.UltraWebGrid.AllowUpdate.RowTemplateOnlyEnd With
' Employee
.Columns.Add(New Infragistics.WebUI.UltraWebGrid.UltraGridColumn)With .Columns(.Columns.Count - 1).Width = 150.Hidden = False.Header.Caption = "Employee".IsBound = True.BaseColumnName = "Employee".Key = "Employee".AllowGroupBy = Infragistics.WebUI.UltraWebGrid.AllowGroupBy.Yes.AllowUpdate = Infragistics.WebUI.UltraWebGrid.AllowUpdate.RowTemplateOnlyEnd With
Dim colExempt As New Infragistics.WebUI.UltraWebGrid.UltraGridColumn(True).Columns.Add(colExempt)With colExempt.Hidden = False.Header.Caption = "ExemptSupervior".Width = 25.IsBound = True.BaseColumnName = "ExemptSupervior".Key = "ExemptSupervior"End With
'more columns
At this point, I'm passing this thread over to Developer Support to provide you with further aid. Everything that's been described so far should likely have worked, to the best of my knowledge, and it will take further research to determine why things aren't working. Developer Support will create a support case for you and contact you through that case.
Nothing works.
Good News! (sort-of)
Using Microsoft's AdventureWorks database, the replacement for Northwind, using a table which has Boolean values resulted in the UltraWebGrid dataobject writing "True' and "False".
The downside is the datatype used within AdventureWorks is not an option within SQL Server 2005, which is "UnknownType".
Hmm, the actual values within the column is True and False, not "0" or "1", which I currently have. I will change the "0" and "1" to "True" and "False" to View the output.
TY
WebGrid should already be doing this. It implicitly provides checkboxes for colums that use the System.Boolean data type, without needing any specific code to do so. I'm suspecting that there's something about the data structure itself that is keeping the grid from identifying your column as a boolean.
Can you reproduce this behavior in a sample that we can run and debug? I suggest using the Products table using the Northwind sample database, since it has a Discontinued column which is a "bit" datatype in SQL Server.
Happy Easter!
I am looked at this problem and found out the following: when I used the GridView object the Boolean value appeared as a checkbox so that I can grab that value to use in a conditional statement. However with the UltraWebGrid no value is reflected; the column is blank.
Only from within Sql Server Query Analyzer, the "-1" value appears.
So, I am thinking that there is a major difference between how Visual Studio's GridView object and infragistics UltraWebGrid object interprets Boolean values. The goal is to have the UltraWebGrid recognize Boolean values.