Highlight a Telerik RadGrid row based on error - ajax

I would like to highlight a row from my RadGrid base on a logic row error (not database related).
I'm using Telerik Ajax .net RadGrid With VB.NET
If ok > 2000 Then
Dim errorRowOrderNumber = ok / 1000
'Get the RadGrid row error index
myErrorRow.Drawing.Color.Red
myErrorRow.Drawing.Color.White
End If

Use this if you can identify the error condition on item data bound event:
Protected Sub grid_ItemDataBound(sender As Object, e As GridItemEventArgs)
Try
If TypeOf e.Item Is GridDataItem Then
Dim dataRow = TryCast(e.Item, GridDataItem)
' Replace with validation logic
If True Then
dataRow.BackColor = Drawing.Color.Gray
dataRow.ForeColor = Drawing.Color.White
dataRow.ToolTip = "Some information about this error."
End If
End If
Catch ex As Exception
' handle exception
End Try
End Sub
In any other grid command event you can get a reference to the same GridDataItem object.
If you can't use a grid event try looking into client-side options.

Related

row is not a member of eventargs in vb.net

I want the code below in the event button to do string formatting in the datagridview column but there is a "row is not a member of eventargs" error. Is there something wrong with my code?.
Thanks
Dim result As Decimal = Nothing
If Decimal.TryParse(e.Row.Cells(4).Text, result) Then
e.Row.Cells(4).Text = String.Format("{0:#,##0.00}", result)
End If

How do you add your queried datatable results into a new datatable

Can someone please help me fill my queried results into the existing datatable or a new datatable
''dt is filled with data from a csv file.
Dim dataRows As DataRow() = dt.Select("[Calendar year TEXT] = '2020'")
dt.Clear() 'Clear the datatable
dt.Rows.Add(dataRows) 'Add the result to the existing datatable or a new databletable if possible ?
So I've figured it out.
The reason I need a new DataTable is that I need to use it again in its original form later.
I could not attach the DataRow collection to my display control which is why I needed a new DataTable with the filtered results.
Private Function FilterDataTable(ByVal strQuery As String, ByVal dtRaw As DataTable)
Dim dataRows As DataRow() = dtRaw.Select(strQuery)
Dim dtFiltered As DataTable
dtFiltered = dtRaw.Clone() 'This is very important.
For Each drow As DataRow In dataRows
dtFiltered.ImportRow(drow) 'Add each filtered row to new DataTable.
Next
Return dtFiltered
End Function
Your dt.select will return an array of Datarow pointing to the rows in the datatable dt. Your dt.clear then clears the datatable and so will empty the dataRows array leaving you nothing left.
I'm not clear exactly what you are trying to do. I'm guessing you have a table that you want to filter and then discard all rows that don't match, leaving you a datatable to work with.
If so, here's a few options:
Work with the datarow array directly rather than the datatable. Is there really any need to convert the rows back to a datatable?
Create a new datatable to add the rows to, but don't clear the original table:
Dim dt As New DataTable ' Assume this is your populated table
Dim dataRows As DataRow() = dt.Select("[Calendar year TEXT] = '2020'")
Dim dtResults As DataTable = dt.Clone()
For Each row As DataRow In dr
dtResults.ImportRow(row)
Next
bare in mind any changes you make to the rows in dtResults will also affect the rows in dt as they both contain the same data
Depending on the size of your table and whether or not you really want to discard non matching rows, you could just remove all rows that don't match then work with the result:
Dim i As Integer = dt.Rows.Count - 1
While i >= 0
If dt(i).Item("Calendar") <> "Your test here" Then dt.Rows.Remove(dt(i))
i -= 1
End While

How do i set the celltype for a datagrid column?

I am adding a new column to a datagrid to store a row total of qty*Cost
When I try to add the column I get an exception saying
System.InvalidOperationException: 'Column cannot be added because its CellType property is null.'
I've tried to set the cell type but I can't get the type right
Dim dt As DataTable = Me.DsOppQuoteDetail.tblOppQuoteDetail
Dim dr As DataRow
Dim dc As New DataGridViewColumn
With dc
.HeaderText = "Item Total"
.Name = "UnitTotal"
.CellType = DataGridTextBox
End With
DGV_OppQuoteDetail.Columns.Insert(6, dc)
Setting the CellType to DataGridTextBox produces an error
If I change the the column to:
Dim dc As New DataGridTextBoxColumn
With dc
.HeaderText = "Item Total"
End With
DGV_OppQuoteDetail.Columns.Insert(6, dc)
then I can't insert it because it's the wrong type for the DataGrid.Insert command
Dim dc As New DataGridViewTextBoxColumn
dc.HeaderText = "SomeText"
dc.Name = "colWhateverName"
DGV_OppQuoteDetail.Columns.Add(dc)
Try this and let me know. Only slightly different in terms of wording. Also from your code snippet it seems fine but make sure you don't add any rows before adding a column.

Display newly created record in Formview

I have this form on VS2012 with asp.net. First I do search for the patron, then go to verify information for that patron. This patron information is displayed in ItemTemplate(ReadOnly). If that is not the patron they are looking for then they can add a new patron with "New button" (asp.net code). I am able to get the id of the new Patron(which is PK). However I am not able to display this newly created record on the form after inserting. It still displays the record which was on display. Since this a formview I did not enable "Paging".
Is it possible to call the pageload event from datasource_inserted event? Then I can pass the new patron ID for display. I declared this ID as global variable?
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim lvPatronID As String
lvPatronID = Request.QueryString("value1")
If lvPatronID = "" Then
frmPatronView.ChangeMode(FormViewMode.Insert)
Else
frmPatronView.ChangeMode(FormViewMode.ReadOnly)
GvPatronID = lvPatronID
lblPatronID.Text = GvPatronID
End If
Protected Sub PatronDS_Inserted(sender As Object, e As SqlDataSourceStatusEventArgs) Handles PatronDS.Inserted
NewID = e.Command.Parameters("#PatronID").Value.ToString
GvPatronID = NewID
End Sub
Well I answered part of my own question. The following change to the Inserted event will let me view the newly inserted data. I have another button to add new record in the emptytemplate of the search form. This is why I am changing the mode to insert as the default mode is readonly. This will let me insert the data but after inserting it doesn't display the form at all. Not sure why Inserted event is not kicking in properly.
Protected Sub PatronDS_Inserted(sender As Object, e As SqlDataSourceStatusEventArgs) Handles PatronDS.Inserted
Dim NewID As String = Nothing
Try
NewID = e.Command.Parameters("#PatronID").Value.ToString
PatronDS.SelectCommand = "SELECT * FROM tblPatron WHERE PatronID='" & NewID & "'"
lblPatronID.Text = NewID.Trim()
frmPatronView.DataBind()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

customunboundcolumndata event not firing in DEVExpress gridview

I have been struggling with the below code snippet. "CustomUnboundColumnData" event is not firing.
Protected Sub gvAlertReport_CustomUnboundColumnData(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridView.ASPxGridViewColumnDataEventArgs)
If e.Column.FieldName = "Active" Then
Dim val As String = e.Value
Dim img As New ImageButton()
Select Case val
Case "False"
img.ImageUrl = "Images/gray_bell.png"
img.Attributes.Add("", "")
Case "True"
img.ImageUrl = "Images/red_bell.png"
img.Attributes.Add("", "")
Case Else
End Select
End If
End Sub
Thanks in Advance..
The CustomUnboundColumnData event is only triggered if there is a column in the ASPxGridView which is designed as an Unbound Column. To learn how this can be done, please refer to the Unbound Columns Overview topic. Also, please make certain that the gvAlertReport_CustomUnboundColumnData is the actual event handler for the ASPxGridView.

Resources