I have a project that uses telerik controls... I'm using a radtabstrip (just creates tabs in a page).. one tab is called safety..
I have another page that is displayed inside the tabstrip
On that page I have two radcombo boxes that are filled by a sqldatasource
I also have a sub that is used to fill all the controls on the page with information from sql.
in the case of the comboxes it takes the keyfiled (just a number) finds that number in the combobox and selects that item
for some reason I am getting an out of range error...
Here is the section where I select the value of the combobox (the entire sub will follow)
thanks in advance experts
Dim item As RadComboBoxItem = Nothing If sdr(14).ToString = "" Then item = cmbPriHelo.FindItemByValue("Helicopter") item.Selected = True 'cmbPriHelo.Items.FindItemByValue("Helicopter").Selected = True Else 'this is where the error happens item = cmbPriHelo.FindItemByValue(sdr(14).ToString()) item.Selected = True End If
Private Sub FillForm() Dim ProjId As String = ProjectInfo.ProjID Dim strConnString As String = ConfigurationManager.ConnectionStrings("TimberOpsConnectionString").ConnectionString Dim strQuery As String = "select KEYField, Lat_Degrees1, Lat_Minutes1, Lat_Seconds1, Long_Degrees1, Long_Minutes1, Long_Seconds1, LandingZoneDesc, LZ_Average_Elevation, Evac_Form_Authorized, JS_Radio_Comm, JS_Mobile_Comm, JS_Designated_Comm_Pt, JS_Comm_Pt_Description, Primary_Helicopter, Secondary_Helicopter from tblProject where KEYField = " & ProjId Dim con As New SqlConnection(strConnString) Dim cmd As New SqlCommand() cmd.CommandType = CommandType.Text cmd.CommandText = strQuery cmd.Connection = con Try con.Open() Dim sdr As SqlDataReader = cmd.ExecuteReader() While sdr.Read() Try txtHeliLatDeg.Text = sdr(1).ToString() txtHeliLatMin.Text = sdr(2).ToString() txtHeliLatSec.Text = sdr(3).ToString() txtHeliLongDeg.Text = sdr(4).ToString() txtHeliLongMin.Text = sdr(5).ToString() txtHeliLongSec.Text = sdr(6).ToString() txtLZoneDesc.Text = sdr(7).ToString() txtLZoneElevation.Text = sdr(8).ToString() If sdr(9).ToString = "True" Then btnAppEvacForm.Checked = True Else btnAppEvacForm.Checked = False End If If sdr(10).ToString = "True" Then btnJobSiteRadio.Checked = True Else btnJobSiteRadio.Checked = False End If If sdr(11).ToString = "True" Then btnJobSiteMobileComm.Checked = True Else btnJobSiteMobileComm.Checked = False End If If sdr(12).ToString = "True" Then btnDesCommPt.Checked = True Else btnDesCommPt.Checked = False End If txtCommPointDesc.Text = sdr(13).ToString() Dim item As RadComboBoxItem = Nothing If sdr(14).ToString = "" Then item = cmbPriHelo.FindItemByValue("Helicopter") item.Selected = True 'cmbPriHelo.Items.FindItemByValue("Helicopter").Selected = True Else 'this is where the error happens item = cmbPriHelo.FindItemByValue(sdr(14).ToString()) item.Selected = True End If MsgBox("made it here") If sdr(15).ToString = "" Then 'cmbSecHelo.Items.FindItemByValue("Helicopter").Selected = True Else cmbSecHelo.Items.FindItemByValue(sdr(15).ToString()).Selected = True End If Catch ex As Exception MsgBox(ex.Message) End Try End While Catch ex As Exception MsgBox(ex.Message) Finally con.Close() con.Dispose() End Try End Sub
I can imagine that the controls use a kind of deferred mode. So the items shown (loaded) are not necessarily the same as in the data source.
But this kind of question is better addressed to Telerik directly.
AndyAinscow
While sdr.Read()
Try
txtHeliLatDeg.Text = sdr(1).ToString()
....
As things use zero based indexing this sdr(1) will use the second field (column) of data and so on until, I suspect, the one more than the number of fields returned in the reader.
David Modugno
ASKER
I realize that it is zero based, I just don't need that value.
All of the other controls get filled without issue.
The problem happens in this section... it looks to see if there is a value returned for sdr(14)
in testing I always pick a project that will return a value.. I even placed the as a test
msgbox(sdr(14).ToString) -- in this case it returns "1"
so it should then should find the item value of "1" and select it
but I get the error
Dim item As RadComboBoxItem = Nothing If sdr(14).ToString = "" Then item = cmbPriHelo.FindItemByValue("Helicopter") item.Selected = True 'cmbPriHelo.Items.FindItemByValue("Helicopter").Selected = True Else 'this is where the error happens item = cmbPriHelo.FindItemByValue(sdr(14).ToString()) item.Selected = True End If
Strange.
Instead of this
'this is where the error happens
item = cmbPriHelo.FindItemByValue(sdr(14).ToString())
item.Selected = True
try
'this is where the error happens
dim s as string = sdr(14).ToString()
item = cmbPriHelo.FindItemByValue(s)
item.Selected = True
then put a breakpoint on the FindItemByValue line and check what s contains (or if it crashes with the same error before reaching the breakpoint)
David Modugno
ASKER
could it be that it is trying to find the value before the combobox has been populated?
I think that is the case... I just did a test.. I added a button to the page and instead of calling my FillPage() sub in page load I am calling it from the button...
now it all works...
problem is I need it to fill the page on load...
from earlier .... I think it is because the safety page is a subpage of the radpageview and for some reason it is causing my combobox to not be filled soon enough ... I have a ticket open with telerek too, but so far they have not been much help and they are very slow... any help would be great
thanks
I managed to isolate the problem to a timing issue.. this was tested by creating a button and letting the page load complete before running the fill page sub.. everything now works after I forced the combo boxes to populate before I try and call them
thanks
I can imagine that the controls use a kind of deferred mode. So the items shown (loaded) are not necessarily the same as in the data source.
But this kind of question is better addressed to Telerik directly.