我在使用FilterTemplates过滤Radgrid时遇到问题。我将值绑定到ItemDataBound事件中的FilterTemplates内的控件中,并且绑定工作正常,除非我单击“过滤器”按钮时丢失了我的值。
这是ItemDataBound事件中的代码,我将值绑定到控件:
protected void gvDaily_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridFilteringItem)
{
GridFilteringItem filterItem = (GridFilteringItem)e.Item;
RadComboBox rcbManagerDailyFilter = (RadComboBox)filterItem.FindControl("rcbManagerDailyFilter");
RadComboBox rcbTvrtkaDailyFilter = (RadComboBox)filterItem.FindControl("rcbTvrtkaDailyFilter");
RadComboBox rcbDolazakDailyFilter = (RadComboBox)filterItem.FindControl("rcbDolazakDailyFilter");
rcbManagerDailyFilter.Items.Clear();
rcbTvrtkaDailyFilter.Items.Clear();
rcbDolazakDailyFilter.Items.Clear();
rcbDolazakDailyFilter.Items.Add(new RadComboBoxItem("Odaberi vrstu", "0"));
rcbDolazakDailyFilter.Items.Add(new RadComboBoxItem("Rad", "1"));
rcbDolazakDailyFilter.Items.Add(new RadComboBoxItem("Dolazak", "2"));
rcbDolazakDailyFilter.Items.Add(new RadComboBoxItem("Sve", "3"));
var kontaktiList = (from k in db.Kontakt
select k).ToList();
var kontaktiM = from k in kontaktiList
orderby k.Prezime, k.Ime
where k.Firma.Naziv == "IDE3"
select new { k.idKontakt, Osoba = k.Ime + " " + k.Prezime };
rcbManagerDailyFilter.Items.Add(new RadComboBoxItem("Odaberi managera", "0"));
rcbManagerDailyFilter.DataSource = kontaktiM;
rcbManagerDailyFilter.DataValueField = "Osoba";
rcbManagerDailyFilter.DataTextField = "Osoba";
rcbManagerDailyFilter.DataBind();
var tvrtkaList = from t in db.Firma
orderby t.Naziv
select new { t.idFirma, t.Naziv };
rcbTvrtkaDailyFilter.Items.Add(new RadComboBoxItem("Odaberi tvrtku", "0"));
rcbTvrtkaDailyFilter.DataSource = tvrtkaList;
rcbTvrtkaDailyFilter.DataValueField = "Naziv";
rcbTvrtkaDailyFilter.DataTextField = "Naziv";
rcbTvrtkaDailyFilter.DataBind();
}
}
以下代码是过滤RadGrid的点击事件:
protected void btnTrazi_Click(object sender, EventArgs e)
{
GridFilteringItem item = gvDaily.MasterTableView.GetItems(GridItemType.FilteringItem)[0] as GridFilteringItem;
RadComboBox rcbManagerDailyFilter = (RadComboBox)item.FindControl("rcbManagerDailyFilter");
RadComboBox rcbTvrtkaDailyFilter = (RadComboBox)item.FindControl("rcbTvrtkaDailyFilter");
RadDatePicker txtDatumPrijaveDailyOdFilter = (RadDatePicker)item.FindControl("txtDatumPrijaveDailyOdFilter");
RadDatePicker txtDatumPrijaveDailyDoFilter = (RadDatePicker)item.FindControl("txtDatumPrijaveDailyDoFilter");
RadioButtonList rblDolazakFilter = (RadioButtonList)item.FindControl("rblDolazakFilter");
string tvrtka = rcbTvrtkaDailyFilter.SelectedItem.Text;
string manager = rcbManagerDailyFilter.SelectedItem.Text;
string datumPrijaveOd = (txtDatumPrijaveDailyOdFilter.SelectedDate).ToString();
string datumPrijaveDo = (txtDatumPrijaveDailyDoFilter.SelectedDate).ToString();
string expression = "";
if (tvrtka != "Odaberi tvrtku")
{
expression += "([Tvrtka] = '" + tvrtka + "')";
}
if (manager != "Odaberi managera")
{
expression += " AND ";
expression += "([DailyManager] = '" + manager + "')";
}
if (datumPrijaveOd.Length != 0)
{
expression += " AND ";
expression += "([Datum] >= '" + datumPrijaveOd + "')";
}
if (datumPrijaveDo.Length != 0)
{
expression += " AND ";
expression += "([Datum] <= '" + datumPrijaveDo + "')";
}
gvDaily.MasterTableView.FilterExpression = expression;
gvDaily.Rebind();
}
}
我需要有关如何在单击过滤器按钮后修复控件中丢失值的帮助,这会导致回发。
此致
赫尔沃耶