Hello,
i have a problem regarding load on demand grid combo box
the problem is i want two combo box field that load grid in one asp.net page
but i am getting error like this
i am using two ajax manager.
you can see the example of telerik combox box.i want a two combo box that load data on grid on same page
http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridincombobox/defaultcs.aspx?product=grid
please help me out
i am a beginner in telerik
thanks
i have a problem regarding load on demand grid combo box
the problem is i want two combo box field that load grid in one asp.net page
but i am getting error like this
Only one instance of a RadAjaxManager can be added to the page!
i am using two ajax manager.
you can see the example of telerik combox box.i want a two combo box that load data on grid on same page
http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridincombobox/defaultcs.aspx?product=grid
please help me out
i am a beginner in telerik
thanks
3 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 24 Oct 2013, 09:05 AM
Hi Immad,
You do not have to use two RadAjaxManager for two ComboBox, both can be added to one.Please try the following code snippet.
ASPX:
C#:
Thanks,
Princy
You do not have to use two RadAjaxManager for two ComboBox, both can be added to one.Please try the following code snippet.
ASPX:
<
telerik:RadCodeBlock
ID
=
"rcb1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
var grid;
function GridCreated(sender, args) {
grid = sender;
}
function RowClicked(sender, args) {
var cellValues1 = args.getDataKeyValue("OrderID") + ", " + args.getDataKeyValue("ProductName") + ", $" + args.getDataKeyValue("UnitPrice");
var cellValues2 = args.getDataKeyValue("OrderID") + ", " + args.getDataKeyValue("CustomerID");
var combo = $find("<%= RadComboBox1.ClientID %>");
var combo1 = $find("<%= RadComboBox2.ClientID %>");
setTimeout(function () {
combo.set_text(cellValues1);
}, 50);
setTimeout(function () {
combo1.set_text(cellValues2);
}, 50);
}
function ShouldInitiateAjaxRequest(comboText) {
if (comboText.length > 2) {
$find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("LoadFilteredData");
return true;
}
else {
return false;
}
}
function HandleOpen(sender, args) {
var flag = ShouldInitiateAjaxRequest(sender.get_text());
if (!flag) {
args.set_cancel(true);
}
}
function HandleKeyPressed(sender) {
var combo = $find(sender.id);
combo.showDropDown();
}
</
script
>
</
telerik:RadCodeBlock
>
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
OnAjaxRequest
=
"RadAjaxManager1_AjaxRequest"
RequestQueueSize
=
"3"
>
</
telerik:RadAjaxManager
>
<
telerik:RadAjaxLoadingPanel
ID
=
"RadAjaxLoadingPanel1"
runat
=
"server"
>
</
telerik:RadAjaxLoadingPanel
>
<
telerik:RadComboBox
ID
=
"RadComboBox1"
Width
=
"340px"
runat
=
"server"
MarkFirstMatch
=
"True"
AllowCustomText
=
"True"
OnClientDropDownOpening
=
"HandleOpen"
ExpandAnimation-Type
=
"None"
CollapseAnimation-Type
=
"None"
DropDownWidth
=
"340px"
onkeyup
=
"HandleKeyPressed(this)"
>
<
ItemTemplate
>
<
telerik:RadGrid
ID
=
"RadGrid1"
Width
=
"325px"
runat
=
"server"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
>
<
MasterTableView
NoMasterRecordsText
=
""
AutoGenerateColumns
=
"False"
DataKeyNames
=
"OrderID,ProductName,UnitPrice"
Width
=
"100%"
ClientDataKeyNames
=
"OrderID,ProductName,UnitPrice"
TableLayout
=
"Fixed"
>
<
Columns
>
<
telerik:GridBoundColumn
HeaderText
=
"OrderID"
DataField
=
"OrderID"
UniqueName
=
"OrderID"
>
<
HeaderStyle
Width
=
"75px"
></
HeaderStyle
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
HeaderText
=
"ProductName"
DataField
=
"ProductName"
UniqueName
=
"ProductName"
>
<
HeaderStyle
Width
=
"138px"
></
HeaderStyle
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
HeaderText
=
"UnitPrice"
DataField
=
"UnitPrice"
UniqueName
=
"UnitPrice"
DataFormatString
=
"{0:$###,###.##}"
>
<
HeaderStyle
Width
=
"65px"
></
HeaderStyle
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
>
<
ClientEvents
OnRowClick
=
"RowClicked"
OnGridCreated
=
"GridCreated"
></
ClientEvents
>
<
Scrolling
AllowScroll
=
"true"
UseStaticHeaders
=
"true"
ScrollHeight
=
"300px"
></
Scrolling
>
</
ClientSettings
>
</
telerik:RadGrid
>
</
ItemTemplate
>
<
Items
>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
" "
></
telerik:RadComboBoxItem
>
</
Items
>
</
telerik:RadComboBox
>
<
telerik:RadComboBox
ID
=
"RadComboBox2"
Width
=
"340px"
runat
=
"server"
MarkFirstMatch
=
"True"
AllowCustomText
=
"True"
OnClientDropDownOpening
=
"HandleOpen"
ExpandAnimation-Type
=
"None"
CollapseAnimation-Type
=
"None"
DropDownWidth
=
"340px"
onkeyup
=
"HandleKeyPressed(this)"
>
<
ItemTemplate
>
<
telerik:RadGrid
ID
=
"RadGrid2"
Width
=
"325px"
runat
=
"server"
OnNeedDataSource
=
"RadGrid2_NeedDataSource"
>
<
MasterTableView
NoMasterRecordsText
=
""
AutoGenerateColumns
=
"False"
DataKeyNames
=
"OrderID,CustomerID"
Width
=
"100%"
ClientDataKeyNames
=
"OrderID,CustomerID"
TableLayout
=
"Fixed"
>
<
Columns
>
<
telerik:GridBoundColumn
HeaderText
=
"OrderID"
DataField
=
"OrderID"
UniqueName
=
"OrderID"
>
<
HeaderStyle
Width
=
"75px"
></
HeaderStyle
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
HeaderText
=
"CustomerID"
DataField
=
"CustomerID"
UniqueName
=
"CustomerID"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
>
<
ClientEvents
OnRowClick
=
"RowClicked"
OnGridCreated
=
"GridCreated"
></
ClientEvents
>
<
Scrolling
AllowScroll
=
"true"
UseStaticHeaders
=
"true"
ScrollHeight
=
"300px"
></
Scrolling
>
</
ClientSettings
>
</
telerik:RadGrid
>
</
ItemTemplate
>
<
Items
>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
" "
></
telerik:RadComboBoxItem
>
</
Items
>
</
telerik:RadComboBox
>
C#:
public
static
string
connectionString = ConfigurationManager.ConnectionStrings[
"Northwind_newConnectionString3"
].ConnectionString;
public
static
DataTable GetDataTable(
string
query)
{
SqlConnection connection1 =
new
SqlConnection(connectionString);
SqlDataAdapter adapter1 =
new
SqlDataAdapter();
adapter1.SelectCommand =
new
SqlCommand(query, connection1);
DataTable table1 =
new
DataTable();
connection1.Open();
try
{
adapter1.Fill(table1);
}
finally
{
connection1.Close();
}
return
table1;
}
protected
void
RadGrid1_NeedDataSource(
object
source, GridNeedDataSourceEventArgs e)
{
RadGrid grid = source
as
RadGrid;
if
(RadComboBox1.Text !=
""
)
{
//split the combobox text and filter the records in the grid based on the first value in the array, i.e. OrderID
String[] vals = RadComboBox1.Text.Split(
','
);
if
(vals.Length > 0)
{
RadComboBox1.Text = vals[0];
}
grid.DataSource = GetDataTable(
"SELECT [Order Details].OrderID, Products.ProductName, [Order Details].UnitPrice FROM Products, [Order Details] "
+
"WHERE [Order Details].OrderID LIKE '"
+ RadComboBox1.Text +
"%'"
+
" AND Products.ProductID=[Order Details].ProductID"
);
}
else
{
DataTable dt =
new
DataTable();
dt.Columns.Add(
"OrderID"
);
dt.Columns.Add(
"ProductName"
);
dt.Columns.Add(
"UnitPrice"
);
grid.DataSource = dt;
}
}
protected
void
RadGrid2_NeedDataSource(
object
source, GridNeedDataSourceEventArgs e)
{
RadGrid grid = source
as
RadGrid;
if
(RadComboBox2.Text !=
""
)
{
//split the combobox text and filter the records in the grid based on the first value in the array, i.e. OrderID
String[] vals = RadComboBox2.Text.Split(
','
);
if
(vals.Length > 0)
{
RadComboBox2.Text = vals[0];
}
grid.DataSource = GetDataTable(
"SELECT OrderID,CustomerID FROM Orders WHERE OrderID LIKE '"
+ RadComboBox2.Text +
"%'"
);
}
else
{
DataTable dt =
new
DataTable();
dt.Columns.Add(
"OrderID"
);
dt.Columns.Add(
"CustomerID"
);
grid.DataSource = dt;
}
}
protected
void
RadAjaxManager1_AjaxRequest(
object
sender, AjaxRequestEventArgs e)
{
RadGrid grid1 = RadComboBox1.Items[0].FindControl(
"RadGrid1"
)
as
RadGrid;
RadGrid grid2 = RadComboBox2.Items[0].FindControl(
"RadGrid2"
)
as
RadGrid;
//detect the filter action
if
(e.Argument.IndexOf(
"LoadFilteredData"
) != -1)
{
grid1.Rebind();
}
if
(e.Argument.IndexOf(
"LoadFilteredData"
) != -1)
{
grid2.Rebind();
}
}
protected
void
Page_Load(
object
sender, EventArgs e)
{
RadGrid grid1 = RadComboBox1.Items[0].FindControl(
"RadGrid1"
)
as
RadGrid;
RadGrid grid2 = RadComboBox2.Items[0].FindControl(
"RadGrid2"
)
as
RadGrid;
RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadAjaxManager1, grid1, RadAjaxLoadingPanel1);
RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadAjaxManager1, grid2, RadAjaxLoadingPanel1);
}
Thanks,
Princy
0
immad
Top achievements
Rank 1
answered on 25 Oct 2013, 07:24 AM
hi princy
its giving me error
i highlight it with bold
thanks 4 the help
its giving me error
Object reference not set to an instance of an object.
Line 111: RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadAjaxManager1, grid1, RadAjaxLoadingPanel1);i highlight it with bold
protected
void
Page_Load(
object
sender, EventArgs e)
{
RadGrid grid1 = RadComboBox1.Items[0].FindControl(
"RadGrid1"
)
as
RadGrid;
RadGrid grid2 = RadComboBox2.Items[0].FindControl(
"RadGrid2"
)
as
RadGrid;
RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadAjaxManager1, grid1, RadAjaxLoadingPanel1);
RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadAjaxManager1, grid2, RadAjaxLoadingPanel1);
}
thanks 4 the help
0
Princy
Top achievements
Rank 2
answered on 25 Oct 2013, 08:46 AM
Hi Immad,
I'm not sure,i couldn't find the issue at my end,Can you try adding the AjaxManager from aspx as follows and see if the error still occurs,if this doesn't help,please provide your full code snippet.
ASPX:
Thanks,
Princy
I'm not sure,i couldn't find the issue at my end,Can you try adding the AjaxManager from aspx as follows and see if the error still occurs,if this doesn't help,please provide your full code snippet.
ASPX:
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
OnAjaxRequest
=
"RadAjaxManager1_AjaxRequest"
RequestQueueSize
=
"3"
EnableAJAX
=
"true"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadAjaxManager1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadAjaxManager1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid2"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
telerik:RadAjaxLoadingPanel
ID
=
"RadAjaxLoadingPanel1"
runat
=
"server"
>
</
telerik:RadAjaxLoadingPanel
>
Thanks,
Princy