I have a couple of dropdownlists on my forTemplate but the fucntionality I need is the following. On Insert I need them to be avialable to pick data, but on Edit mode I want to disable them so that they cannot mess with them becuase they are not editable in edit mode. i thought the follwoing code would work but appears not. On insert mode or what i thought was insertmode it fills the ddl and it works for soem reason, but on edit or insert it disables my dropwdownlists.
Protected Sub myPOGrid_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles myPOGrid.ItemDataBound
If (TypeOf e.Item Is IGridInsertItem AndAlso e.Item.IsDataBound) Then
Dim gr As DropDownList = DirectCast(e.Item.FindControl("ddlPOFund"), DropDownList)
sql = "Select intFundID, strPGMCDnum + ' \ ' + CASE WHEN intSourceId = 1 then 'FEDERAL' ELSE 'STATE' END + ' \ ' + strEorNum FUND from Drat_fundSource where bitArchive IS NULL"
gr.Items.Add(New ListItem("Pick Funding Source", "0"))
buildDD(sql, gr)
End If
If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then
Dim editedItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)
Dim PoFund As DropDownList = DirectCast(editedItem.FindControl("ddlPOFund"), DropDownList)
Dim FundS As DropDownList = DirectCast(editedItem.FindControl("ddlFundSource"), DropDownList)
PoFund.Enabled = False
FundS.Enabled = False
End If
End Sub
<ConfirmTemplate> <div id="dlg1" style="display:none"> Dialog content </div>
<div id="dlg2" style="display:none"> Dialog content </div></ConfirmTemplate>
<telerik:GridDateTimeColumn DataField=
"AssignDate"
DataFormatString=
"{0:MM/dd/yyyy hh:mm tt}"
HeaderText=
"Assign Date"
PickerType=
"DatePicker"
SortExpression=
"AssignDate"
UniqueName=
"AssignDate"
/>
if
(filter.Contains(
"[AssignDate]"
))
{
int
index = filter.IndexOf(
"([AssignDate]"
);
int
firstQuote = filter.IndexOf(
"'"
, index);
int
lastQuote = filter.IndexOf(
"'"
, firstQuote + 1);
string
stringToExcise = filter.Substring(index, lastQuote - index + 2);
string
dateToParse = filter.Substring(firstQuote + 1, lastQuote - firstQuote - 1);
DateTime dateTime = DateTime.Parse(dateToParse);
assignDate =
"(convert(varchar(10), [AssignDate], 101) = '"
+ dateTime.Month.ToString(
"0#"
) +
"/"
+ dateTime.Day.ToString(
"0#"
) +
"/"
+ dateTime.Year +
"')"
;
}
<telerik:GridDateTimeColumn datafield="ExportedDate" DataFormatString="{0:MM/dd/yyyy}" datatype="System.DateTime"
headertext="Exported" sortexpression="ExportedDate" uniquename="EXPORTED" FilterControlWidth="75px">
<HeaderStyle HorizontalAlign="Center" Width="90px"/>
<ItemStyle HorizontalAlign="Right" Width="90px"/>
</telerik:GridDateTimeColumn>
What I have found is that the date will not work correctly on fields unless the data coming from the database has the time essentially set to 00:00:00. All the filtering is done by the specified date with the time set to midnight.
For example: if my date field from the database is 3/25/2009 06:30:12 and I'm filtering on the date 3/25/2009, then the following results ocurr:
Comparison Expected Result Actual Result
-------------------------- ----------------------- --------------------
EqualTo Match No match
NotEqualTo No Match Match
GreaterThan No Match Match
LessThan No Match No Match
GreaterThanOrEqualTo Match Match
LessThanOrEqualTo Match No Match
As you can see, only 2 comparisons return results as expected. It all stems around the issue with the time component being used in the comparison.
Work arounds include adding custom filtering, changing every database access procedure or call to remove the time component in the results, and limiting the filter functions to only what works.
None are very attractive when considering the extent of work involved. This system that the Telerik controls are used was initially developed 10 years ag0 and has grown to have at one site alone, 300,000 registered users, hundreds of web pages, thousands of queries, and, needless to say, an extremely large amount of accumulated data.
I believe I shouldn't have to add code to make the date filter work as logically expected. The filtering logic should automatically strip off the TimeOfDay and not be used in the comparisons. Because the System.DateTime has a resolution down to the milliseconds, anyone searching for any equality based on the date will not find a match. This is especially true when picking a date from the calendar icon or when typing in a date; you do not specifiy the time and it is implied to be midnight.
Any assistance, comments, or improvements is greatly appreciated.
Ed Lamprecht
Public Class TempComboBox
Inherits RadComboBox
Const BACK_SPACE = "8"
Private Sub CompanyInfoComboBox_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Dim oHeaderTemplate
Dim oItemTemplate
Me.Height = 200
Me.EnableTextSelection = True
Me.MarkFirstMatch = False
Me.EnableViewState = True
Me.DropDownWidth = 500
Me.OnClientDropDownOpening = "DropDownOpening"
Me.EmptyMessage = "Type Code"
Me.EnableLoadOnDemand = True
Me.ShowMoreResultsBox = False
Me.ShowDropDownOnTextboxClick = True
Me.HighlightTemplatedItems = True
Me.OnClientItemsRequested = "HighlightItem"
Me.OnClientItemsRequesting = "HandleKeyPress"
Me.OnClientKeyPressing = "HandleTab"
Me.OnClientFocus = "HandleOnFocus"
Me.CloseDropDownOnBlur = True
Me.ChangeTextOnKeyBoardNavigation = True
Page.ClientScript.RegisterStartupScript(Me.GetType, "TelerikHandleKeyPressScript", TelerikHandleKeyPressScript())
Page.ClientScript.RegisterStartupScript(Me.GetType, "TelerikHandleTabScript", TelerikHandleTabScript())
Page.ClientScript.RegisterStartupScript(Me.GetType, "TelerikDropDownOpeningScript", TelerikDropDownOpeningScript())
Page.ClientScript.RegisterStartupScript(Me.GetType, "TelerikHandleOnFocusScript", TelerikHandleOnFocusScript())
Page.ClientScript.RegisterStartupScript(Me.GetType, "TelerikHighlightItemScript", TelerikHighlightItemScript())
AddHandler Me.ItemsRequested, AddressOf RadComboBox_ItemsRequested
oHeaderTemplate = New MasterHeaderTemplate
oItemTemplate = New MasterItemTemplate
Me.Width = 75
Me.HeaderTemplate = oHeaderTemplate
Me.ItemTemplate = oItemTemplate
End Sub
Function TelerikHighlightItemScript() As String
Dim sJscript As String = "<
script
language
=
""
javascript""> " & _
" function HighlightItem(combo,e){" & _
" var item=combo.get_items().getItem(0); " & _
" if (item){ " & _
" if (item.get_value() != '0'){ " & _
" item.highlight() ; " & _
" } } " & _
" } </
script
>"
Return sJscript
End Function
Function TelerikDropDownOpeningScript() As String
Dim sJscript As String = "<
script
language
=
""
javascript""> " & _
" function DropDownOpening(combo,e){" & _
" combo.requestItems(combo.get_text(), false); " & _
" } </
script
>"
Return sJscript
End Function
Function TelerikHandleTabScript() As String
Dim sJscript As String = "<
script
language
=
""
javascript""> " & _
" function HandleTab(combo,e){" & _
" if (event.keyCode == 9) { " & _
" combo.hideDropDown(); " & _
" if (combo.get_value() == ''){" & _
" if (combo.get_items().get_count() > 0){" & _
" combo.set_value(combo.get_text()); } else { combo.set_value(combo.get_text()); } } }" & _
" } </
script
>"
Return sJscript
End Function
Function TelerikHandleOnFocusScript() As String
Dim sJscript As String = "<
script
language
=
""
javascript""> " & _
" function HandleOnFocus(combo,e){" & _
" var attrib = combo.get_attributes().getAttribute('OriginalFieldID'); " & _
" var firstCombo = $find('FilterType_'+attrib+''); " & _
" if (firstCombo){ " & _
" combo.requestItems(firstCombo.get_value()+'_FilterType', false); } " & _
" } </
script
>"
Return sJscript
End Function
Function TelerikHandleKeyPressScript() As String
Dim sJscript As String = "<
script
language
=
""
javascript""> " & _
" function HandleKeyPress(combo,e){" & _
" try {if (keypressed == 9) { combo.hideDropDown(); " & _
" }} catch(e) {}" & _
" try {if (keypressed == 8) { var context = e.get_context();" & _
" context[""keyPressed""] = keypressed+''; }} catch(e) {}" & _
" } </
script
>"
Return sJscript
End Function
Protected Sub RadComboBox_ItemsRequested(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs)
If (e.Context.TryGetValue("keyPressed", BACK_SPACE)) Then
'do nothing
Else
If e.Text.Trim.Length > 3 Then
GetDataIntoCombo(e.Text)
End If
End If
End Sub
Public Sub GetDataIntoCombo(ByVal txtCode As String)
Dim dt As DataTable = GetComboBoxDataFROMDATABASE(txtCode)
If dt.Rows.Count = 0 Then
Dim item As New RadComboBoxItem()
Dim hl As New HyperLink()
hl.ID = "hl"
hl.Text = " There were no matches. Please click on this link for further information."
item.Value = "0"
item.DataBind()
Me.Items.Add(item)
item.DataBind()
ElseIf dt.Rows.Count < 51 Then
SetDisplayItemsForRefInfo(dt)
Dim item As New RadComboBoxItem()
item.Text = String.Empty
item.Value = "0"
Me.Items.Add(item)
Else
Dim item As New RadComboBoxItem()
item.Text = "Too many codes have been found. Please enter more characters."
item.Value = "0"
Me.Items.Add(item)
End If
Me.DataBind()
End Sub
Private Sub SetDisplayItemsForRefInfo(ByVal dt As DataTable)
For Each dataRow As DataRow In dt.Rows
Dim item As New RadComboBoxItem()
Dim Code As String = String.Empty
item.Text = DirectCast(dataRow("Code"), String)
item.Value = dataRow("Code").ToString()
Dim Name As String = String.Empty
Try
Name = DirectCast(dataRow("Name"), String)
Code = DirectCast(dataRow("Code"), String)
Catch ex As Exception
End Try
item.Attributes.Add("Code", Code.ToString)
item.Attributes.Add("Name", Name.ToString())
Me.Items.Add(item)
item.DataBind()
Next
End Sub
Private Function GetComboBoxDataFROMDATABASE(ByVal UserText As String) As DataTable
Try
'code to get from DB
Return New DataTable
Catch ex As Exception
Return Nothing
End Try
End Function
End Class