Pages

Showing posts with label webpart. Show all posts
Showing posts with label webpart. Show all posts

Saturday, August 16, 2014

How To: Load SharePoint web part User Control Inside another SharePoint web part without C# Coding

simple way to Load SharePoint web part User Control Inside another  SharePoint web part without C# Coding is done by :

  1. registering the user control
    <%@ Register src="webPartUC.ascx" tagname="webPartUC" tagprefix="uc" %>

  2. loading the user control <uc:webPartUC ID="webPartUC1" runat="server" />
if you wanted to pass webpart properties.. all you have to do is to specify the values as follows:
<uc:webPartUC ID="webPartUC1" LabelText="TEXT" runat="server" />

if you wanted to pass webpart properties from within a DataList Control Items .. all you have to do is to specify the values as follows making sure to add the below line inside the DataList:

 <asp:DataList ID="usersDL" runat="server" Width="100%" >
   <ItemTemplate>
         <uc:webPartUC ID="webPartUC1"
              LabelText=<%# Eval("userName")%> runat="server" />

    </ItemTemplate>
 </asp:DataList>


Thats it :)

    

Saturday, May 17, 2014

Embed PDF in HTML Page


To Embed PDF files in HTML Page You can use below snippet of code, It works in most browser versions (Chrome, Firefox, IE,... ).

if it is not supported, it shows the message "The PDF cannot be displayed."

<div id="pdf">
<object width="900" height="1000" type="application/pdf" data="/filepath/filename.pdf?#zoom=85&scrollbar=0&toolbar=0&navpanes=0" id="pdf_content">
<p>The PDF cannot be displayed. <a href="/filepath/filename.pdf" target="_top">download</a>.</p>
</object>
</div>

Above snippet of code sets the zoom to 85%, removes scrollbars, toolbars and nav panes.

Hope it helps J

Saturday, November 30, 2013

How to bind LINQ data to DataGrid

Let's assume we have a Web Service which will return the results as an object for IN and OUT data records.
The following will explain how to use LINQ to query and then bind the results to the asp:DataGrid


C# code:
//query to get currunt month data ordered by LOCAL_TIME then TYPE
 var thisMonthData = eData.Contents
.OrderByDescending(o => o.LOCAL_TIME)
.OrderByDescending(o2 => o2.TYPE)
.Where(m => m.DATE.Substring(0, 6)
== DateTime.Today.ToString("yyyyMM", arCulture));
 
//Bind Data
eDataGrid.DataSource = thisMonthData;
eDataGrid.DataBind();
 
//query to get currunt month data ordered by LOCAL_TIME for TYPE=IN
var thisMonthDataIn = eData.Contents
.OrderByDescending(o => o.LOCAL_TIME)
.Where(r => r.TYPE == "IN")
.Where(m => m.DATE.Substring(0, 6) == DateTime.Today.ToString("yyyyMM", arCulture));
 
//Bind Data
eINDataGrid.DataSource = thisMonthDataIn;
eINDataGrid.DataBind();
 
//query to get currunt month data ordered by LOCAL_TIME for TYPE=OUT
var thisMonthDataOut = eData.Contents
.OrderByDescending(o => o.LOCAL_TIME)
.Where(r => r.TYPE == "OUT")
.Where(m => m.DATE.Substring(0, 6) == DateTime.Today.ToString("yyyyMM", arCulture));
 
//Bind Data
eOUTDataGrid.DataSource = thisMonthDataOut;
eOUTDataGrid.DataBind();

 

Markup:


                     
<asp:DataGrid CssClass="gvTbl" ID="eINDataGrid" runat="server"  AutoGenerateColumns="true">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle BackColor="#DAF1F2" HorizontalAlign="Right" />
<AlternatingItemStyle BackColor="#ECE9EA" />
<Columns>
</Columns>
</asp:DataGrid>
 
<asp:DataGrid CssClass="gvTbl" ID="eOUTDataGrid" runat="server"  AutoGenerateColumns="true">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle BackColor="#DAF1F2" HorizontalAlign="Right" />
<AlternatingItemStyle BackColor="#ECE9EA" />
<Columns>
</Columns>
</asp:DataGrid>
<asp:DataGrid CssClass="gvTbl" ID="eDataGrid" runat="server"  AutoGenerateColumns="true">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle BackColor="#DAF1F2" HorizontalAlign="Right" />
<AlternatingItemStyle BackColor="#ECE9EA" />
<Columns>
</Columns>
</asp:DataGrid>

Tuesday, September 3, 2013

Passing url parameters to webpart in SharePoint

To pass the URL parameters to a webpart page in SharePoint, we can't use the "Page Viewer" webpart because it does not allow us to use the parameters in the URL.

So we use teh "Content Editor" webpart since it allows us to embed javascript code in it. We can then use an "iframe" with a generated URL from a JavaScript with URL parameters from the webpart page's URL.

First, create a webpart page, then insert a content editor webpart in it with the following code:
<script type="text/javascript">
    function getQueryStringRegExp(name) {
        var reg = new RegExp("(^|\\?|&)"
+ name + "=([^&]*)(\\s|&|$)", "i");
        if (reg.test(location.href))
return unescape(RegExp.$2.replace(/\+/g, " "));
        return "";
    }
    document.write("<iframe src='http://www.sitename.com/default.aspx?param1="+ getQueryStringRegExp('param1') + "' width=100% height=100%></iframe>");
</script>

The function getQueryStringRegExp is used to retrieve the parameter value from the page url.

Referece: