Hi,
I create a server control that create programmatically a grid with template columns, filter templates , ecc.
Evrithing works fine, but i noticed that when i introduced the MyFilterTemplate class to generate the filter items for any column, if the item (radcombobox, raddatapicker, ecc) include a clientside event then others controls outside the grid doesn't work propertly.
For example i have a raddatepicker with a DatePopupButton visible outside the grid , after the page load if i click the popupbutton it shows the popup fine; but after an edit/insert of a value in the grid the popupbutton don't show the popup !.
So, my question is, how a programatically definition of a filter template column with clientside events may cause undesired operation of others controls..
This is the code of my filter template class... that as i said before it works perfectly on the grid.
I create a server control that create programmatically a grid with template columns, filter templates , ecc.
Evrithing works fine, but i noticed that when i introduced the MyFilterTemplate class to generate the filter items for any column, if the item (radcombobox, raddatapicker, ecc) include a clientside event then others controls outside the grid doesn't work propertly.
For example i have a raddatepicker with a DatePopupButton visible outside the grid , after the page load if i click the popupbutton it shows the popup fine; but after an edit/insert of a value in the grid the popupbutton don't show the popup !.
So, my question is, how a programatically definition of a filter template column with clientside events may cause undesired operation of others controls..
This is the code of my filter template class... that as i said before it works perfectly on the grid.
private
class
MyFilterColumn : ITemplate
{
private
Telerik.Web.UI.RadComboBox combo;
private
RadDatePicker _rdp;
protected
CommonParameters.GridTemplateColumnType type;
protected
string
fieldvalue;
protected
string
fieldtext;
public
MyFilterColumn(
string
Fieldvalue,
string
Fieldtext, CommonParameters.GridTemplateColumnType Type)
{
fieldvalue = Fieldvalue;
fieldtext = Fieldtext;
type = Type;
}
public
void
InstantiateIn(Control container)
{
switch
(type)
{
case
CommonParameters.GridTemplateColumnType.ComboOnDemand:
{
combo =
new
Telerik.Web.UI.RadComboBox();
combo.ID = String.Format(
"RadComboBox{0}"
, fieldtext);
combo.AppendDataBoundItems =
true
;
if
(fieldvalue.Length > 0)
combo.DataTextField = fieldtext.Substring(fieldtext.IndexOf(
"."
) + 1, (fieldtext.Length - (fieldtext.IndexOf(
"."
) + 1)));
combo.DataValueField = fieldvalue;
combo.EmptyMessage =
"niente"
;
combo.Items.Insert(0,
new
Telerik.Web.UI.RadComboBoxItem(
"Tutti"
));
combo.Enabled =
true
;
combo.DataBound += combo_DataBound;
combo.DataBinding +=
new
EventHandler(combo_DataBinding);
combo.OnClientSelectedIndexChanged = String.Format(
"ClientComboFilterSelected_{0}"
, fieldvalue);
container.Controls.Add(combo);
}
break
;
case
CommonParameters.GridTemplateColumnType.Date:
{
_rdp =
new
RadDatePicker();
_rdp.ID =
"rdpf"
+ fieldvalue;
_rdp.Width =
new
System.Web.UI.WebControls.Unit(CommonParameters.RadDatePickerWidth);
_rdp.DbSelectedDate = _rdpf_DataBinding((GridItem)container.NamingContainer);
string
script =
"function ClientDataPickerFilterSelected_"
+ fieldvalue +
"(sender,args) {var tableView=$find(\""
+ ((GridItem)container.NamingContainer).OwnerTableView.ClientID +
"\"); var date= FormatSelectedDate(sender);if (date != '') { alert('data:' + date); tableView.filter(\""
+ fieldvalue +
"\",date,\"EqualTo\");} else { tableView.filter(\""
+ fieldvalue +
"\",date,\"NoFilter\"); } }"
;
// tableView.filter(\"" + fieldvalue + "\" ,date,\"NoFilter\");
_rdp.ClientEvents.OnDateSelected = script;
container.Controls.Add(_rdp);
}
break
;
}
}
DateTime? _rdpf_DataBinding(GridItem pGriditem)
{
if
((pGriditem).OwnerTableView.GetColumn(fieldvalue).CurrentFilterValue ==
string
.Empty)
{
return
new
DateTime?();
}
else
{
return
DateTime.Parse((pGriditem).OwnerTableView.GetColumn(fieldvalue).CurrentFilterValue);
}
}
void
combo_DataBinding(
object
sender, EventArgs e)
{
combo.DataSource = GetData();
}
public
IList GetData()
{
IList mydata;
using
(DMWEntities ctx =
new
DMWEntities())
{
mydata = (from c
in
ctx.Cli_for
orderby c.Denominazione
select
new
{ IdFornitore = c.IdCLiFor, c.Denominazione }).ToList();
}
return
mydata;
}
void
combo_DataBound(
object
sender, EventArgs e)
{
Page page = HttpContext.Current.Handler
as
Page;
Telerik.Web.UI.RadComboBox combo = (Telerik.Web.UI.RadComboBox)sender;
GridItem container = (GridItem)combo.NamingContainer;
string
script =
"function ClientComboFilterSelected_"
+ fieldvalue +
"(sender,args) {var tableView=$find(\""
+ ((GridItem)container).OwnerTableView.ClientID +
"\");if (tableView)alert(args.get_item().get_value());tableView.filter(\""
+ fieldvalue +
"\",args.get_item().get_value(),\"EqualTo\");}"
;
ScriptManager.RegisterStartupScript(page, page.GetType(), String.Format(
"ClientComboFilterSelected_{0}"
, fieldvalue), script,
true
);
combo.SelectedValue = container.OwnerTableView.GetColumn(fieldvalue).CurrentFilterValue;
}
}