RadGrid 自定义过滤器在回发时丢失值
我在使用 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();
}
}
我需要有关如何在单击导致回发的过滤器按钮后修复控件中丢失的值的帮助。
问候,
赫尔沃耶
I have a problem regarding filtering with Radgrid using FilterTemplates. I bind values into the controls within FilterTemplates inside ItemDataBound event and binding works perfectly except when I click "Filter" button I lose my values.
This is the code from ItemDataBound event in which I bind the values to the controls:
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();
}
}
The following code is click event which filters the 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();
}
}
I need help on how to fix lost values from controls after clicking filter button which causes postback.
Regards,
Hrvoje
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论