Barbara Barbara

Barbara Barbara

  • NA
  • 55
  • 855

changing gridview after choose list in dropdownlist

Mar 23 2020 9:21 AM
hi all, 
I have 8 lists. These 8 lists have 7 fields in common. I would like it to change the grid when I choose one of the lists with the enter button, but not working. Please can u help me?
 
 this is aspx code 
 
<asp:Label ID="lblListaDiRiferimento" runat="server" Text="Lista di riferimento"></asp:Label>
<asp:DropDownList ID="ddlListaDiRiferimento" runat="server" OnSelectedIndexChanged="ddlListaDiRiferimento_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="1" Value="1"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
<asp:ListItem Text="3" Value="3"></asp:ListItem>
<asp:ListItem Text="4" Value="4"></asp:ListItem>
<asp:ListItem Text="5" Value="5"></asp:ListItem>
<asp:ListItem Text="6" Value="6"></asp:ListItem>
<asp:ListItem Text="7" Value="7"></asp:ListItem>
<asp:ListItem Text="8" Value="8"></asp:ListItem>
<asp:ListItem Text="--" Value=""></asp:ListItem>
</asp:DropDownList> 
 
 <asp:Button ID="btnCercaTitle" runat="server" Text="Cerca" OnClick="btnCerca_Click"/>
<asp:Button ID="btnAnnulla" runat="server" Text="Annulla" OnClick="btnAnnulla_Click"/>
 

<asp:GridView ID="grdItems" runat="server" AutoGenerateColumns="false" PageSize="10" AllowPaging="true" DataKeyNames="ID" >
<Columns>
<asp:CommandField ShowSelectButton="true" DeleteText="Seleziona Record"/>
<asp:BoundField DataField="Titolo" HeaderText="Titolo" />
<asp:BoundField DataField="Attivita" HeaderText="Attività" />
<asp:BoundField DataField="OrigineCSV" HeaderText="OrigineCSV" />
<asp:BoundField DataField="IDUtente" HeaderText="IDUtente" />
<asp:BoundField DataField="Utente" HeaderText="Utente" />
<asp:BoundField DataField="Esito" HeaderText="Esito" />
<asp:BoundField DataField="Causale" HeaderText="Causale" />
</Columns>
</asp:GridView>
 
 
 
 
 code ascx.cs
 
 
  protected void Page_Load(object sender, EventArgs e)
{
// _id = Page.Request.QueryString["ID"];
if (!Page.IsPostBack)
{
SPSecurity.RunWithElevatedPrivileges(delegate ()
{
using (SPSite ElevatedSite = new SPSite(SPContext.Current.Web.Site.ID))
using (SPWeb ElevatedWeb = ElevatedSite.OpenWeb(SPContext.Current.Web.ID))
{
//CaricaTendina(ElevatedWeb);
// CaricaGriglia(ElevatedWeb);
CaricaItem(ElevatedWeb);

}
});
}
}
protected void btnCerca_Click(object sender, EventArgs e)
{
SPSecurity.RunWithElevatedPrivileges(delegate ()
{
using (SPSite ElevatedSite = new SPSite(SPContext.Current.Web.Site.ID))
using (SPWeb ElevatedWeb = ElevatedSite.OpenWeb(SPContext.Current.Web.ID))
{
CaricaItem(ElevatedWeb);
}
});
}
protected void btnAnnulla_Click(object sender, EventArgs e)
{
SPSecurity.RunWithElevatedPrivileges(delegate ()
{
using (SPSite ElevatedSite = new SPSite(SPContext.Current.Web.Site.ID))
using (SPWeb ElevatedWeb = ElevatedSite.OpenWeb(SPContext.Current.Web.ID))
{
PulisciControlli();
CaricaItem(ElevatedWeb);
}
});
}
private void PulisciControlli()
{
txtAttivita.Text = "";
txtEsito.Text = "";
txtCausale.Text = "";
txtOrigineCSV.Text = "";
}

private void CaricaItem(SPWeb web)
{
SPList listaGestAtt = web.GetList(web.ServerRelativeUrl + "/Lists/");
SPListItemCollection items = listaGestAtt.GetItems();
var itemBindabili = from SPListItem i in items.Cast<SPListItem>()
select new
{
ID = i.ID, // va messo xk nella griglia hai DataKeyNames="ID"
Titolo = i["Title"],
Attivita = new SPFieldLookupValue(i["Attivit_x00e0_"] as String).LookupValue, // i["Attivit_x00e0_"], // va preso internal name del campo
OrigineCSV = new SPFieldLookupValue(i["OrigineCSV"] as String).LookupValue,
IDUtente = ControllaID(web, Convert.ToString(i["Utente"])),
Utente = ControllaUtente(web, Convert.ToString(i["Utente"])),
Esito = new SPFieldLookupValue(i["Esito"] as String).LookupValue,
Causale = new SPFieldLookupValue(i["Causale"] as String).LookupValue
};
grdItems.DataSource = itemBindabili.ToList();
grdItems.DataBind();
}
private string ControllaUtente(SPWeb web, string fieldValue)
{
if (!string.IsNullOrEmpty(fieldValue))
return new SPFieldUserValue(web, fieldValue).User.Name;
else
return (fieldValue);
}
private int ControllaID(SPWeb web, string fieldValue)
{
if (!string.IsNullOrEmpty(fieldValue))
return new SPFieldUserValue(web, fieldValue).User.ID;
else
return -1;
}
protected void ddlListaDiRiferimento_SelectedIndexChanged(object sender, EventArgs e)
{
string value = ddlListaDiRiferimento.SelectedValue;
}
 
 

Answers (3)