<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Integration Points &#187; asp.net c# datagrid</title>
	<atom:link href="http://dmgorman.wordpress.com/tag/aspnet-c-datagrid/feed/" rel="self" type="application/rss+xml" />
	<link>http://dmgorman.wordpress.com</link>
	<description>Extending Corporate Data ...</description>
	<lastBuildDate>Wed, 16 Dec 2009 16:27:47 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='dmgorman.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/09ff9c9336e6ecd7cc49045a62d1aab3?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Integration Points &#187; asp.net c# datagrid</title>
		<link>http://dmgorman.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://dmgorman.wordpress.com/osd.xml" title="Integration Points" />
		<item>
		<title>#05 Employee Directory</title>
		<link>http://dmgorman.wordpress.com/2008/05/23/05-simple-employee-directory/</link>
		<comments>http://dmgorman.wordpress.com/2008/05/23/05-simple-employee-directory/#comments</comments>
		<pubDate>Fri, 23 May 2008 03:38:20 +0000</pubDate>
		<dc:creator>dmgorman</dc:creator>
				<category><![CDATA[Intranet Integration]]></category>
		<category><![CDATA[asp.net c# datagrid]]></category>

		<guid isPermaLink="false">http://dmgorman.wordpress.com/?p=10</guid>
		<description><![CDATA[Update: Post #19 offers a Stored Procedure and a (part 2+)  Sharepoint Webpart code for an employee directory.
Note: This uses asp.net 1.1 framework &#8211; should migrate to 2.0+ just fine but has not been tested on the newer frameworks. I plan to replace the data calls using the DAAB see Post #04. It should at [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dmgorman.wordpress.com&blog=2497805&post=10&subd=dmgorman&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><em>Update: Post #19 offers a Stored Procedure and a (part 2+)  Sharepoint Webpart code for an employee directory.</em></p>
<p>Note: This uses asp.net 1.1 framework &#8211; should migrate to 2.0+ just fine but has not been tested on the newer frameworks. I plan to replace the data calls using the DAAB see Post #04. It should at least show you how easy you can filter and post to a grid.</p>
<p>As I spend time &amp; convert this over to use a better data access layer I will repost but as is should give you an idea of what to do (if you know asp.net).</p>
<p>First here is what it looks like:</p>
<p><a href="http://dmgorman.files.wordpress.com/2008/05/empdir4.jpg"><img class="aligncenter size-medium wp-image-15" src="http://dmgorman.files.wordpress.com/2008/05/empdir4.jpg?w=300&#038;h=117" border="0" alt="" width="300" height="117" /></a></p>
<hr size="1" /><strong>asp.net</strong></p>
<p><span style="color:#99ccff;">&lt;asp:dropdownlist id=&#8221;dlRecordsPerPage&#8221; runat=&#8221;server&#8221; AutoPostBack=&#8221;True&#8221;&gt;<br />
&lt;asp:ListItem Value=&#8221;25&#8243; Selected=&#8221;True&#8221;&gt;25&lt;/asp:ListItem&gt;<br />
&lt;asp:ListItem Value=&#8221;50&#8243;&gt;50&lt;/asp:ListItem&gt;<br />
&lt;asp:ListItem Value=&#8221;100&#8243;&gt;100&lt;/asp:ListItem&gt;<br />
&lt;asp:ListItem Value=&#8221;500&#8243;&gt;500&lt;/asp:ListItem&gt;<br />
&lt;/asp:dropdownlist&gt;<br />
&lt;asp:button id=&#8221;ExportToExcel&#8221; runat=&#8221;server&#8221; CssClass=&#8221;b1&#8243; Visible=&#8221;False&#8221; Text=&#8221; Export to Excel&#8221;&gt;&lt;/asp:button&gt;<br />
&lt;asp:datagrid id=&#8221;DataGrid1&#8243; Width=&#8221;680px&#8221; BorderStyle=&#8221;None&#8221; Height=&#8221;20px&#8221; OnSortCommand=&#8221;DataGrid1_SortCommand&#8221;<br />
AllowSorting=&#8221;True&#8221; OnPageIndexChanged=&#8221;DataGrid1_PageIndexChanged&#8221; Runat=&#8221;Server&#8221; PageSize=&#8221;25&#8243;<br />
GridLines=&#8221;Vertical&#8221; CellPadding=&#8221;3&#8243; BorderWidth=&#8221;1px&#8221; AllowPaging=&#8221;True&#8221; BorderColor=&#8221;#999999&#8243;<br />
BackColor=&#8221;White&#8221; AutoGenerateColumns=&#8221;False&#8221;&gt;</span></p>
<p><span style="color:#99ccff;">&lt;SelectedItemStyle Font-Bold=&#8221;True&#8221; ForeColor=&#8221;White&#8221; BackColor=&#8221;#008A8C&#8221;&gt;&lt;/SelectedItemStyle&gt;<br />
&lt;AlternatingItemStyle Height=&#8221;20px&#8221; BackColor=&#8221;Gainsboro&#8221;&gt;&lt;/AlternatingItemStyle&gt;<br />
&lt;ItemStyle Height=&#8221;20px&#8221; ForeColor=&#8221;Black&#8221; BackColor=&#8221;#EEEEEE&#8221;&gt;&lt;/ItemStyle&gt;<br />
&lt;HeaderStyle Font-Bold=&#8221;True&#8221; HorizontalAlign=&#8221;Center&#8221; Height=&#8221;40px&#8221; ForeColor=&#8221;White&#8221; BackColor=&#8221;#000084&#8243;&gt;&lt;/HeaderStyle&gt;<br />
&lt;FooterStyle Height=&#8221;20px&#8221; ForeColor=&#8221;Black&#8221; BackColor=&#8221;#CCCCCC&#8221;&gt;&lt;/FooterStyle&gt;<br />
&lt;Columns&gt;<br />
&lt;asp:BoundColumn DataField=&#8221;PersonID&#8221; HeaderText=&#8221;Emp ID&#8221; SortExpression=&#8221;A.Employee&#8221;&gt;<br />
&lt;ItemStyle Wrap=&#8221;False&#8221; HorizontalAlign=&#8221;Center&#8221; Width=&#8221;40px&#8221; CssClass=&#8221;smallAlert&#8221;&gt;&lt;/ItemStyle&gt;<br />
&lt;/asp:BoundColumn&gt;<br />
&lt;asp:HyperLinkColumn Text=&#8221;&lt;img border=&#8217;0&#8242; src=&#8217;/newnet/images/intranet/person.gif&#8217; /&gt;&#8221; Target=&#8221;_self&#8221;<br />
DataNavigateUrlField=&#8221;PersonID&#8221; DataNavigateUrlFormatString=&#8221;http://intranet/newnet/resources/EmployeeView.aspx?id={0}&#8221;<br />
HeaderText=&#8221;View &#8221; Visible=&#8221;false&#8221;&gt;<br />
&lt;ItemStyle CssClass=&#8221;smallredC&#8221;&gt;&lt;/ItemStyle&gt;<br />
&lt;/asp:HyperLinkColumn&gt;<br />
&lt;asp:HyperLinkColumn Text=&#8221;&lt;img border=&#8217;0&#8242; src=&#8217;/newnet/images/intranet/email.gif&#8217; /&gt;&#8221; DataNavigateUrlField=&#8221;Email&#8221;<br />
DataNavigateUrlFormatString=&#8221;mailto:{0}&#8221; HeaderText=&#8221;Email&#8221;&gt;<br />
&lt;ItemStyle HorizontalAlign=&#8221;Center&#8221; Width=&#8221;100px&#8221; CssClass=&#8221;smallredC&#8221;&gt;&lt;/ItemStyle&gt;<br />
&lt;/asp:HyperLinkColumn&gt;<br />
&lt;asp:HyperLinkColumn Text=&#8221;&lt;img border=&#8217;0&#8242; src=&#8217;/newnet/images/intranet/person.gif&#8217; /&gt;&#8221; DataNavigateUrlField=&#8221;Employee&#8221;<br />
DataNavigateUrlFormatString=&#8221;http://intranet/newnet/images/emp/{0}.jpg&#8221; HeaderText=&#8221;Photo&#8221;&gt;<br />
&lt;ItemStyle HorizontalAlign=&#8221;Center&#8221; Width=&#8221;100px&#8221; CssClass=&#8221;smallredC&#8221;&gt;&lt;/ItemStyle&gt;<br />
&lt;/asp:HyperLinkColumn&gt;<br />
&lt;asp:BoundColumn DataField=&#8221;FirstName&#8221; HeaderText=&#8221;First Name&#8221; SortExpression=&#8221;FirstName&#8221;&gt;<br />
&lt;ItemStyle Wrap=&#8221;False&#8221; Width=&#8221;90px&#8221; CssClass=&#8221;smallred&#8221;&gt;&lt;/ItemStyle&gt;<br />
&lt;/asp:BoundColumn&gt;<br />
&lt;asp:BoundColumn DataField=&#8221;LastName&#8221; HeaderText=&#8221;Last Name&#8221; SortExpression=&#8221;LastName&#8221;&gt;<br />
&lt;ItemStyle Wrap=&#8221;False&#8221; Width=&#8221;90px&#8221; CssClass=&#8221;smallred&#8221;&gt;&lt;/ItemStyle&gt;<br />
&lt;/asp:BoundColumn&gt;<br />
&lt;asp:BoundColumn DataField=&#8221;WorkPhoneExt&#8221; HeaderText=&#8221;Ext&#8221;&gt;<br />
&lt;ItemStyle Wrap=&#8221;False&#8221; Width=&#8221;35px&#8221; CssClass=&#8221;smalldetail&#8221;&gt;&lt;/ItemStyle&gt;<br />
&lt;/asp:BoundColumn&gt;<br />
&lt;asp:BoundColumn DataField=&#8221;WorkPhone&#8221; HeaderText=&#8221;Direct&#8221;&gt;<br />
&lt;ItemStyle Wrap=&#8221;False&#8221; Width=&#8221;65px&#8221; CssClass=&#8221;smalldetail&#8221;&gt;&lt;/ItemStyle&gt;<br />
&lt;/asp:BoundColumn&gt;<br />
&lt;asp:BoundColumn DataField=&#8221;MobilePhone&#8221; HeaderText=&#8221;Mobile&#8221;&gt;<br />
&lt;ItemStyle Wrap=&#8221;False&#8221; Width=&#8221;75px&#8221; CssClass=&#8221;smalldetail&#8221;&gt;&lt;/ItemStyle&gt;<br />
&lt;/asp:BoundColumn&gt;<br />
&lt;asp:BoundColumn DataField=&#8221;Org&#8221; HeaderText=&#8221;Primary Dept&#8221; SortExpression=&#8221;Org&#8221;&gt;<br />
&lt;ItemStyle Wrap=&#8221;False&#8221; CssClass=&#8221;smallredC&#8221;&gt;&lt;/ItemStyle&gt;<br />
&lt;/asp:BoundColumn&gt;<br />
&lt;asp:BoundColumn DataField=&#8221;custSecondaryDepartment&#8221; HeaderText=&#8221;Secondary Dept&#8221; SortExpression=&#8221;C.custSecondaryDepartment&#8221;&gt;<br />
&lt;ItemStyle Wrap=&#8221;False&#8221; CssClass=&#8221;smallredC&#8221;&gt;&lt;/ItemStyle&gt;<br />
&lt;/asp:BoundColumn&gt;<br />
&lt;asp:BoundColumn DataField=&#8221;Office&#8221; HeaderText=&#8221;Office&#8221; SortExpression=&#8221;B.Cust5ULPhysical&#8221;&gt;<br />
&lt;ItemStyle Wrap=&#8221;False&#8221; CssClass=&#8221;smallredC&#8221;&gt;&lt;/ItemStyle&gt;<br />
&lt;/asp:BoundColumn&gt;<br />
&lt;/Columns&gt;<br />
&lt;PagerStyle Height=&#8221;20px&#8221; HorizontalAlign=&#8221;Center&#8221; ForeColor=&#8221;Black&#8221; BackColor=&#8221;#999999&#8243; Mode=&#8221;NumericPages&#8221;&gt;&lt;/PagerStyle&gt;<br />
&lt;/asp:datagrid&gt;</span></p>
<p><strong>C#:</strong></p>
<p>Note: The embedded query should be cleaned up using join clauses and the should be replaced by a stored procedure perhaps using WHEN CASE to ignore unused filter parms.<br />
<code><br />
public void BindDataGrid( string sOrderParm )<br />
{</code></p>
<p>SqlDataAdapter daList;<br />
DataSet dsClients;</p>
<p>SqlConnection conn = new SqlConnection(connstring);<br />
conn.Open();<br />
string strDeptCode = &#8220;%&#8221; + dlDepartment.SelectedValue.ToString() + &#8220;%&#8221;;<br />
string strRegionCode = &#8220;%&#8221; + dlRegion.SelectedValue.ToString() + &#8220;%&#8221;;</p>
<p>string strSQL = &#8221; Select A.Employee , (RTRIM(LastName) + &#8216; &#8216; + ISNULL(Suffix,&#8221;)) as LastName , PreferredName As FirstName, MiddleName, Org, Region, WorkPhone, WorkPhoneExt, MobilePhone, B.Cust5ULPhysical As Office, C.custSecondaryDepartment &#8220;;<br />
strSQL += &#8221; , RTRIM(A.Employee) As PersonID, A.Email &#8220;;<br />
strSQL += &#8221; FROM EM A , EmployeeCustomTabFields B, EmployeeCustomTabFields C &#8220;;<br />
strSQL += &#8221; WHERE A.Status = &#8216;A&#8217; &#8220;;<br />
strSQL += &#8221; AND A.Employee = B.Employee &#8220;;<br />
strSQL += &#8221; AND A.Employee = C.Employee &#8220;;<br />
strSQL += &#8221; AND A.[LastName] Like &#8216;&#8221; + txtLastName.Text.Trim() + &#8220;%&#8217; And A.[Employee] Like &#8216;&#8221; + txtEmpID.Text.Trim() + &#8220;%&#8217; And ( A.[PreferredName] Like &#8216;&#8221; + txtFirstName.Text.Trim() + &#8220;%&#8217; OR A.[FirstName] like &#8216;&#8221; + txtFirstName.Text.Trim() + &#8220;%&#8217; ) AND ( A.[Org] like &#8216;&#8221; + strDeptCode + &#8220;%&#8217; or C.custSecondaryDepartment like &#8216;%&#8221; + strDeptCode + &#8220;%&#8217; ) AND ( A.WorkPhone like &#8216;%&#8221; + txtPhone.Text.Trim() + &#8220;%&#8217; OR A.WorkPhoneExt like &#8216;%&#8221; + txtPhone.Text.Trim() + &#8220;%&#8217; OR A.MobilePhone like &#8216;%&#8221; + txtPhone.Text.Trim() + &#8220;%&#8217;) &#8220;;<br />
strSQL += &#8221; AND B.Cust5ULPhysical like &#8216;%&#8221; + strRegionCode + &#8220;%&#8217; &#8220;;<br />
strSQL += &#8221; Order By &#8221; + sOrderParm;</p>
<p>daList = new SqlDataAdapter(strSQL, conn );<br />
dsClients = new DataSet();<br />
daList.Fill( dsClients );<br />
DataGrid1.PageSize = Int32.Parse(dlRecordsPerPage.SelectedValue.ToString());<br />
DataGrid1.DataSource = dsClients;<br />
try<br />
{<br />
DataGrid1.DataBind();<br />
if (DataGrid1.Items.Count == 0)<br />
{<br />
txtError.Text = &#8220;No Records Found&#8221;;<br />
txtError.Visible = true;<br />
DataGrid1.Visible = false;</p>
<p>}<br />
else<br />
{<br />
ExportToExcel.Visible = true;<br />
DataGrid1.Visible = true;<br />
txtError.Visible = false;<br />
txtTest.Visible = false;<br />
}<br />
}<br />
catch<br />
{<br />
txtError.Text = &#8220;No Records Found&#8221;;<br />
txtError.Visible = true;<br />
DataGrid1.Visible = false;<br />
}<br />
finally<br />
{<br />
if (conn != null) { conn.Close(); conn.Dispose(); }<br />
if (daList != null) { daList.Dispose(); }<br />
if (dsClients != null) { dsClients.Dispose(); }<br />
}</p>
<p>}</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/dmgorman.wordpress.com/10/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/dmgorman.wordpress.com/10/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dmgorman.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dmgorman.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dmgorman.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dmgorman.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dmgorman.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dmgorman.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dmgorman.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dmgorman.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dmgorman.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dmgorman.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dmgorman.wordpress.com&blog=2497805&post=10&subd=dmgorman&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://dmgorman.wordpress.com/2008/05/23/05-simple-employee-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0f40e4ba23d8f519bc9491fe6ae71f78?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dmgorman</media:title>
		</media:content>

		<media:content url="http://dmgorman.files.wordpress.com/2008/05/empdir4.jpg?w=300" medium="image" />
	</item>
	</channel>
</rss>