Bonjour à tous,
Je me permets de solliciter votre aide pour le tri dans un tableau d'un webpart de SharePoint qui ne veut pas se faire.
Voila mon code, si quelqu'un a une petite minute pour y jeter un petit coup d'oeil :
private void BuildDataSet(int mode)
{
if (SelectedDoc == null)
{
foreach (SPList sp in doclists)
{
if (sp.Title.ToString() == "RDD")
{
docList = sp;
}
}
}
else
{
docList = SelectedDoc.List ;
this.oData.Tables[0].Rows.Clear ();
HttpContext.Current.Session["dataSet"] = oData;
Update_Data(mode);
this.oGrid.DataBind();
}
//On dit à Sharepoint de ne pas rediriger automatiquement vers la page "Accès Refusé"
SPContext.Current.Site.CatchAccessDeniedException = false;
//On vérifie si l'utilisateur peut ajouter des éléments
if (docList.DoesUserHavePermissions(SPBasePermissions.AddListItems))
{
this.btn_Delete.Enabled = true;
this.btn_Delete.Visible = true;
}
else
{
this.btn_Delete.Enabled = false;
this.btn_Delete.Visible = false;
}
DataSet dsSession = HttpContext.Current.Session["dataSet"] as DataSet;
if (dsSession == null)
{
//Add a table
this.oData = new DataSet();
this.oData.Tables.Add();
this.oData.Tables[0].TableName = "RDD";
this.oData.Tables[0].Columns.Add("LinkFilename");
this.oData.Tables[0].Columns.Add("Rdd_No");
this.oData.Tables[0].Columns.Add("Debtor_Name");
this.oData.Tables[0].Columns.Add("Loading_Date");
DataColumn chk = new DataColumn("Selection", typeof(bool));
chk.DefaultValue = false;
chk.ReadOnly = false;
this.oData.Tables[0].Columns.Add(chk);
HttpContext.Current.Session["dataSet"] = oData;
Update_Data(mode);
}
else
{
oData = dsSession;
}
this.oGrid.DataBind();
}
private void Update_Data(int mode)
{
SPListItemCollection SelectedList = null;
if (mode == 0)
SelectedList = docList.Items;
else
SelectedList = SelectedDoc;
foreach (SPListItem listItem in SelectedList)
{
DataRow row1 = this.oData.Tables[0].NewRow();
row1["LinkFilename"] = listItem.Web.Url + "/" + listItem.ParentList.Title + "/" + listItem["LinkFilename"].ToString();
row1["Rdd_No"] = listItem["Rdd No"].ToString();
row1["Debtor_Name"] = listItem["Debtor Name"].ToString();
row1["Loading_Date"] = listItem["Loading Date"].ToString();
this.oData.Tables[0].Rows.Add(row1);
}
}
protected override void CreateChildControls()
{
//Make sure we call this first as required by the ajax base part.
base.CreateChildControls();
string site_name = (string)config.GetValue("Site", typeof(string));
using (CurentSite = new SPSite(site_name))
{
CurentSite.AllowUnsafeUpdates = true;
CurentSite.CatchAccessDeniedException = false;
//SPWeb CurrentWeb = CurentSite.OpenWeb();
using (CurrentWeb = CurentSite.OpenWeb())
{
CurrentWeb.AllowUnsafeUpdates = true;
doclists = CurrentWeb.GetListsOfType(SPBaseType.DocumentLibrary);
}
}
this.BuildDataSet(0);
this.oGrid.AutoGenerateColumns = false;
this.Controls.Add(oGrid);
this.oGrid.DataSource = this.GetGridDataSource();
this.oGrid.DataKeyNames = new string[] { "ID" };
this.oGrid.AllowSorting = true;
this.oGrid.AllowPaging = true;
this.oGrid.PagerTemplate = null;
this.oGrid.PageSize = (int)config.GetValue(("Page_Size"), typeof(int));
this.oGrid.PagerSettings.Mode = PagerButtons.NumericFirstLast ;
this.oGrid.PageIndexChanging += new System.Web.UI.WebControls.GridViewPageEventHandler(oGrid_PageIndexChanging);
this.oGrid.Sorting += new GridViewSortEventHandler(oGrid_Sorting);
//Add columsns the gridview control..
TemplateField colonneChk = new TemplateField();
colonneChk.HeaderText = "";
colonneChk.ItemTemplate = new ColonneModele(this, TypeColonne.CheckBox, "Choix");
this.oGrid.Columns.Add(colonneChk);
//Ajout de colonne Modele
TemplateField colonneModele = new TemplateField();
colonneModele.HeaderText = "";
colonneModele.ItemTemplate = new ColonneModele(this, TypeColonne.Image, "Document");
this.oGrid.Columns.Add(colonneModele);
////Add columsns the gridview control..
BoundField colFirstName = new BoundField();
colFirstName.DataField = "Rdd_No";
colFirstName.HeaderText = "Rdd No";
colFirstName.SortExpression = "Rdd_No";
this.oGrid.Columns.Add(colFirstName);
BoundField colFirstName1 = new BoundField();
colFirstName1.DataField = "Debtor_Name";
colFirstName1.HeaderText = "Debtor Name";
colFirstName1.SortExpression = "Debtor_Name";
this.oGrid.Columns.Add(colFirstName1);
BoundField colFirstName2 = new BoundField();
colFirstName2.DataField = "Loading_Date";
colFirstName2.HeaderText = "Loading Date";
colFirstName2.SortExpression = "Loading_Date";
this.oGrid.Columns.Add(colFirstName2);
BoundField colFirstNameDerniere = new BoundField();
colFirstNameDerniere.DataField = "ID";
colFirstNameDerniere.Visible = false;
this.oGrid.Columns.Add(colFirstNameDerniere);
this.oGrid.HeaderStyle.Font.Bold = true;
this.oGrid.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
this.oPanel = new HtmlTable();
CreateUserPanel();
this.Controls.Add(this.oPanel);
this.oGrid.DataBind();
HttpContext.Current.Session["dataSet"] = oData;
}
Merci d'avance !
Partager