Let me cut to the chase. My scenario is as follows: I have custom added fields to filter the RadGrid and filtering works perfectly. The problem comes when I want to edit record using EditForm inside RadGrid. It used to work fine, but then I had some problems with selecting the right row (I was always getting the wrong row selected) so this is what I did to fix it.
So, my RadGrid with filters looks like this:
What I did is to use the Session which will help us to determine later if the filtered RadGrid DataSource was initiated or it was the default one.
protected void btnSearch_Click(object sender, EventArgs e)
{
Session["SearchKontakti"] = "1";
}
After that I had to set PreRender with if loop to check for previously mentioned Session.
protected void gvKontakti_PreRender(object sender, EventArgs e)
{
int idKontakt = Convert.ToInt32(Request.QueryString["idk"]);
if (Session["SearchKontakti"] == "1")
{
var kontakti = from k in db.Kontakt
select k;
int idTipUsera = Convert.ToInt32(rcbTipUsera.SelectedValue);
int idTvrtka = Convert.ToInt32(rcbTvrtka.SelectedValue);
if (rcbTvrtka.SelectedValue != "0")
{
kontakti = kontakti.Where(k => k.idFirma == idTvrtka);
}
if (rcbTipUsera.SelectedValue != "0")
{
kontakti = kontakti.Where(k => k.idOvlasti == idTipUsera);
}
if (chkAktivan.Checked == true)
{
kontakti = kontakti.Where(k => k.Aktivan == true);
}
else
{
kontakti = kontakti.Where(k => k.Aktivan == false);
}
int idAuthKontakt = Convert.ToInt32(Session["authenticatedUI"]);
if (idKontakt > 0 && idAuthKontakt == idKontakt)
{
gvKontakti.DataSource = from k in kontakti
where k.idKontakt == idKontakt
orderby k.Prezime, k.Ime
select new { Tvrtka = k.Firma.Naziv, k.idKontakt, Naziv = k.Ime + " " + k.Prezime, Funkcija = k.Funkcija, k.Ime, k.Prezime, k.Tel1, k.Tel2, k.Mob1, k.Mob2, k.Email1, k.Email2, k.Fax, k.Adresa1, k.Adresa2, k.Adresa3, k.Grad, k.PostanskiBroj, k.Drzava, k.Biljeske, k.Aktivan, k.Username, k.Password };
}
else if (idKontakt > 0 && idAuthKontakt != idKontakt)
{
gvKontakti.DataSource = from k in kontakti
where k.idKontakt == idKontakt
orderby k.Prezime, k.Ime
select new { Tvrtka = k.Firma.Naziv, k.idKontakt, Naziv = k.Ime + " " + k.Prezime, Funkcija = k.Funkcija, k.Ime, k.Prezime, k.Tel1, k.Tel2, k.Mob1, k.Mob2, k.Email1, k.Email2, k.Fax, k.Adresa1, k.Adresa2, k.Adresa3, k.Grad, k.PostanskiBroj, k.Drzava, k.Biljeske, k.Aktivan, k.Username, k.Password };
}
else
{
gvKontakti.DataSource = from k in kontakti
orderby k.Prezime, k.Ime
select new { Tvrtka = k.Firma.Naziv, k.idKontakt, Naziv = k.Ime + " " + k.Prezime, Funkcija = k.Funkcija, k.Ime, k.Prezime, k.Tel1, k.Tel2, k.Mob1, k.Mob2, k.Email1, k.Email2, k.Fax, k.Adresa1, k.Adresa2, k.Adresa3, k.Grad, k.PostanskiBroj, k.Drzava, k.Biljeske, k.Aktivan, k.Username, k.Password };
}
gvKontakti.DataBind();
}
}
So, this fixed my primary problem, but gave me another one. Some of my UserControls contain UpdatePanel and for each UserControl that has it whenever I try to clik Edit button from the RadGrid I receive the following message: "Cannot unregister UpdatePanel with ID 'UpdatePanel4' since it was not registered with the ScriptManager. This might occur if the UpdatePanel was removed from the control tree and later added again, which is not supported. Parameter name: updatePanel"
What I'd like to know is how to fix it.
Regards,
Hrvoje