Hi forum!
i'm having some trouble making a combobox select an item knowing its value. I've seen demos and documentation and i cloned the examples but its not working for me. I don't know what im doing wrong.
When i select an item from my combobox1, even in the RadComboBox1_SelectedIndexChanged the selectedIndex is always = -1 so this way i can't know the index of the item and use it for other things.
So to try and selecte an item in the radcombobox2 i go for the value of the item selected in the radcombobox1. This value comes right but when i try RadComboBox2.SelectedIndex = RadComboBox2.FindItemIndexByValue(boletim_id) the index i receive from the find method is -1 and i know that exists an item with the boletim_id value in the radcombobox2 because the datasource in both radcombobox is the same. The same will happen if i try the finditemindexbytext or finditembyvalue or finditembytext.
File Code (ASP)
File Code(VB.NET)
Many Thanks,
FEST
i'm having some trouble making a combobox select an item knowing its value. I've seen demos and documentation and i cloned the examples but its not working for me. I don't know what im doing wrong.
When i select an item from my combobox1, even in the RadComboBox1_SelectedIndexChanged the selectedIndex is always = -1 so this way i can't know the index of the item and use it for other things.
So to try and selecte an item in the radcombobox2 i go for the value of the item selected in the radcombobox1. This value comes right but when i try RadComboBox2.SelectedIndex = RadComboBox2.FindItemIndexByValue(boletim_id) the index i receive from the find method is -1 and i know that exists an item with the boletim_id value in the radcombobox2 because the datasource in both radcombobox is the same. The same will happen if i try the finditemindexbytext or finditembyvalue or finditembytext.
File Code (ASP)
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
Runat
=
"server"
>
</
telerik:RadScriptManager
>
<
div
>
<
asp:SqlDataSource
ID
=
"SqlDataSource1"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:Processos8ConnectionString %>"
SelectCommand="SELECT [Sinistrado], [Sinistrado_ID] FROM [Sinistrados]">
</
asp:SqlDataSource
>
<
asp:SqlDataSource
ID
=
"SqlDataSource2"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:Processos8ConnectionString %>"
SelectCommand="SELECT [Sinistrado_ID], [Sinistro_ID], [Tomador_ID], [Boletim_id] FROM [Boletins]">
</
asp:SqlDataSource
>
</
div
>
<
telerik:RadComboBox
ID
=
"RadComboBox1"
Runat
=
"server"
DataSourceID
=
"SqlDataSource1"
DataTextField
=
"Sinistrado"
DataValueField
=
"Sinistrado_ID"
AllowCustomText
=
"True"
AutoCompleteSeparator
=
"|"
AutoPostBack
=
"True"
ItemsPerRequest
=
"20"
MarkFirstMatch
=
"True"
ShowMoreResultsBox
=
"True"
EnableAutomaticLoadOnDemand
=
"True"
>
</
telerik:RadComboBox
>
<
telerik:RadTextBox
ID
=
"RadTextBox1"
Runat
=
"server"
>
</
telerik:RadTextBox
>
<
telerik:RadTextBox
ID
=
"RadTextBox2"
Runat
=
"server"
>
</
telerik:RadTextBox
>
<
telerik:RadComboBox
ID
=
"RadComboBox2"
Runat
=
"server"
DataSourceID
=
"SqlDataSource1"
DataTextField
=
"Sinistrado"
DataValueField
=
"Sinistrado_ID"
AllowCustomText
=
"True"
AutoCompleteSeparator
=
"|"
AutoPostBack
=
"True"
ItemsPerRequest
=
"20"
MarkFirstMatch
=
"True"
ShowMoreResultsBox
=
"True"
EnableAutomaticLoadOnDemand
=
"True"
>
</
telerik:RadComboBox
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
CellSpacing
=
"0"
DataSourceID
=
"SqlDataSource2"
GridLines
=
"None"
AutoGenerateColumns
=
"False"
>
<
HeaderContextMenu
CssClass
=
"GridContextMenu GridContextMenu_Default"
></
HeaderContextMenu
>
<
MasterTableView
datakeynames
=
"Boletim_id"
datasourceid
=
"SqlDataSource2"
>
<
CommandItemSettings
ExportToPdfText
=
"Export to PDF"
></
CommandItemSettings
>
<
RowIndicatorColumn
FilterControlAltText
=
"Filter RowIndicator column"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
FilterControlAltText
=
"Filter ExpandColumn column"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridButtonColumn
Text
=
"Select"
CommandName
=
"Select"
ButtonType
=
"ImageButton"
ImageUrl
=
"~/images/select_16_mouse.png"
>
</
telerik:GridButtonColumn
>
<
telerik:GridBoundColumn
DataField
=
"Sinistrado_ID"
DataType
=
"System.Int32"
FilterControlAltText
=
"Filter Sinistrado_ID column"
HeaderText
=
"Sinistrado_ID"
SortExpression
=
"Sinistrado_ID"
UniqueName
=
"Sinistrado_ID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Sinistro_ID"
DataType
=
"System.Int32"
FilterControlAltText
=
"Filter Sinistro_ID column"
HeaderText
=
"Sinistro_ID"
SortExpression
=
"Sinistro_ID"
UniqueName
=
"Sinistro_ID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Tomador_ID"
DataType
=
"System.Int32"
FilterControlAltText
=
"Filter Tomador_ID column"
HeaderText
=
"Tomador_ID"
SortExpression
=
"Tomador_ID"
UniqueName
=
"Tomador_ID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Boletim_id"
DataType
=
"System.Int32"
FilterControlAltText
=
"Filter Boletim_id column"
HeaderText
=
"Boletim_id"
ReadOnly
=
"True"
SortExpression
=
"Boletim_id"
UniqueName
=
"Boletim_id"
>
</
telerik:GridBoundColumn
>
</
Columns
>
<
EditFormSettings
>
<
EditColumn
FilterControlAltText
=
"Filter EditCommandColumn column"
></
EditColumn
>
</
EditFormSettings
>
</
MasterTableView
>
<
ClientSettings
>
<
Selecting
AllowRowSelect
=
"True"
/>
</
ClientSettings
>
<
FilterMenu
EnableImageSprites
=
"False"
></
FilterMenu
>
</
telerik:RadGrid
>
</
form
>
</
body
>
</
html
>
File Code(VB.NET)
Imports
Telerik.Web.UI
Imports
System.IO
Imports
System.Data.SqlClient
Imports
System.Configuration
Imports
System.Data
Imports
System.Net
Partial
Class
_Default
Inherits
System.Web.UI.Page
Protected
Sub
RadComboBox1_SelectedIndexChanged(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)
Handles
RadComboBox1.SelectedIndexChanged
SqlDataSource2.SelectCommand =
"SELECT [Sinistrado_ID], [Sinistro_ID], [Tomador_ID], [Boletim_id] FROM [Boletins] WHERE SINISTRADO_ID = "
& RadComboBox1.SelectedValue
RadGrid1.DataBind()
RadComboBox1.SelectedIndex = RadComboBox1.SelectedIndex
End
Sub
Protected
Sub
RadGrid1_SelectedIndexChanged(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
RadGrid1.SelectedIndexChanged
Dim
boletim_id
As
String
=
DirectCast
(RadGrid1.SelectedItems.Item(0), GridDataItem).Cells(6).Text.ToString
RadTextBox1.Text =
DirectCast
(RadGrid1.SelectedItems.Item(0), GridDataItem).Cells(5).Text.ToString
RadTextBox2.Text =
DirectCast
(RadGrid1.SelectedItems.Item(0), GridDataItem).Cells(4).Text.ToString
Dim
x
As
Integer
= RadComboBox2.FindItemIndexByValue(boletim_id)
'Dim z As Integer = RadComboBox1.SelectedItem.Index
RadComboBox1.Text =
""
RadComboBox1.SelectedValue =
""
RadComboBox2.SelectedIndex = RadComboBox2.FindItemIndexByValue(boletim_id)
RadComboBox2.SelectedIndex = RadComboBox1.SelectedItem.Index
End
Sub
End
Class
Many Thanks,
FEST