Correct display of SPList and Refreshing? [solved]
-
Hello everybody, I'm currently working on a project where I have to develope an Sharepoint web part. My webpart does fetch external data from an MS SQL database and add each entry in a SPList, I created programmatically before. Furthermore I have an form where you can filter each list field by check/uncheck some checkboxes. For example if I uncheck the Checkbox "RAM" I want to hide the column "RAM" of my list. This works well. But if I check this checkbox again, the column will not be shown. In the List which was created in the sharepoint website content, everything works fine but not so in the list I render in my webpart. I searched a long time for a solution but I can't find what I've made wrong. So my question is: how I can correctly render and refresh a SPList? My source code follows below. Thanking you in anticipation for reading and helping. PS: sorry for my terrible english ;) Best regards nki ----------------------------------------------------------------- After button click, the sql statement will be assembled. Furthermore the the list will be rendered.
private void SubmitClick(object sender, EventArgs e) { string sqlSelects = "select "; if (m\_cbShowPC.Checked) sqlSelects += "pc.LI\_PCNAME,"; if (m\_cbShowOS.Checked) sqlSelects += "os.LI\_TYPE,"; if (m\_cbShowSP.Checked) sqlSelects += "os.LI\_SERVICEPACK,"; if (m\_cbShowUUID.Checked) sqlSelects += "pc.LI\_UUID,"; if (m\_cbShowName.Checked) sqlSelects += "acc.LI\_USERFULLNAME,"; if (m\_cbShowCPU.Checked) sqlSelects += "cpu.LI\_NAME,"; if (m\_cbShowCores.Checked) sqlSelects += "cpu.LI\_NUMCORES,"; if (m\_cbShowMHz.Checked) sqlSelects += "cpu.LI\_MHZ,"; if (m\_cbShowRAM.Checked) sqlSelects += "ram.LI\_SIZE,"; if (m\_cbShowIP.Checked) sqlSelects += "net.LI\_IPADDRESS,"; if (m\_cbShowSubnet.Checked) sqlSelects += "net.LI\_SUBNETMASK"; m\_SqlQuery = sqlSelects + " from LI\_ACCOUNT acc " + "INNER JOIN LI\_PCINFO pc ON acc.LA\_ID = pc.LA\_ID " + "INNER JOIN LI\_OS os ON acc.LA\_ID = os.LA\_ID " + "INNER JOIN LI\_CPU cpu ON acc.LA\_ID = cpu.LA\_ID " + "INNER JOIN LI\_RAM ram ON acc.LA\_ID = ram.LA\_ID " + "INNER JOIN LI\_NET net ON acc.LA\_ID = net.LA\_ID " + "where " +
-
Hello everybody, I'm currently working on a project where I have to develope an Sharepoint web part. My webpart does fetch external data from an MS SQL database and add each entry in a SPList, I created programmatically before. Furthermore I have an form where you can filter each list field by check/uncheck some checkboxes. For example if I uncheck the Checkbox "RAM" I want to hide the column "RAM" of my list. This works well. But if I check this checkbox again, the column will not be shown. In the List which was created in the sharepoint website content, everything works fine but not so in the list I render in my webpart. I searched a long time for a solution but I can't find what I've made wrong. So my question is: how I can correctly render and refresh a SPList? My source code follows below. Thanking you in anticipation for reading and helping. PS: sorry for my terrible english ;) Best regards nki ----------------------------------------------------------------- After button click, the sql statement will be assembled. Furthermore the the list will be rendered.
private void SubmitClick(object sender, EventArgs e) { string sqlSelects = "select "; if (m\_cbShowPC.Checked) sqlSelects += "pc.LI\_PCNAME,"; if (m\_cbShowOS.Checked) sqlSelects += "os.LI\_TYPE,"; if (m\_cbShowSP.Checked) sqlSelects += "os.LI\_SERVICEPACK,"; if (m\_cbShowUUID.Checked) sqlSelects += "pc.LI\_UUID,"; if (m\_cbShowName.Checked) sqlSelects += "acc.LI\_USERFULLNAME,"; if (m\_cbShowCPU.Checked) sqlSelects += "cpu.LI\_NAME,"; if (m\_cbShowCores.Checked) sqlSelects += "cpu.LI\_NUMCORES,"; if (m\_cbShowMHz.Checked) sqlSelects += "cpu.LI\_MHZ,"; if (m\_cbShowRAM.Checked) sqlSelects += "ram.LI\_SIZE,"; if (m\_cbShowIP.Checked) sqlSelects += "net.LI\_IPADDRESS,"; if (m\_cbShowSubnet.Checked) sqlSelects += "net.LI\_SUBNETMASK"; m\_SqlQuery = sqlSelects + " from LI\_ACCOUNT acc " + "INNER JOIN LI\_PCINFO pc ON acc.LA\_ID = pc.LA\_ID " + "INNER JOIN LI\_OS os ON acc.LA\_ID = os.LA\_ID " + "INNER JOIN LI\_CPU cpu ON acc.LA\_ID = cpu.LA\_ID " + "INNER JOIN LI\_RAM ram ON acc.LA\_ID = ram.LA\_ID " + "INNER JOIN LI\_NET net ON acc.LA\_ID = net.LA\_ID " + "where " +
Hello again, I've solved this problem. I had to delete the view of the SPList before: I just add the following code at the end of AddView():
try { SPView view = m\_InventList.Views\["Overview"\]; if (view != null) m\_InventList.Views.Delete(view.ID); } catch (System.Exception) { } m\_InventList.Views.Add("Overview", strColl, @"", 200, true, true, SPViewCollection.SPViewType.Html, false); m\_InventList.Update();
Best regards nki