SharePoint - Custom VIew in DVWP

Asked By jc dls
02-Nov-11 03:43 AM

i found a way to modify the views programatically in a custom list using this site http://www.devx.com/dotnet/Article/31762/1954

but this only applies to a listview is there a way we can also apply modify views programatically in a dataview webpart..


  Reena Jain replied to jc dls
02-Nov-11 04:10 AM
Hi,

If you need to retrieve items from a list when developing web parts, application pages or custom field types you can best use the SPQueryobject from the SharePoint object model. This object is located in the Microsoft.SharePoint namespace of the Microsoft.SharePoint.dll located in the Global Assembly Cache.

Instantiate the object as follows:

SPQuery qry = new SPQuery();

The most important property is the Query property, which needs to be set to your CAML query:

string camlquery = "<OrderBy><FieldRef Name='Country' /></OrderBy><Where>"
    + "<Eq><FieldRef Name='LastName' /><Value Type='Text'>Smith</Value></Eq>"
    + </Where>";
qry.Query = camlquery;

At this point you can execute the query on your list:

SPListItemCollection listItemsCollection = list.GetItems(qry);

A small remark with the GetItems method of the SPList instance: this method returns a collection of type SPListItemCollection. It is possible that it is easier working with a DataTable. In that case you can execute the query as follows:

DataTable listItemsTable = list.GetItems(qry).GetDataTable();

let me know whether its working for you or not
  Vickey F replied to jc dls
02-Nov-11 04:34 AM
Use this code-

try

        {

    SPSite oSite = new SPSite([Site URL]);// change it to your sharepoint site URL

          SPWeb oWeb = oSite.OpenWeb();

          SPList oList = oWeb.Lists["shared documents"];        

 

          SPLimitedWebPartManager oWebPartManager = oWeb.GetLimitedWebPartManager("Shared%20Documents/MyCustomPage.aspx", PersonalizationScope.Shared);// change the wepart page absolute URL to your webpart page URL

          foreach (System.Web.UI.WebControls.WebParts.WebPart oWebpart in oWebPartManager.WebParts)

          {

            if (oWebpart.GetType().Name == "ListViewWebPart")

            {

              ListViewWebPart myWebPart = (ListViewWebPart)oWebpart;

 

              SPView doclibview = oList.Views[“MyCustomView”];

 

              Guid oGuid = new Guid(myWebPart.ViewGuid);

              SPView oWebPartView = oList.Views[oGuid];

 

              oWebPartView.ViewFields.DeleteAll();// deleting the existing view fields for adding new one

 

              foreach (string strField in doclibview.ViewFields)

              {

                oWebPartView.ViewFields.Add(strField);

              }

              oWebPartView.Query = doclibview.Query;

              oWebPartView.RowLimit = doclibview.RowLimit;

              oWebPartView.ViewEmpty = doclibview.ViewEmpty;

              oWebPartView.ViewFooter = doclibview.ViewFooter;

              oWebPartView.ViewHeader = doclibview.ViewHeader;

              oWebPartView.Scope = doclibview.Scope;

              oWebPartView.GroupByFooter = doclibview.GroupByFooter;

              oWebPartView.GroupByHeader = doclibview.GroupByHeader;

              oWebPartView.Update();

 

              myWebPart.ViewGuid = oWebPartView.ID.ToString("B").ToUpper();

              myWebPart.Visible = true;

              myWebPart.Title = "My title";

              oWebPartManager.SaveChanges(myWebPart);

 

              break;

 

            }

          }

          oWeb.Update();  

 

        }

        catch (Exception ex)

        {

          MessageBox.Show(ex.Message);

        }



Try thsi and let me know.
  Riley K replied to jc dls
02-Nov-11 04:47 AM


Recently I came across a situation where I had to add a checkbox to each row of a DFWP and retrieve values of that check boxes in a HTML button click.

Here is what I added in my DFWP’s XSLT to get a check box in each row.

  1. In SPD, add a Data View webpart to the page Date View >Insert Data View
  2. Configure columns
  3. Add an extra column to the left of the rendered data view (you can do this by selecting any left most cell and then Table > Insert > Column to the Left)
  4. In the newly generated column, select first (or any <TD>) and then add a HTML check box (Insert > HTML > then Input (Checkbox)
    SPD view
  5. Set the value property of the checkbox to use ID column’s value
  6. Also add a html button somewhere outside the DFWP. In my example, I will attach an event handler that will read the check box values into an Array. <input
    id=”actionButton”
    type=button
    value=”Get Selected Item IDs”
    />
  7. Now add the following script just after the button element.

    <script>

    document.getElementById(“actionButton”).onclick = function() {


    var idValues = new Array();

    $(“input:checkbox:checked”).each(function() {

    idValues.push(this.value);

    })

    alert(idValues.toString());

    }

    </script>

     

  8. Here is the output

 

 

Regards

  Sree K replied to jc dls
02-Nov-11 04:52 AM

1. Using SharePoint designer, insert a data view web part onto the page you want to display in the list by selecting Data View > Insert Data View from the main menu.

data-view-web-part-insert

2. Using the Data Source Library Task Pane in SharePoint designer select ‘Connect to another library‘ and browse to the site that contains the list you wish to display.

sharepoint-designer-data-source-library sharepoint-designer-connect-external-library

3. Expand the new site in the Data Source Library Task Pane and select the list or library that contains the information you wish to display. From the drop down select ‘Show Data‘ to populate the Data Preview tab.

sharepoint-designer-show-data

4. From the list of columns, select the ones that you wish to display and select ‘Insert selected fields as… multiple item view’ from the drop down menu at the top of the window. This will populate the data view with sample information (in a table by default). At this stage you may get an error in the design view that states:

“The server returned a non-specific error when trying to get data from the data source. Check the format and content of your query and try again. If the problem persists, contact the server administrator”.

sharepoint-designer-data-view-non-specific-error

This can be corrected by modifying the <SelectParameters> tag of the <SharePoint:SPDataSource> element of the data view to contain the reletive url of the site for the WebUrl parameter (look at the default parameters to find this out – should be something similar to ‘/news/’).

data-view-web-part-data-source-weburl

5. (Optional) Modify the XSL for the data view to display the information in the format you require. By default there is often a large amount of redundant information, and in simple cases can be replaced with the following:


<XSL>
<xsl:stylesheet ...>
<xsl:output method="html" indent="no"/>
<xsl:template match="/">
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
<ul>
<xsl:for-each select="$Rows">
<li>
<a href="{substring-before(@URL, ', ')}"><xsl:value-of select="substring-after(@URL, ', ')"/></a>
</li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
</XSL>

6. Now you have the basic data coming through you can select to filter, sort, group or perform other data view related tasks by clicking on the arrow next to the data view in design view. I will cover some of these options in a later post.

Create New Account
help
custom data source SharePoint We have a WSS 3 site running off default database schemas. What we need to do is have the data that is displayed in lists, calendars etc to come from, and get written to, a different SQL data source. This data would be subject to edits, deletes as well as, of course, adding new data. For example if I create a new calendar entry I should be able to edit
wss3 -populate lookup from external data source? SharePoint what is the best way of populating a lookup in a list from an external data source? we can populate a dataview web part from an external datasource (in designer) but that not appear in the list of web parts when configuring a new list column thx SharePoint Development Discussions MOSS (1) UI (1) External (1) Business (1) Populate (1) Catalog (1) Source (1) Server (1) I doubt you can do it. Its probably easiest to either write an app to import ur data and schedule it, or create a web part for that UI. Are you thinking of
Use of external xml file in wsp webpart to storing and retriving data Hi, I have created an xml file with this code. Named as PageSize.xml. <?xml value in another webpart. Please give me solutin if any. Many thanks Narendra Exploring the Data View Web Part Companies typically use a multitude of repository types to store and manage their data. A company may use SQL Server to store relational data; the Windows file system for storing semi-structured data and eXtensible Markup Language (XML) files to hold hierarchical data. The need to aggregate and manage data in a central location is a very common requirement within portal environments. To cater to this need, you could build custom Web Parts using Visual Studio.NET to incorporate various data sources. Instead, for a range of scenarios, you will want to try to use the
I added the right permissions on the content type. Then, I created a column "external data" in Sharepoint that I linked to my content type. When I want to change the data in this column in a list , for example, an error says: An error occurred when retrieving data " name of the database ." For more information administrators can view the server log . Can you EventID Level Message Correlation 11 / 13 / 2011 00:08:30.31 w3wp.exe (0x1D9C) 0x1038 SharePoint Foundation Monitoring nasq Medium Entering monitored scope (Request (GET:http: / / tricoflex:80 / CRM / _layouts / FldNewEx Cust%2E%20Relation%20ID&DescriptionParam = &VldFormulaParam = &VldMessageParam = )) 11 / 13 / 2011 00:08:30.31 w3wp.exe (0x1D9C) 0x1038 SharePoint Foundation Logging Correlation Data xmnv Medium Name = Request (GET:http: / / tricoflex:80 / CRM / _layouts / FldNewEx.aspx?List = %7B4E776DA0%2D583C%2D40C3%2D8F91%2DBBE615D5295B%7D&FieldTypeParam e307-4c5d-b470-c4351e5dff53 11 / 13 / 2011 00:08:30.32 w3wp.exe (0x1D9C) 0x1038 SharePoint Foundation Logging Correlation Data xmnv Medium Site = / 9694064f-e307-4c5d-b470-c4351e5dff53 11 / 13 / 2011
sharepoint designer - data source connection SharePoint When trying to create access to an sql server with data source connection wizard i just can get the connection done. error returns to contact the server admin, 'the data retrieval service encountered an error during connection to the data source.' after contact the server admin, the credentials were ok. have tried both provider names