Category Archives: .Net

SharePoint SPDataSource

Tired of writing codes and creating webparts? Here is a less code solution for SharePoint developers.

The SPDataSource control (Microsoft.SharePoint.WebControls.SPDataSource) means a lot to developers.

With less custom code one can quickly retrieve and display data from SharePoint lists and libraries.

This is how you can access list data from SharePoint. For select command you can use CAML query builder from U2U.

This data source can be used like a SQL data source which comes with standard controls.

<SharePoint:SPDataSource ID=”spdsSupervisor” runat=”server” DataSourceMode=”List” SelectCommand=”<Query><Where><Eq><FieldRef Name=’Heading’ /><Value Type=’Choice’>Questions</Value></Eq></Where></Query>”>

<asp:Parameter Name=”ListName” DefaultValue=”Feedback”/>


For data binding to any data bound controls this data source can be used. Given below is an example of using Data source with an asp grid view.

<asp:GridView runat=”server” id=”gvSupervisor” AutoGenerateColumns=”False” DataSourceID=”spdsSupervisor”
GridLines=”None” ForeColor=”#333333″ CellPadding=”4″ width=”100%”>

<FooterStyle BackColor=”#e2eeff” Font-Bold=”True” ForeColor=”White” />

<RowStyle BackColor=”#EFF3FB” Font-Size=”Smaller”/>


<asp:boundfield DataField=”Title” HeaderText=”Type” HeaderStyle-Font-Bold=”true” HeaderStyle-Font-Names=”verdana” HeaderStyle-ForeColor=”#525252″


<asp:templatefield HeaderText=”Rating”


    <asp:RadioButtonList runat=”server” id=”rblCourse”
RepeatDirection=”Horizontal” CssClass=”ms-radiotext”>











<PagerStyle HorizontalAlign=”Center” BackColor=”#2461BF”
ForeColor=”White” />

<SelectedRowStyle BackColor=”#D1DDF1″ Font-Bold=”True”

<HeaderStyle BackColor=”#e2eeff” Font-Bold=”True”
Font-Size=”Large” ForeColor=”White” />

<EditRowStyle BackColor=”#2461BF”/>

<AlternatingRowStyle CssClass=”ms-alternating”


The above code will result in a grid looking like below. I have used some SharePoint CSS (Core.css) to bring the SharePoint look.

The data should be displayed using bound columns. The SPDataSource can be used with SharePoint controls without any coding.

Given below is another example for binding data to InputFormCheckBoxList in SP.

<sharepoint:InputFormCheckBoxList ID=”InputFormCheckBoxList1″ runat=”server”
DataSourceID=”spdsSupervisor” DataTextField=”Title”/>

The above code will result in a checkbox list looking like the one below. On change of codes the assemblies need not be recompiled and deployed

To GAC. This means no building of WSP/CAB files and writing codes to copy assemblies to Global Assembly Cache. (Nice isn’t it)

Hassle free code with fewer bugs can be developed by using SPDataSource. There are different types of Datasourcemode-ListItem, CrossList, Webs, and ListOfLists.

SharePoint developers who develop applications and custom application pages with SharePoint as data store (Lists as tables) will be benefited by using SPDataSource.


Modal Popup Extender

 To hide a modal popup control (Ajax control toolkit may 2009 release), the below JavaScript code can be used. Instead of using OK control ID or OK script, this JavaScript code can be used in the  

 oncllientclick event of any control.  

  $find(‘mdlpopup’).hide();return false <asp:ImageButton ID=”imgbtnCancel” runat=”server” ImageUrl=”Images/cancel.gif”CausesValidation=”False” OnClientClick=”$find(‘mdlpopup’).hide();return false;” />   


While using a popup control extender, hiding it from server side sometimes gives an error. 

To avoid this use the popupcontrolextender.Cancel() event from server side. Often the control is rendered with

Server side code making it less possible to write client side scripts to hide it.

Internet explorer automation

Automating internet explorer from dotnet is possible through c# given below is a sample

To use the below code add reference to Microsoft.mshtml class and Microsoft html library class

To assist you in finding the names of html controls and their id’s use internet developer toolbar available from Microsoft (click here to get it now)    

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using SHDocVw; using System.IO;

using System.Security.Cryptography;

namespace ie


public partial class Form1 : Form

public Form1()




private void button1_Click(object sender, EventArgs e)


Object nullob = null;

Object URL =;; //Use the url of webpage to automate

mshtml.HTMLDocumentClass doc;   

InternetExplorer ie = new

ie.Visible = true;

ie.Navigate2(ref URL, ref nullob, ref nullob, ref nullob, ref nullob);







doc = (mshtml.HTMLDocumentClass)ie.Document;

mshtml.HTMLInputElementClass inputel = (mshtml.HTMLInputElementClass)doc.all.item(“sometextboxid”, null);

inputel.value = “sometext”; //Text needed to be filled in textbox get the text box id from source


inputel = (mshtml.HTMLInputElementClass)doc.all.item(“sometextboxid”, null);

inputel.value = “sometext”;


mshtml.HTMLSelectElementClass inputsel = (mshtml.HTMLSelectElementClass)doc.all.item(“questions”, null);

inputsel.selectedIndex = 2; //dropdown select


foreach (mshtml.HTMLInputElementClass inp in doc.getElementsByTagName(“INPUT”))

{ // to click the button in webpage

if (inp.value == “submit”)






Bin packing algorithm



People working with ERP systems and applications related to them would have come across the

Bin packing problem.usually this is solved using knapsack algorithm. But it doesnt gives correct solution.

Here is the implementation of bin packing algorithm in boxes with maximum height limits can be done.

The methodology will be so efficient that the solution will be best fit for the boxes.



        If IsNumeric(cbobox.Text) Then
            Dim check As String
            Dim bins()() As Integer ‘the bin elements stored as two dimensional array representing bin number and the weights
            Dim item As Integer
            item = objds.Tables(0).Rows.Count – 1
            Dim h As Integer
            Dim itw As Integer = 0
            Dim itemw As String
            Dim objitemweight As String = String.Empty
            Dim it As Integer = 0
            Dim itno As String
            Dim itemno As String
            Dim itremove As ArrayList = New ArrayList()
  For h = 0 To item
                itw = grdDisplayitems.Item(2, h).Value
                If (h <> item) Then
                    itemw = itw.ToString() + ” ”
                    itemw = itw.ToString()
                End If

                objitemweight += itemw


            Dim elements() As String
            Dim elementnumber(elements.GetUpperBound(0)) As Integer
            Dim v As Integer
            For v = 0 To elements.GetUpperBound(0)

                If IsNumeric(elements(v)) Then
                    elementnumber(v) = CType(elements(v), Integer)
                End If


            ReDim bins(0)
            Dim BinNumber, BinElement, BinCount As Integer
            Dim BestBin, BestBinAmount As Integer
            Dim i, j, k As Integer

          ‘If required make a copy of array elements and proceed

            ReDim bins(0)(0)
            For i = 0 To elementnumber.GetUpperBound(0)
                BestBin = -1
                BestBinAmount = -1

                For j = 0 To BinNumber

                    BinElement = bins(j).GetUpperBound(0)
                    BinCount = 0
                    For k = 0 To BinElement
                        BinCount += bins(j)(k)

                    If BestBinAmount < BinCount AndAlso BinCount + elementnumber(i) <= cbobox.Text Then

                        BestBinAmount = BinCount
                        BestBin = j
                    End If


                If BestBin = -1 Then
                    ReDim Preserve bins(BinNumber + 1)
                    BinNumber += 1
                    ReDim bins(BinNumber)(1)
                    BinElement = 0
                    bins(BinNumber)(BinElement) = elementnumber(i)
                    BinElement = bins(BestBin).GetUpperBound(0)
                    ReDim Preserve bins(BestBin)(BinElement + 1) ‘This is one of the best thing in vb apart from c# redim statement
                    bins(BestBin)(BinElement) = elementnumber(i)
                End If




Happy programming