Uncategorized


Well, everyone has worked with datatables sometime or the other. In this article, I just wanted to illustrate the various usage and implementation of datatables.

The DataTable object represents tabular data as rows, columns, and constraints.Use the DataTable object to hold data in memory while performing disconnected data operations.Datatable consists of DataColumn and DataRow.
The DataTable object must contain DataColumn objects before any data can be added to the DataTable object.

In this example, we have a datatable with three columns, Name, Adress and Date of Joining(DOJ) which is a datetime column.

dtResults = new DataTable();
dtResults.Columns.Add(“Name”, Type.GetType(“System.String”));
dtResults.Columns.Add(“Department”, Type.GetType(“System.String”));
dtResults.Columns.Add(“DOJ”, Type.GetType(“System.DateTime”));

Adding row to datatable:
dtResults.Rows.Add(“Olyvia”, “Developer”, DateTime.Now);

Adding a datatacolumn to dtresults and populating it with default values

dcRec = new DataColumn(“Age”, typeof(int));
dcRec.DefaultValue = 23;
dtResults.Columns.Add(dcRec);

datatable Select
The DataTable Select method accepts a filter and sort argument to return an arry of DataRow objects that conform to the criteria in a FilterExpression.
DataRow[] drResultSet= dtResults.Select(“Age ‘21′”);

To get the column name dynamically, see the example below:

DataRow[] drResultSet;
drResultSet = dtResults.Select(site.Fields["ID"].InternalName + “=’” + dtStore.Rows[i]["DocUniqueID"].ToString().Substring(0, dtStore.Rows[i]["DocUniqueID"].ToString().IndexOf(“.”)) + “‘ and ” + site.Fields["Title"].InternalName + “=’” + dtStore.Rows[i]["Title"] + “‘”);

How to remove duplicate rows from a datatable
If some rows of a some columns in the datatable are repititive and duplicate and you want to remove them, then see the example below:

DataColumn[] keyColumns = new DataColumn[] { dtStore.Columns["DocUniqueID"], dtStore.Columns["DocType"] };
//remove the duplicates
RemoveDuplicates(dtStore, keyColumns);

private static void RemoveDuplicates(DataTable tbl,DataColumn[] keyColumns)
{
int rowNdx = 0;
while (rowNdx 0)
{
foreach (DataRow dup in dups)
{
tbl.Rows.Remove(dup);
}
}
else
{
rowNdx++;
}
}
}

private static DataRow[] FindDups(DataTable tbl,int sourceNdx,DataColumn[] keyColumns)
{
ArrayList retVal = new ArrayList();
DataRow sourceRow = tbl.Rows[sourceNdx];
for (int i = sourceNdx + 1; i < tbl.Rows.Count; i++)
{
DataRow targetRow = tbl.Rows[i];
if (IsDup(sourceRow, targetRow, keyColumns))
{
retVal.Add(targetRow);
}
}
return (DataRow[])retVal.ToArray(typeof(DataRow));
}

private static bool IsDup(DataRow sourceRow,DataRow targetRow,DataColumn[] keyColumns)
{
bool retVal = true;
foreach (DataColumn column in keyColumns)
{
retVal = retVal && sourceRow[column].Equals(targetRow[column]);
if (!retVal) break;
}
return retVal;
}

How to edit a row in datatable

strName = “Gitolekha”;
drResultSet[0]["Name"] = strName.ToString();
dtResults.AcceptChanges();

Datatables have lots of features and functionality, I have just covered some of them, more will be covered next time.

I was trying to create a table and add rows and cells in it using c#.

And tried to hyperlink in a tablecell, tried to add styles in the hyperlink without touching the css class and open the hyperlink popup via navigateurl in a new window.

putting hyperlink on tablecell:

TableRow tr = new TableRow();
TableCell td = new TableCell();
HyperLink hyper1 = new HyperLink();
hyper1.NavigateUrl = “http://techolyvia.wordpress.com/category/technical/sharepoint/spgroup/”;
hyper1.Text = “SPGroup”;
td.Controls.Add(hyper1);
tr.Cells.Add(td);
tableOuterCtrl.Rows.Add(tr);

Using navigateurl to open in a new window:

hyper1.Target = “_blank”;

Add styles in hyperlink without modifying css classes.

hyper1.Style.Add(“font”, “normal 8pt Verdana;”);
hyper1.Style.Add(“color”, “black”);

full code goes like this:
tableOuterCtrl = new Table();
tableOuterCtrl.CellPadding = 0;
tableOuterCtrl.CellSpacing = 0;
Controls.Add(tableOuterCtrl);
TableRow tr;
TableCell td;
tr = new TableRow();
tr.Width = Unit.Percentage(100);
tableOuterCtrl.Rows.Add(tr);
td = new TableCell();
HyperLink hyper1 = new HyperLink();
td.Wrap = false;
td.Width = Unit.Percentage(100);
hyper1.Style.Add(“font”, “normal 8pt Verdana;”);
hyper1.Style.Add(“color”, “black”);
hyper1.NavigateUrl = “http://techolyvia.wordpress.com/2009/03/31/report-to-show-all-users-and-user-groups-in-sharepoint-site/”;
hyper1.Target = “_blank”;
hyper1.Text = “Displaying all users and groups through coding”;
td.Controls.Add(hyper1);
tr.Cells.Add(td);
tableOuterCtrl.Rows.Add(tr);
this.Controls.Add(tableOuterCtrl);

An user might want to email an url like the one given below:
http://gitolekha:82/default.aspx?ConnectSearch=good sharepoint blog

We need to do url encoding to send such links because often url’s contain characters outside the ASCII set, so URL encoding converts the url to valid ASCII sets.URL encoding replaces unsafe ASCII characters with “%” followed by two hexadecimal digits corresponding to the character values in the ISO-8859-1 character-set.

URLs cannot contain spaces. URL encoding normally replaces a space with a + sign or as %20.

To do url encoding with .NET,one usually uses System.WebHttpUtility.UrlEncode to encode the querystring.

I had to do this through javascript.There are methods like
escape(string) to do encoding, but it did not work for me.
So, what I chose is the replace mothod to replace all unsafe characters.
what I used is regular expression to replace all occurences of space in  string “good sharepoint blog” as encodestring.replace(/\\s+/g ,’$-*’);

A detailed explaination of the above is as follows,
/ = start pattern
, = pattern to look for in the string badtext
/ = end pattern
g = global (anywhere the pattern match occurs in the string)
“$-*” = what to replace the pattern with if found

So, the full code to send the encoded url in email is given below.

parent.location = ‘mailto:?body=” + HttpUtility.UrlEncode(SPContext.Current.Web.Url + “/default.aspx?ConnectSearch=”) + “‘+txtSearch.value.replace(/\\s+/g ,’$-*’)+’~-~User=’+txtTopicsSearch.value.replace(/\\s+/g ,’$-*’)+’~-~Place=’+txtDocTypeSearch.value.replace(/\\s+/g ,’$-*’)+’~-~Country=’+txtCountrySearch.value.replace(/\\s+/g ,’$-*’)+’&subject=site search link’

The mail has a subject line of ’site search link’ as seen above.

This emails the encoded url as,
http://gitolekha:82/default.aspx?ConnectSearch=good$-*sharepoint$-*blog~-~User=gitolekha~-~Place=any$-*where/$-*in$-*India~-~Country=All$-*geographic$-*scopes

Now when the user types/paste the above url in the browser, we can use httphandler to make the application decode the above url in the desired format.
Now, we know that an ASP.NET HTTP handler is the process that runs in response to a request that is made to an ASP.NET Web application. When users request an .aspx file, the request is processed by the page handler.An IHttpModule is registered in the Web.Config file and it is notified of every HTTP request.
IHttpModule is an interface defined in System.Web.dll. The interface contains only two method signatures: Init and Dispose. On the Init method wire up, the behavior—for example application events—that you want the IHttpModule to support and perform any clean up in the Dispose method.

using System.Web;
namespace Gitolekha.Sample.KnowledgeManagement
{
class CustomHandler : IHttpModule
{
public void Dispose()
{
//throw new Exception(“The method or operation is not implemented.”);
}
public void Init(HttpApplication context)
{
context.BeginRequest+=new EventHandler(context_BeginRequest);
}
public void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
string requestedPage = app.Request.RawUrl;
if (requestedPage.Contains(“?ConnectSearch=”))
{
string strurl = app.Request.Url.AbsoluteUri;
if (strurl .Contains(“$-*”))
{
strurl = strurl.Replace(“$-*”, ” “);
}
if (strurl.Contains(“~-~”))
{
strurl = strurl.Replace(“~-~”, “&”);
}
string strencode = HttpUtility.UrlEncode(strurl );
HttpContext.Current.Response.Redirect(strurl, true);
}}

This will do the required decoding for this url.
Possible scenarios/reasons for users wanting to send url might be Sometimes it is easy for users to email interesting links of a site to another user.To elaborate, suppose you have a document management system where the users like to share interesting and important links of documents to other users through emails.

One of my colleague was using a treeview. He was not able to get the value of the node selected in a checkbox,the nodes were rendering in a td,say the name of the node is Apple and name of the treeview is tview :-

<td><div style=”width:20px;height:1px”></div></td><td><a id=”tviewn1″ href=”javascript:TreeView_ToggleNode(tview_Data,1,tviewn1,’ ‘,tviewn1Nodes)”><img  alt=”Expand Apple” style=”border-width:0;” /></a></td><td style=”white-space:nowrap;”><input type=”checkbox” name=”tviewn1CheckBox” id=”tviewn1CheckBox” /><span class=”tview_0″ id=”tviewt1″>Apple</span></td>

The javascript to get the node name in this case will be :-

function getSelectedNodeValue()
{
var storeTemp = ”;
var x=document.getElementsByTagName(“td”);
for(var i=0;i
{
var srch=x[i].innerHTML;
if(srch.search(‘CHECKED’)>=0)
{/storeTemp += x[i].innerText + ‘,’; }
}
storeTemp = storeTemp.substring(0,storeTemp.lastIndexOf(‘,’));
}

Refer to http://www.dotnetspider.com/resources/24242-how-get-value-selected-node-treeview.aspx

It is very simple to implement tab control using hotmap.It is all with html and a bit of javascript. Refer to the images shown in Tab control without postback.
, where on clicking each tab the color of that tab had to change.

The image map was something like this,

<img id="imgHotmap" src="images/arrows_step_1.gif" width="342" height="34" border="0" usemap="#steps" />
<map name="steps" id="steps">
<area shape="poly" coords="253,1,330,1,342,17,331,34,252,34,264,17,254,3" href="#" alt="step4" onclick="changeImage(4);" />
<area shape="poly" coords="168,1,245,1,257,17,246,34,167,34,179,17,169,3" href="#" alt="step3" onclick="changeImage(3);" />
<area shape="poly" coords="0,0,77,0,88,16,77,32,0,32,1,1" href="#" alt="step1" onclick="changeImage(1);" />
<area shape="poly" coords="84,0,161,0,173,16,162,33,83,33,95,16,85,2" href="#" alt="step2" onclick="changeImage(2);" />
</map>

All, we did was to invoke a javascript for each area of the map i.e for each tab.
The job of the javascript was simple, it changed the image of “imgHotmap”.

function changeImage(opt)
{
if(opt == 1)
{
document.getElementById(‘imgHotmap’).src = ‘/_layouts/images/novartis/arrows_step_1.gif’;

}
if(opt == 2)
{
document.getElementById(‘imgHotmap’).src = ‘/_layouts/images/novartis/arrows_step_2.gif’;
}
if(opt == 3)
{
document.getElementById(‘imgHotmap’).src = ‘/_layouts/images/novartis/arrows_step_3.gif’;
}
if(opt == 4)
{
document.getElementById(‘imgHotmap’).src = ‘/_layouts/images/novartis/arrows_step_4.gif’;

}
}

We had to implement a functionality wherein we had a tab control with a peopleeditor in the first tab and we had to show the summary of all controls of the first tab in the second tab.

Initially,we were facing difficulties in fetching values in the peopleeditor, then we found out a way: Our people editor control had the id=pplContact

@ Register Tagprefix=”wssawc” Namespace=”Microsoft.SharePoint.WebControls” Assembly=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %> 

<wssawc:PeopleEditor id=”pplContacts” runat=”server” MultiSelect=”true” AllowEmpty=”false” PlaceButtonsUnderEntityEditor=”false” Width=”388px”/>
 

In the javascript for tab change, we included the following:

var users = null;
var  elem = document.forms[0].elements;
for(var i=0; i < elem.length; i++) {// look for the value we set the peopleeditor’s id to and “TextBox”
 
 
if(elem[i].id.indexOf(“pplOwner”) != -1 && elem[i].id.indexOf(“TextBox”) != -1) users = elem[i].value; }
 
Thus, we couls easily put the value of people editor pplOwner in a label on the next tab using:
document.getElementById(‘<%=lblOwner.ClientID %>’).innerHTML = users;

In a particular scenario,we faced a problem with CAML query, returning an error “The property Query contains an invalid value.”.

Our CAML query was:

<Where>
<Contains><FieldRef Name=’Kits’/><Value Type=’Text’>Ray & Martin</Value></Contains>;
</Where>

After lots of tries we came to the solution that only in value’s containing ‘&’ we faced the problem, for other cases it worked fine.

We tried using CDATA, and it worked.

The reason being,a CDATA section is a section of element content that is marked for the parser to interpret as only character data, not markup.

So, our new approach as:

<Where> 
<Contains>   
<FieldRef Name=’Kits’/>     
<Value Type=’Text’>  <![CDATA[Ray & Martin]]></Value></Contains>
</Where>

I needed to add a populate on demand treeview to a div because the normal treeview was taking a very long time to get loaded. This is what I did.

public System.Web.UI.WebControls.TreeView tvGeoScope = new System.Web.UI.WebControls.TreeView();
string strCountry =”Country”;
tvGeoScope.ID =”tvGeoScope”;
//gets called whenever a node is clicked to expand.
tvGeoScope.TreeNodePopulate += new TreeNodeEventHandler
(tvGeoScope_TreeNodePopulate);
TreeNode n2 = new TreeNode(strCountry, strCountry);
n2.Expanded = false;
n2.SelectAction = TreeNodeSelectAction.None;
n2.PopulateOnDemand = true;
n2.ShowCheckBox = false;

To get a more detailed explaination, click on the link where I have given more explainations http://www.dotnetspider.com/resources/20921-Get-populate-demand-treeview-asp-net.aspx


 

Rank Company CEO Revenue
(in crores)
1 Tata Consultancy Services S Ramadorai  9680 
2 Infosys Technologies Nandan M Nilekani  6938 
3 Wipro Ltd Azim Premji  6760 
4 Hewlett-Packard India Sales   6706 
5 IBM India Abraham Thomas  4219 
6 Satyam Computer Services B Ramalinga Raju  3464 
7 HCL Technologies Shiv Nadar  2772 
8 Tech Pacific India K Jaishankar  2741 
9 Intel Avtar Saini  2733 
10 Cisco Systems Manoj Chugh  2703 
11 Redington India Jitendra Kulkarni  2666 
12 HCL Infosystems Ajai Chowdhry  2203 
13 Ingram Micro NY Prasad  2047 
14 Patni Computer Systems NK Patni  1573 
15 Samsung   1519 
16 Cognizant Technology Solutions Lakshmi Narayanan  1511 
17 Moser Baer India Deepak Puri  1354 
18 Oracle India Shekhar Dasgupta  1325 
19 Microsoft Corporation India   1277 
20 I-flex Solutions Rajesh Hukku  1136 

 

21 Mahindra British Telecom John Helleur  947 
22 Tata Infotech Farrokh K Kavarana  932 
23 Sun Microsystems Bhaskar Pramanik  924 
24 SAP India   878 
25 Polaris Software Lab Arun Jain  784 
26 American Power Conversion Pankaj Sharma  770 
27 Celetronix India   668 
28 Perot Systems TSI Vineet Nayar  657 
29 Computer Associates India Ninad Karpe  645 
30 Dell   633 
31< TD width=182>Microtek International   620   
32 Hexaware Technlogies   586 
33 L&T Infotech   576 
34 Siemens Information Systems Anil R Laud  570 
35 iGate Global Solutions   556 
36 Mastek Ashank Desai  552 
37 CMS Computers RD Grover  547 
38 Texas Instruments   523 
39 Honeywell Technology Solutions Lab Krishna Mikkilineni  518 
40 Acer India   516 

 

41 NIIT Technologies Arvind Thakur  509 
42 MphasiS BFL Jerry Rao  481 
43 Datacraft India   466 
44 Nortel Networks India Ashok Waliya  462 
45 Flextronics Software Systems   458 
46 Syntel India   428 
47 Kanbay India Cyprian D’Souza  422 
48 NIIT Limited  < /TD> 398 
49 Rolta India Kamal Singh  393 
50 Infinite Computer Systems   385 
51 SES Technologies PK Krishnaprasad  377 
52 GTL Manoj Tirodkar  370 
53 Convansys India   367 
54 Sify R Ramaraj  361 
55 Zensar Technologies Ganesh Natarajan  345 
56 Tulip IT Services Lt. Col. HS Bedi  334 
57 NeST Group N Jehangir  331 
58 Iris Computers Sanjiv Krishen  330 
59 PCS Technology   330 
60 Zenith computers Raj Saraf  323 

 

61 Sonata Software   298 
62 D-Link India K R Naik  295 
63 Neoteric informatique Paras Shah  290 
64 Mascon Global Sandy K Chandra  290 
65 3i Infotech (formerly ICICI Infotech )   289 
66 WeP Peripherals Ram N Agarwal   286 
67 CSC India Dr Arun Maheshwari  284 
68 Philips Innovation Center Bob Hoekstra  281 
69 Xansa India Saurabh Srivastava  279 
70 Canon india Alan Grant  262 
71 TVS Electronics S Shreenivasa Rao  258 
72 Infotech Enterprises   257 
73 Savex Comuters   254 
74 KPIT Cummins Infosystems   252 
75 ITC Infotech India   249 
76 Mindtree Consulting Ashok Soota  245 
77 Sasken Communications   241 
78 Tally Solutions Bharat Goenka  229 
79 Rashi Peripherals Suresh Pansari   221 
80 Ramco Systems PR Venketarama Raja  221 

 

81 Epson India Etsuo Fujito  220 
82 Numeric Power Systems R.Chellappan  219 
83 Network Solutions &nbs p; 201 
84 Juniper Networks   195 
85 AMD Far East (India) Sanjeev Keskar   192 
86 Jupiter International Alok Garodia  190 
87 Tata Elxsi   187 
88 Xenitis   178 
89 Aftek Infosys Ranjit Dhuru  177 
90 IRCTC MN Chopra  176 
91 EMC Manoj chugh  175 
92 3D Networks SK Jha  174 
93 Veritas   174 
94 Tata Technologies PR McGoldrick   172 
95 Geometric Software   168 
96 Cranes Software   163 
97 Accel ICIM Frontline   163 
98 Mediaman Infotech Dushyant Mehta  156 
99 Priya AK Bhuwania  155 
100 Keane India Parmindar S Miglani   150 

 

101 Persistent Systems Anand Deshpande  147 
102 Zylog Systems V Sudarshan  146 
103 Supertron Electronics VK Bhandari  139 
104 Aptech Promod Khera  135 
105 Lipi Data Systems Mukul Singhal  127 
106 Celetronix Power India   125 
107 Cadence Design Systems   125 
108 Intex Technologies Narender Bansal  121 
109 Aditi Technologies Pradeep Singh  121 
110 Systimax   120 
111 Mro-Tek S Narayanan  120 
112 Subex Systems Suba sh Menon  117 
113 Team Computers Ranjan Chopra  111 
114 Softcell Technologies Sunil Dalal  108 
115 Blue Star Infotech Suneel M. Advani  107 
116 Tyco   106 
117 Netapps   104 
118 Ness Technologies   104 
119 Nucleus Software Exports Vishnu Dusad  103 
120 PC Solutions   103 

 

121 Bristlecone   101 
122 Aztec Software and Technologies   98 
123 Tata Interactive Systems Sanjaya Sharma  98 
124 Allied Digital Services Nitin D Shah  97 
125 BMC Software   93 
126 Eaton Power Quality   90 
127 Skytech   88 
128 FCS Software Solutions Dalip Kumar  85 
129 Onward Novell Munesh Jalota (Country Manager)  84 
130 RS Software   82 
131 DB Power Electronics   80 
132 Pentamedia Graphics V Chandrasekaran  79 
133 OA Compserve R K Malhotra  78 
13 4 Micro Max Technologies   75 
135 Cybage   71 
136 Netlink Business Systems   71 
137 Dax Networks Ashok Mirza  70 
138 SAS India Gourish Hosangady  70 
139 RR Systems Bharat Bhushan  68 
140 Park Electronik Ajaya Kumar  65 

 

141 Symantec India   64 
142 Sierra Atlantic Software Services Sarath Sura   62 
143 Syntech Informatices Ltd   61 
144 MC Modi and Company   60 
145 Comnet Vision India   58 
146 Ontrack Solutions   56 
147 Targus Technologies   55 
148 Artek Enterprises Anil Gupta  52 
149 Kale Consultants Vipul jain   51 
150 Trend Micro India Niraj Kaushik  51 
151 Jalan Infotech   50 
152 VSM Advance Automation Deepak Lomba, Raj Kumar Gupta  50 
153 SAN Computech Shudhir Saluja   48 
154 RMSI Ajay Lavakare  47 
155 Jetking Infotrain Suresh Bharwani  47 
156 Quinnox Consultancy Services Udai Kumar  47 
157 Kadam Marketing Anil Sachdeva  47 
158 Elcom Trading Company   45 
159 FCG Software Services Avinash Chandra Agrawal  44 
160 Induslogic   43 

 

161 Infrasoft Technologies Hanuman Tripathi  43 
162 Trifin Information Technology   42 
163 Fortune Marketing Manoj Gupta  41 
164 Geodesic Information Systems Kiran Kulkarni (MD)  41 
165 Visesh Infotecnics Sanjiv Bhavnani   40 
166 Microclinic India Tarun Seth   39 
167 Gemini Infotech SP Agarwala  37 
168 McAfee India   37 
169 Hitachi Data Systems   37 
170 Nihilent   37 
171 Mistral Software Anees Ahmed   37 
172 Pulse Systems NK Agarwal  35 
173 Softech Computers Ashok Taneja  35 
174 CCS Infotech   35 
175 Financial Technologies   34 
176 Spark Technology and Testing   32 
177 Ittiam Systems Srini Rajam  32 
178 KMG Infotech   32 
179 Login Infotech Sanjay Shrivatsava   31 
180 RSA Security   31 

 

181 Computer Empire Harish Puri  27 
182 Crest Animation Studios   30 
183 Emerson Network Power S.S. Bapat  30 
184 Synechron   29 
185 Champion Computers   28 
186 Onward Technologies Hari sh mehta  27 
187 Computer Land AK Singh  27 
188 Red Hat India Javed Tapia  26 
189 Toonz Animation India   26 
190 Ontrack Systems   26 
191 Wizer Technologies   25 
192 Globsyn Technologies   25 
193 Lexmark   25 
194 Neilsoft   23 
195 Nelito Systems JM Varma   22 
196 Selectica   22 
197 Choice Solutions   22 
198 Cash Tech Solutions   20 
199 Digitronics Infosolutions   20 
200 netGuruIndia   20 

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!