<?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>Giteshsankhe&#039;s Blog</title>
	<atom:link href="http://giteshsankhe.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://giteshsankhe.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Wed, 12 Aug 2009 13:09:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='giteshsankhe.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Giteshsankhe&#039;s Blog</title>
		<link>http://giteshsankhe.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://giteshsankhe.wordpress.com/osd.xml" title="Giteshsankhe&#039;s Blog" />
	<atom:link rel='hub' href='http://giteshsankhe.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Tips for Deploying ASP.Net Application in Production</title>
		<link>http://giteshsankhe.wordpress.com/2009/08/12/tips-for-deploying-asp-net-application-in-production/</link>
		<comments>http://giteshsankhe.wordpress.com/2009/08/12/tips-for-deploying-asp-net-application-in-production/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 13:09:19 +0000</pubDate>
		<dc:creator>giteshsankhe</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://giteshsankhe.wordpress.com/2009/08/12/tips-for-deploying-asp-net-application-in-production/</guid>
		<description><![CDATA[One of my previous article Deploying ASP.Net Applications discussed about how to deploy asp.net applications in IIS. In this article, we will see some of useful tips that can help us in deploying application efficiently in production. Deploy application with debug=&#8221;false&#8221; When we develop asp.net application using Visual Studio, the default value for debug attribute [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=giteshsankhe.wordpress.com&amp;blog=8976745&amp;post=9&amp;subd=giteshsankhe&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One of my previous article Deploying ASP.Net Applications discussed about how to deploy asp.net applications in IIS. In this article, we will see some of useful tips that can help us in deploying application efficiently in production.</p>
<p>Deploy application with debug=&#8221;false&#8221;</p>
<p>When we develop asp.net application using Visual Studio, the default value for debug attribute is true. This setting will help developers to debug the application in development environment. For example, executing the application in this mode will not cache the resource files rendered by WebResources.axd handler. This prevents the need to clear the temporary cache every time when the developer needs to check the changes done. There will be other useful things done for developers for debugging like debug symbols, settings that will enable breakpoints etc. These setting will give a poor performance in production if released in the default debug mode (false).</p>
<p>So, never release your website with debug mode set to true. It should be set to false in web.config when moving to production.</p>
<p>Disadvantages of debug = “true”</p>
<p>Ø       Code execution will be slow.</p>
<p>Ø       Compilation will be slow since batch compilation is disabled.</p>
<p>Ø       Memory consumption is higher since there are additional debug symbols, etc.</p>
<p>Ø       Resources downloaded with webresources.axd will not be cached.</p>
<p>Alternate will be  in machine.config. If you are a server administrator, make this change in machine.config so that it will enforce the debug attribute in the application’s web.config to false. It also disables the page output tracing and the ability to show the detailed exception report to the remote users when there is an exception.</p>
<p>Read Scott Guthrie’s post about this,</p>
<p>http://weblogs.asp.net/scottgu/archive/2006/04/11/442448.aspx</p>
<p>Encrypt the Sensitive data in Web.Config</p>
<p>Sometimes, you will have some sensitive information stored on web.config. For example: SQL Userid and Password if you use SQL authentication to connect to database. Since, the information stored in web.config is clear text then it poses a security risk. </p>
<p>Even though, users can&#8217;t access web.config file, it is still not safe because the server admins can still see the userid and password from web.config files. For example, in shared hosting environments. So, it will be better if we encrypt the connection string in web.config file in these scenarios. </p>
<p>Understanding this need, Microsoft introduced a new technique to encrypt and decrypt the Web.Config sections in Asp.Net 2.0. ASP.Net 2.0 has 2 providers for encrypting and decrypting config sections, </p>
<p>Ø       RSA(RSAProtectedConfigurationProvider) </p>
<p>Ø       DPAPI(DataProtectionConfigurationProvider)</p>
<p> To encrypt a connection string section,</p>
<p>protected void btnEncrypt_Click(object sender, EventArgs e)</p>
<p>    {</p>
<p>        Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);</p>
<p>        ConfigurationSection section = config.GetSection(&#8220;connectionStrings&#8221;);</p>
<p>        if (!section.SectionInformation.IsProtected)</p>
<p>        {            section.SectionInformation.ProtectSection(&#8220;DataProtectionConfigurationProvider&#8221;);</p>
<p>            config.Save();</p>
<p>        }</p>
<p>    } </p>
<p>To use RSA algorithm, use RSAProtectedConfigurationProvider in the place of DataProtectionConfigurationProvider in the above code snippet. </p>
<p>Once encrypted, this section will have encrypted data which is not readable by humans.</p>
<p>The connection string can be still accessed in code by regular ways,</p>
<p>SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Sql"].ConnectionString);</p>
<p>To see back the original connection string we need to decrypt it.</p>
<p>To decrypt a connection string section,</p>
<p>  protected void btnDecrypt_Click(object sender, EventArgs e)</p>
<p>    {</p>
<p>        Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);</p>
<p>        ConfigurationSection section = config.GetSection(&#8220;connectionStrings&#8221;);</p>
<p>        if (section.SectionInformation.IsProtected)</p>
<p>        {</p>
<p>            section.SectionInformation.UnprotectSection();</p>
<p>            config.Save();</p>
<p>        }</p>
<p>    }</p>
<p>Use App_Offline.htm to make application Offline</p>
<p>When performing an upgradation of an existing website and if you expect a downtime, then it will be good if we give a generic message to the users accessing the site at that time instead of an error.</p>
<p>The trick is, just include a HTML file called App_Offline.htm in the root directory and include some messages on the page. Anyone trying to access the site at that time will be presented with the content in the App_Offline.htm file. ASP.Net will shutdown the app domain and sends back the content of this html file instead for every request. </p>
<p>App_Offline.htm</p>
<p>    Untitled Page</p>
<h3>We are Upgrading!!! Please visit us later!!!</h3>
<p>If the above page content is not showing up on your browser, then just do the following changes in your IE. Open IE &gt; Tools &gt;Internet Options&gt; Advanced &gt; Uncheck &#8220;Show Friendly Http error messages&#8221;.</p>
<p>Use Web Deployment Project to Create Release files</p>
<p>Ø       For Visual Studio 2005, the plug-in can be downloaded here. </p>
<p>Ø       For Visual Studio 2008, the plug-in can be downloaded here. </p>
<p>Features of the Plug-in</p>
<p>The Web Deployment project will provide the following features for building and deploying ASP.NET Web sites: </p>
<p>1.      ASP.NET 2.0 precompilation as part of the build process. </p>
<p>2.      More flexible options for generating compiled assemblies from a Web      project, including these alternatives: </p>
<p>Ø       A single assembly for the entire Web site. </p>
<p>Ø       One assembly per content folder. </p>
<p>Ø       A single assembly for all UI components. </p>
<p>Ø       An assembly for each compiled file in the Web site. </p>
<p>3.      Assembly signing options. </p>
<p>4.      The ability to define custom pre-build and post-build actions. </p>
<p>5.      The ability to exclude folders from the build. </p>
<p>6.      The ability to modify settings in the Web.config file, such as the  element, based on the Visual Studio build configuration. </p>
<p>7.      Support for creating .msi files with setup projects.</p>
<p> Sponsors </p>
<p>Useful Books For Developers<br />
 More books..  </p>
<p>Similar Articles<br />
Exploring Themes and Skins in ASP.Net 2.0<br />
Posted on 8/11/2009 @ 7:45 AM By Satheesh Babu<br />
SEO Friendly Custom Paging and Jump To a Page Functionality in GridView Control Using LINQ<br />
Posted on 7/16/2009 @ 9:19 AM By Satheesh Babu<br />
User Controls and Dynamic User controls in ASP.Net<br />
Posted on 7/10/2009 @ 11:37 PM By Satheesh Babu<br />
Working with DateTime Object and Formatting DateTime Object in ASP.Net<br />
Posted on 7/2/2009 @ 5:42 AM By Bala Murugan<br />
Custom Paging for GridView using LINQ<br />
Posted on 6/11/2009 @ 9:09 AM By Satheesh Babu  </p>
<p>Configure Custom Error Page in Web.Config file</p>
<p>Use the customError section in web.config to redirect to a generic error page in case of any exception. This will give a better user experience when compared to showing some technical exception messages to the users.</p>
<p>mode </p>
<p>On  </p>
<p>Specifies that custom errors are enabled. If no defaultRedirect attribute is specified, users see a generic error. The custom errors are shown to the remote clients and to the local host. </p>
<p>Off </p>
<p>Specifies that custom errors are disabled. The detailed ASP.NET errors are shown to the remote clients and to the local host. </p>
<p>RemoteOnly </p>
<p>Specifies that custom errors are shown only to the remote clients, and that ASP.NET errors are shown to the local host. This is the default value. </p>
<p>You can change this setting accordingly to get the detailed report of an error after deployed to the production.</p>
<p>Separate Application pool</p>
<p>Application Pools a.k.a App Pools is introduced with IIS 6.0 to isolate websites into a group called Application Pools. We can say application pools are a group of one or more URLs that are served by a worker process, means applications running in a single app pools runs in same worker process w3wp.exe, thus providing a boundary so that if one application fails it doesn’t hinder other applications running on other app pools. So as a good practice each website can be assigned with a separate app pool.</p>
<p>     Refer my article Deploying ASP.Net Applications to create new application pool.</p>
<p>Custom Service Account </p>
<p>It is the identity of the App pool under which it services the request. It is an windows account that has very less privileges on the server so that we can reduce the security risk and loop holes. There can be several reasons to opt for custom service account over the default Network service account. Some of the reasons are:</p>
<p>Ø       We can have different access controls for different applications on the local and network resources such as fileservers, etc.</p>
<p>Ø       It is also a mode of isolating one application from another by giving a separate identity so other applications cannot access the resource of another application.</p>
<p>Ø       We can prevent any accidental or deliberate changes to the access controls or permissions associated with the general purpose Network Service account from affecting your application.</p>
<p>To create new service account, refer here.</p>
<p>For Intranet applications use Windows Authentication to connect to database </p>
<p>If your application is hosted in an intranet domain, then use windows authentication to connect to the database. The advantage of this approach, you can use the same windows service account configured to run your app pool in IIS 6.0 to connect to the database. This prevents the need to store the password as a clear text in web.config.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/giteshsankhe.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/giteshsankhe.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/giteshsankhe.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/giteshsankhe.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/giteshsankhe.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/giteshsankhe.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/giteshsankhe.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/giteshsankhe.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/giteshsankhe.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/giteshsankhe.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/giteshsankhe.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/giteshsankhe.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/giteshsankhe.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/giteshsankhe.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=giteshsankhe.wordpress.com&amp;blog=8976745&amp;post=9&amp;subd=giteshsankhe&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://giteshsankhe.wordpress.com/2009/08/12/tips-for-deploying-asp-net-application-in-production/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3edbd7dbd12b702734dd43ef44655d7f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">giteshsankhe</media:title>
		</media:content>
	</item>
		<item>
		<title>Grid View</title>
		<link>http://giteshsankhe.wordpress.com/2009/08/12/7/</link>
		<comments>http://giteshsankhe.wordpress.com/2009/08/12/7/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 12:20:21 +0000</pubDate>
		<dc:creator>giteshsankhe</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://giteshsankhe.wordpress.com/2009/08/12/7/</guid>
		<description><![CDATA[GridView Tips and Tricks using ASP.NET 2.0 The GridView control is quiet a handy control and is the most commonly used control when building an ASP.NET site. The more you work with it, the more you realize how powerful it can be while presenting data. In this article, we will explore some of the most [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=giteshsankhe.wordpress.com&amp;blog=8976745&amp;post=7&amp;subd=giteshsankhe&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>GridView Tips and Tricks using ASP.NET 2.0</p>
<p>The GridView control is quiet a handy control and is the most commonly used control when building an ASP.NET site. The more you work with it, the more you realize how powerful it can be while presenting data. In this article, we will explore some of the most frequently asked questions about the GridView control. The article discusses ten tips and tricks that you can use while using the GridView control.<br />
Update: The second and third part of this article containing 17 more tips and tricks about the GridView can be found over here:<br />
Some More GridView Tips and Tricks using ASP.NET &#8211; Part II<br />
GridView Tips and Tricks using ASP.NET &#8211; Part III</p>
<p>Tip 1: Add, Update, Delete Records in a Gridview using SqlDataSource<br />
By default, the GridView control doesn’t have support for inserting new records. However you can use the built-in edit or delete functionality of the GridView control. Let us explore how to insert new records and Update and Delete existing records in Gridview. Just copy and paste the code in your project. We will be using the ‘Categories’ table in the ‘Northwind’ database.<br />
GridView.aspx</p>
<p>Grid View Add Update Delete</p>
<div>    </div>
<p>&lt;asp:Label ID=&#8221;Label1&#8243; runat=&#8221;server&#8221; Text=&#8221;&gt;</p>
<p>&lt;asp:Label ID=&#8221;Label1&#8243; runat=&#8221;server&#8221; Text=&#8221;&gt;</p>
<p>&lt;asp:TextBox ID=&#8221;TextBox1&#8243; runat=&#8221;server&#8221; Text=&#8221;&gt;</p>
<p>&lt;asp:Label ID=&#8221;Label2&#8243; runat=&#8221;server&#8221; Text=&#8221;&gt;</p>
<p>&lt;asp:TextBox ID=&#8221;TextBox2&#8243; runat=&#8221;server&#8221; Text=&#8221;&gt;</p>
<p>&lt;asp:Label ID=&#8221;Label3&#8243; runat=&#8221;server&#8221; Text=&#8221;&gt;</p>
<p>GridView.aspx.cs<br />
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)<br />
{<br />
SqlConnection conn = new SqlConnection(<br />
ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);<br />
try<br />
{<br />
if (e.CommandName.Equals(&#8220;New&#8221;))<br />
{<br />
LinkButton btnNew = e.CommandSource as LinkButton;<br />
GridViewRow row = btnNew.NamingContainer as GridViewRow;<br />
if (row == null)<br />
{<br />
return;<br />
}<br />
TextBox txtCatName = row.FindControl(&#8220;CategoryNameTextBox&#8221;) as TextBox;<br />
TextBox txtDescription = row.FindControl(&#8220;DescriptionTextBox&#8221;) as TextBox;<br />
SqlCommand cmd = new SqlCommand(&#8220;INSERT INTO [Categories] ([CategoryName], [Description]) VALUES (@CategoryName, @Description)&#8221;,conn);<br />
cmd.Parameters.AddWithValue(&#8220;CategoryName&#8221;, txtCatName.Text);<br />
cmd.Parameters.AddWithValue(&#8220;Description&#8221;,txtDescription.Text);<br />
conn.Open();</p>
<p>if (cmd.ExecuteNonQuery() == 1)</p>
<p>{<br />
GridView1.DataBind();<br />
}<br />
}<br />
}<br />
catch (Exception ex)<br />
{</p>
<p>}<br />
finally<br />
{<br />
conn.Close();<br />
}<br />
}<br />
Web.config</p>
<p>Tip 2: Paging and Sorting a GridView without Refreshing a Page<br />
If you have created a GridView and have bound it to a data source control, you can avoid postback during sorting and paging by setting ‘EnableSortingAndPagingCallbacks’ property of the GridView to True.<br />
Just remember that when you set the &#8216;EnableSortingAndPagingCallbacks&#8217; property to true, you cannot use Template Fields in the GridView.</p>
<p>Tip 3: Pop-up a Confirmation box before Deleting a row in GridView<br />
Add a template field and drop a button in it, using which the user will delete the record. In the OnClientClick event, call the confirm() function as mentioned below:</p>
<p>Tip 4: Display details of the Row selected in the GridView<br />
Assuming you have a button called ‘Select’ in your GridView with CommandName ‘Select’, to find out the row clicked and display the row’s details, use this code:<br />
C#<br />
private void GridView1_RowCommand(Object sender,GridViewCommandEventArgs e)<br />
{<br />
if (e.CommandName == &#8220;Select&#8221;)<br />
{<br />
int idx = Convert.ToInt32(e.CommandArgument);<br />
GridViewRow selrow = GridView1.Rows[idx];<br />
string fstCell = selrow.Cells[0].Text;<br />
string scndCell = selrow.Cells[1].Text;<br />
// and so on<br />
// Thanks to Mark Rae (MVP) for pointing the typo. Earlier it was Cells[1] and Cells [2]<br />
}<br />
}</p>
<p>VB.NET<br />
Private Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)<br />
If e.CommandName = &#8220;Select&#8221; Then<br />
Dim idx As Integer = Convert.ToInt32(e.CommandArgument)<br />
Dim selrow As GridViewRow = GridView1.Rows(idx)<br />
Dim fstCell As String = selrow.Cells(0).Text<br />
Dim scndCell As String = selrow.Cells(1).Text<br />
&#8216; and so on<br />
End If<br />
End Sub</p>
<p>Tip 5: Retrieve Details of the Row being Modified in GridView<br />
C#<br />
void GridView1_RowUpdated(Object sender, GridViewUpdatedEventArgs e)<br />
{<br />
// Retrieve the row being edited.<br />
int index = GridView1.EditIndex;<br />
GridViewRow row = GridView1.Rows[index];</p>
<p>// Retrieve the value of the first cell<br />
lblMsg.Text = &#8220;Updated record &#8221; + row.Cells[1].Text;<br />
}<br />
VB.NET<br />
Private Sub GridView1_RowUpdated(ByVal sender As Object, ByVal e As GridViewUpdatedEventArgs)<br />
&#8216; Retrieve the row being edited.<br />
Dim index As Integer = GridView1.EditIndex<br />
Dim row As GridViewRow = GridView1.Rows(index)</p>
<p>&#8216; Retrieve the value of the first cell<br />
lblMsg.Text = &#8220;Updated record &#8221; &amp; row.Cells(1).Text<br />
End Sub</p>
<p>Tip 6: Retrieve Details of the Row being Deleted in GridView<br />
The ID of the row being deleted must be in the GridView.DataKeyNames collection.<br />
C#<br />
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)<br />
{<br />
int ID = (int)GridView1.DataKeys[e.RowIndex].Value;<br />
// Query the database and get the values based on the ID<br />
}<br />
VB.NET<br />
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs)<br />
Dim ID As Integer = CInt(GridView1.DataKeys(e.RowIndex).Value)<br />
&#8216; Query the database and get the values based on the ID<br />
End Sub</p>
<p>Tip 7: Cancelling Update and Delete in a GridView<br />
RowUpdating &#8211; Occurs when a row&#8217;s Update button is clicked, but before the GridView control updates the row.<br />
RowDeleting – Occurs when a row&#8217;s Delete button is clicked, but before the GridView control deletes the row.<br />
C#<br />
protected void gvDetail_RowUpdating(object sender, GridViewUpdateEventArgs e)<br />
{<br />
e.Cancel = true;<br />
}<br />
void GridView1_RowDeleting(Object sender, GridViewDeleteEventArgs e)<br />
{<br />
// Check for a condition and cancel the delete<br />
// There should be atleast one row left in the GridView<br />
if (GridView1.Rows.Count &lt;= 1)<br />
{<br />
e.Cancel = true;<br />
}<br />
}<br />
VB.NET<br />
Protected Sub gvDetail_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)<br />
e.Cancel = True<br />
End Sub<br />
Private Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs)<br />
&#8216; Check for a condition and cancel the delete<br />
&#8216; There should be atleast one row left in the GridView<br />
If GridView1.Rows.Count &lt;= 1 Then<br />
e.Cancel = True<br />
End If<br />
End Sub<br />
Tip 8: Paging and Sorting in GridView without using Datasource control<br />
Original Code Author: Ryan Olshan<br />
C#</p>
<p>private string ConvertSortDirectionToSql(SortDirection sortDireciton)<br />
{<br />
string newSortDirection = String.Empty;<br />
switch (sortDirection)<br />
{<br />
case SortDirection.Ascending:<br />
newSortDirection = &#8220;ASC&#8221;;<br />
break;<br />
case SortDirection.Descending:<br />
newSortDirection = &#8220;DESC&#8221;;<br />
break;<br />
}<br />
return newSortDirection<br />
}<br />
protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)<br />
{<br />
gridView.PageIndex = e.NewPageIndex;<br />
gridView.DataBind();<br />
}<br />
protected void gridView_Sorting(object sender, GridViewSortEventArgs e)<br />
{<br />
DataTable dataTable = gridView.DataSource as DataTable;<br />
if (dataTable != null)<br />
{<br />
DataView dataView = new DataView(dataTable);<br />
dataView.Sort = e.SortExpression + &#8221; &#8221; + ConvertSortDirectionToSql(e.SortDirection);<br />
gridView.DataSource = dataView;<br />
gridView.DataBind();<br />
}<br />
}<br />
VB.NET<br />
Private Function ConvertSortDirectionToSql(ByVal sortDireciton As SortDirection) As String<br />
Dim newSortDirection As String = String.Empty</p>
<p>Select Case sortDirection<br />
Case SortDirection.Ascending<br />
newSortDirection = &#8220;ASC&#8221;</p>
<p>Case SortDirection.Descending<br />
newSortDirection = &#8220;DESC&#8221;<br />
End Select</p>
<p>Return newSortDirection<br />
End Function</p>
<p>Protected Sub gridView_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)<br />
gridView.PageIndex = e.NewPageIndex<br />
gridView.DataBind()<br />
End Sub</p>
<p>Protected Sub gridView_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs)<br />
Dim dataTable As DataTable = TryCast(gridView.DataSource, DataTable)</p>
<p>If Not dataTable Is Nothing Then<br />
Dim dataView As DataView = New DataView(dataTable)<br />
dataView.Sort = e.SortExpression &amp; &#8221; &#8221; &amp; ConvertSortDirectionToSql(e.SortDirection)</p>
<p>gridView.DataSource = dataView<br />
gridView.DataBind()<br />
End If<br />
End Sub</p>
<p>Tip 9: Delete Multiple rows in a GridView<br />
Check this article of mine over here.</p>
<p>Tip 10: Export GridView To Excel<br />
C#<br />
protected void Button1_Click(object sender, EventArgs e)<br />
{<br />
Response.AddHeader(&#8220;content-disposition&#8221;, &#8220;attachment;filename=FileName.xls&#8221;);<br />
Response.Charset = String.Empty;<br />
Response.ContentType = &#8220;application/vnd.xls&#8221;;<br />
System.IO.StringWriter sw = new System.IO.StringWriter();<br />
System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(sw);<br />
GridView1.RenderControl(hw);<br />
Response.Write(sw.ToString());<br />
Response.End();<br />
}<br />
VB.NET<br />
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)<br />
Response.AddHeader(&#8220;content-disposition&#8221;, &#8220;attachment;filename=FileName.xls&#8221;)<br />
Response.Charset = String.Empty<br />
Response.ContentType = &#8220;application/vnd.xls&#8221;<br />
Dim sw As System.IO.StringWriter = New System.IO.StringWriter()<br />
Dim hw As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(sw)<br />
GridView1.RenderControl(hw)<br />
Response.Write(sw.ToString())<br />
Response.End()<br />
End Sub</p>
<p>Well that was a quick overview of some of the most frequently used features of the GridView control. I hope you liked the article and I thank you for viewing it.</p>
<p>Some More GridView Tips and Tricks using ASP.NET &#8211; Part II</p>
<p>The GridView control is quiet a handy control and is the most commonly used control when building an ASP.NET site. The more you work with it, the more you realize how powerful it can be while presenting data.<br />
In one of our previous articles GridView Tips and Tricks using ASP.NET 2.0, we discussed ten of the most frequently asked questions about the GridView control. This article adds ten more tips and tricks to our collection, related to the GridView control.<br />
[Update: The 3rd part of the GridView Tips and Tricks can be found over here: GridView Tips and Tricks using ASP.NET - Part III ]<br />
For this article, we would be using the following template to populate the GridView.</p>
<p>GridView Tips and Tricks Part 2</p>
<div>
<p>&lt;asp:Label ID=&#8221;lblCategoryID&#8221; runat=&#8221;server&#8221; Text=&#8221;&gt;</p>
<p>&lt;asp:TextBox ID=&#8221;txtCategoryName&#8221; runat=&#8221;server&#8221; Text=&#8221;&gt;</p>
<p>&lt;asp:Label ID=&#8221;lblCategoryName&#8221; runat=&#8221;server&#8221; Text=&#8221;&gt;</p>
<p>&lt;asp:TextBox ID=&#8221;txtDesc&#8221; runat=&#8221;server&#8221; Text=&#8221;&gt;</p>
<p>&lt;asp:Label ID=&#8221;lblDesc&#8221; runat=&#8221;server&#8221; Text=&#8221;&gt;</p></div>
<p>The web.config holding the connection will look similar to the following:</p>
<p>&#8230;</p>
<p>Tip 1: Enable Disable Controls inside a GridView<br />
There are at times when you have to disable controls on some rows, when a certain condition is satisfied. In this snippet, we will see how to disable editing for rows that have the CategoryName as ‘Confections’. Use the following code:<br />
C#<br />
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)<br />
{<br />
if (e.Row.RowType == DataControlRowType.DataRow)<br />
{<br />
if (e.Row.DataItem != null)<br />
{<br />
Label lblControl = (Label)e.Row.Cells[2].FindControl(&#8220;lblCategoryName&#8221;);</p>
<p>if(lblControl.Text == &#8220;Confections&#8221;)<br />
{<br />
e.Row.Cells[0].Enabled = false;<br />
}<br />
}<br />
}<br />
}<br />
VB.NET<br />
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)<br />
If e.Row.RowType = DataControlRowType.DataRow Then<br />
If Not e.Row.DataItem Is Nothing Then<br />
Dim lblControl As Label = CType(e.Row.Cells(2).FindControl(&#8220;lblCategoryName&#8221;), Label)</p>
<p>If lblControl.Text = &#8220;Confections&#8221; Then<br />
e.Row.Cells(0).Enabled = False<br />
End If<br />
End If<br />
End If<br />
End Sub</p>
<p>Tip 2: Adding Arrows for Sorting Columns in a GridView<br />
When you are sorting the columns in a GridView, it would be a nice to have feature, to display arrows which depict either an ascending or descending sort as shown below. Create a folder called ‘images’ and add two small images called up.gif and down.gif:<br />
C#<br />
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)<br />
{<br />
if (e.Row.RowType == DataControlRowType.Header)<br />
{<br />
foreach (TableCell cell in e.Row.Cells)<br />
{<br />
if (cell.HasControls())<br />
{<br />
LinkButton btnSort = (LinkButton)cell.Controls[0];<br />
Image image = new Image();<br />
if (btnSort.Text == GridView1.SortExpression)<br />
{<br />
if (GridView1.SortDirection == SortDirection.Ascending)<br />
{<br />
image.ImageUrl = &#8220;images/up.gif&#8221;; }<br />
else<br />
{<br />
image.ImageUrl = &#8220;images/down.gif&#8221;;<br />
}<br />
}<br />
cell.Controls.Add(image);</p>
<p>}<br />
}<br />
VB.NET<br />
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)<br />
If e.Row.RowType = DataControlRowType.Header Then<br />
For Each cell As TableCell In e.Row.Cells<br />
If cell.HasControls() Then<br />
Dim btnSort As LinkButton = CType(cell.Controls(0), LinkButton)<br />
Dim image As Image = New Image()<br />
If btnSort.Text = GridView1.SortExpression Then<br />
If GridView1.SortDirection = SortDirection.Ascending Then<br />
image.ImageUrl = &#8220;images/up.gif&#8221;<br />
Else<br />
image.ImageUrl = &#8220;images/down.gif&#8221;<br />
End If<br />
End If<br />
cell.Controls.Add(image)<br />
End If<br />
Next cell<br />
Tip 3: How to Add a Row Number to the Gridview<br />
There are a couple of ways to do this. However I will share a very handy tip that was shared by XIII in the asp.net forums.<br />
Just add the following tags to your section of your GridView</p>
<p>Tip 4: How to programmatically hide a column in the GridView<br />
There are two conditions to be checked in the Page_Load to hide a columns in the GridView, let us say the 3rd column:<br />
If ‘AutoGenerateColumns’ = True on the GridView<br />
C#<br />
GridView1.HeaderRow.Cells[2].Visible = false;<br />
foreach (GridViewRow gvr in GridView1.Rows)<br />
{<br />
gvr.Cells[2].Visible = false;<br />
}<br />
VB.NET<br />
GridView1.HeaderRow.Cells(2).Visible = False<br />
For Each gvr As GridViewRow In GridView1.Rows<br />
gvr.Cells(2).Visible = False<br />
Next gvr<br />
If ‘AutoGenerateColumns’ = False on the GridView<br />
C#<br />
GridView1.Columns[2].Visible = false;<br />
VB.NET<br />
GridView1.Columns(2).Visible = False<br />
Tip 5: Handling Concurrency Issues in GridView<br />
If you are using the SqlDataSource (or ObjectDataSource), you can use both the SqlDataSource.ConflictDetection and OldValuesParameterFormatString property to handle concurrency issues. These two properties together control how to perform updates and delete operations when the underlying data source changes, while the operation is being carried out. The original and modified versions of each column can be tracked using the two properties.<br />
Read more about it over here.<br />
Tip 6: How to transfer multiple values from GridView to a different page<br />
Check my article over here:</p>
<p>http://www.dotnetcurry.com/ShowArticle.aspx?ID=147</p>
<p>A common requirement in our projects is to select a GridView row and pass multiple values of the selected row to another page. I recently got a request from a few readers who wanted an article on this. In this article, we will explore how simple it is to achieve this requirement.<br />
I assume you have some basic understanding of the GridView and how to bind it to a Data Source control. The Hyperlink control added to the GridView makes it quiet easy to select a row and send single/multiple values to a different page through the URL. Let us see how:<br />
Step 1: Create a new ASP.NET website. Drag and drop a SqlDataSource Control to the page and use the wizard to connect to the Northwind database. Select the CustomerId, CompanyName, ContactName, Address and City from the Customers table. The wizard will also prompt you to save the connection string in the web.config file. Choose to do so. The design code will look similar to the following:<br />
&lt;asp:SqlDataSource ID=&#8221;SqlDataSource1&#8243; runat=&#8221;server&#8221; ConnectionString=&#8221;"<br />
SelectCommand=&#8221;SELECT [CustomerID], [CompanyName], [ContactName], [Address], [City] FROM [Customers]&#8220;&gt;</p>
<p>An entry will be added to the web.config file as shown below:</p>
<p>Step 2: Now add a GridView control to the page and using the smart tag, select the DataSource to be SqlDataSource1 in the GridView tasks panel. Using the same panel, click on the Enable Paging and Enable Sorting checkboxes. The source will look similar to the following. Observe that the DataKeyNames is set to ‘CustomerId’, that is the primary key of the Customers table.</p>
<p>Step 3: We will now add another page in our project. In the Solution Explorer, right click the project &gt; Add New Item &gt; Web Form &gt; Rename it to ‘CustomerDetails.aspx’.<br />
Step 4: Go back to Default.aspx and add two hyperlink fields. We will see how to pass a single value as well as multiple values using the two hyperlink fields.<br />
Single Value:<br />
Add the following hyperlink control after the tag in the GridView as shown below:</p>
<p>Multiple Values:<br />
Just below the first hyperlink field, add another hyperlink field as shown below:</p>
<p>In the source code shown above, we are using the hyperlink field and setting some properties that will make it extremely easy to pass values to a different page. The &#8216;DataNavigateUrlFields&#8217; sets the names of the fields, that is to be used to construct the URL in the HyperLinkField. In the first hyperlink, since we are passing only a single value, the DataNavigateUrlFields contains only CustomerID. However in the second hyperlink, since there are multiple values to be passed, DataNavigateUrlFields contains all the names of the fields that are to be passed as query string to CustomerDetails.aspx<br />
Similarly, the &#8216;DataNavigateUrlFormatString&#8217; sets the string that specifies the format in which the URL is to be created. The &#8216;Text&#8217; property represents the text that will be displayed to the user. The entire source code will look similar to the following:</p>
<div>&lt;asp:SqlDataSource ID=&#8221;SqlDataSource1&#8243; runat=&#8221;server&#8221; ConnectionString=&#8221;"<br />
SelectCommand=&#8221;SELECT [CustomerID], [CompanyName], [ContactName], [Address], [City] FROM [Customers]&#8220;&gt;</div>
<p>Step 5: The last step is to retrieve the query string variables from the URL in the CustomerDetails.aspx page. Add the following code for that:<br />
C#<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
string cid = Request.QueryString["CID"];<br />
string cname = Request.QueryString["CName"];<br />
string contactName = Request.QueryString["ContactName"];<br />
string address = Request.QueryString["Addr"];<br />
string city = Request.QueryString["City"];<br />
}<br />
VB.NET<br />
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)<br />
Dim cid As String = Request.QueryString(&#8220;CID&#8221;)<br />
Dim cname As String = Request.QueryString(&#8220;CName&#8221;)<br />
Dim contactName As String = Request.QueryString(&#8220;ContactName&#8221;)<br />
Dim address As String = Request.QueryString(&#8220;Addr&#8221;)<br />
Dim city As String = Request.QueryString(&#8220;City&#8221;)<br />
End Sub<br />
Set a breakpoint at the Page_Load method of the CustomerDetails.aspx. Run the application and click on either the ‘Pass Single Value’ or ‘Pass Multiple Values’ hyperlink to pass values to the CustomerDetails.aspx page. Using the breakpoint, observe the values of the selected row being passed to the CustomerDetails page.<br />
I hope this article was useful and I thank you for viewing it.</p>
<p>Tip 7: Displaying Empty Data in a GridView<br />
When there are no results returned from the GridView control’s data source, the short and simple way of displaying a message to the user, is to use the GridView’s EmptyDataText property.</p>
<p>Note: You can also add style to the EmptyDataText by using the EmptyDataRowStyle property.<br />
Tip 8: Displaying an Image in case of Empty Data in a GridView<br />
As an alternative to using the EmptyDataText property, if you need to display an image or any HTML/ASP.NET control, you can use the EmptyDataTemplate. In this snippet below, we are using the image control in the to display an image.</p>
<p>Tip 9: Highlight a Row in GridView without a PostBack<br />
Check my article on the same over here:</p>
<p>http://www.dotnetcurry.com/ShowArticle.aspx?ID=123</p>
<p>Selecting a row in the GridView causes a postback. In order to highlight a row in the GridView, you have to set the ‘SelectedRowStyle’ property which takes effect when the postback occurs. In this article, we will see how to highlight a row without causing a postback.<br />
We will be using the RowCreated event of the GridView. A GridViewRow object is created for each row in the control before the GridView is rendered. Whenever a row in the GridView gets created, the RowCreated event is fired. Using this event, we can customize the behavior of the GridView. For e.g.: adding client script to the row or customizing the content of the row. Let us see an example where we will be adding some client script to the GridView. I assume that you have some experience of creating data sources and binding controls to it.<br />
Perform the following steps:<br />
Step 1: Create an asp.net website. In the Default.aspx page, add a GridView and a SqlDataSource control to it.<br />
Step 2: Configure the connection of SqlDataSource to point to the Northwind database. Create query for the Select command to fetch records from the Customer table. The resultant code will look similar to the one given below:<br />
&lt;asp:SqlDataSource ID=&#8221;SqlDataSource1&#8243; runat=&#8221;server&#8221; ConnectionString=&#8221;"<br />
SelectCommand=&#8221;SELECT [CustomerID], [CompanyName], [ContactName], [ContactTitle], [Address], [City] FROM [Customers]&#8220;&gt;</p>
<p>The web.config will look similar to the following</p>
<p>Step 3: Once the SqlDataSource has been configured, bind the GridView to this data source. Also set ‘AllowPaging’ and ‘AllowSorting’ to true. The mark up will look similar to the following:</p>
<p>&lt;asp:SqlDataSource ID=&#8221;SqlDataSource1&#8243; runat=&#8221;server&#8221; ConnectionString=&#8221;"<br />
SelectCommand=&#8221;SELECT [CustomerID], [CompanyName], [ContactName], [ContactTitle], [Address], [City] FROM [Customers]&#8220;&gt;</p>
<p>Step 4: Now switch to the design mode and select the GridView. Go to the properties window (F4) and click on the lightning like bolt to display the events of the GridView. Double click the RowCreated event to add the event. The mark up will look similar to the following</p>
<p>&#8230;</p>
<p>Step 5: In the code behind of Default.aspx, add the following code to the RowCreated event handler<br />
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)<br />
{<br />
e.Row.Attributes.Add(&#8220;onMouseOver&#8221;, &#8220;this.style.background=&#8217;#eeff00&#8242;&#8221;);<br />
e.Row.Attributes.Add(&#8220;onMouseOut&#8221;, &#8220;this.style.background=&#8217;#ffffff&#8217;&#8221;);<br />
}<br />
As you are already aware that the GridView is rendered as a HTML table and each row as . In the code shown above, we are using the Attributes property of the AttributeCollection to add extra properties to the element. The onMouseOver and the onMouseOut events are added that enable the row to change its color whenever the mouse is over a particular row.<br />
Run the application and see the color of the rows changing, that too without a postback!!<br />
Well that was a quick overview of the RowCreated event. You can also use the same event to find the index of the row clicked. Just use e.Row.DataItemIndex.ToString() to retrieve the selected row index information.<br />
I hope you liked the article and I thank you for viewing it.</p>
<p>Tip 10: How to Bind a List to a GridView<br />
Let us see how to bind a List to a GridView. We assume that the ‘AutoGenerateColumns’ = True. We will create a class called Employees and bind it to the GridView with the help of a List.<br />
Create a class called ‘Employees’<br />
C#<br />
public class Employee<br />
{<br />
private string enm;<br />
private int ageofemp;<br />
private string department;</p>
<p>public string EName<br />
{<br />
get<br />
{<br />
return enm;<br />
}<br />
set<br />
{<br />
enm = value;<br />
}<br />
}</p>
<p>public int Age<br />
{<br />
get<br />
{<br />
return ageofemp;<br />
}<br />
set<br />
{<br />
ageofemp = value;<br />
}<br />
}</p>
<p>public string Dept<br />
{<br />
get<br />
{<br />
return department;<br />
}<br />
set<br />
{<br />
department = value;<br />
}<br />
}</p>
<p>public Employee(string ename, int age, string dept)<br />
{<br />
this.enm = ename;<br />
this.ageofemp = age;<br />
this.department = dept;<br />
}</p>
<p>}</p>
<p>VB.NET<br />
Public Class Employee<br />
Private enm As String<br />
Private ageofemp As Integer<br />
Private department As String</p>
<p>Public Property EName() As String<br />
Get<br />
Return enm<br />
End Get<br />
Set(ByVal value As String)<br />
enm = value<br />
End Set<br />
End Property</p>
<p>Public Property Age() As Integer<br />
Get<br />
Return ageofemp<br />
End Get<br />
Set(ByVal value As Integer)<br />
ageofemp = value<br />
End Set<br />
End Property</p>
<p>Public Property Dept() As String<br />
Get<br />
Return department<br />
End Get<br />
Set(ByVal value As String)<br />
department = value<br />
End Set<br />
End Property</p>
<p>Public Sub New(ByVal ename As String, ByVal age As Integer, ByVal dept As String)<br />
Me.enm = ename<br />
Me.ageofemp = age<br />
Me.department = dept<br />
End Sub</p>
<p>End Class</p>
<p>Bind the ‘Employee’ data to the GridView using a List<br />
C#<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
System.Collections.Generic.List emp = new System.Collections.Generic.List();<br />
emp.Add(new Employee(&#8220;Jack&#8221;, 22, &#8220;Marketing&#8221;));<br />
emp.Add(new Employee(&#8220;Anna&#8221;, 28, &#8220;Advertising&#8221;));<br />
emp.Add(new Employee(&#8220;Linra&#8221;, 23, &#8220;Advertising&#8221;));<br />
emp.Add(new Employee(&#8220;Jacob&#8221;, 44, &#8220;Production&#8221;));<br />
emp.Add(new Employee(&#8220;Zinger&#8221;, 28, &#8220;PPC&#8221;));</p>
<p>GridView1.DataSource = emp;<br />
GridView1.DataBind();</p>
<p>}<br />
VB.NET<br />
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)<br />
Dim emp As System.Collections.Generic.List(Of Employee) = New System.Collections.Generic.List(Of Employee)()<br />
emp.Add(New Employee(&#8220;Jack&#8221;, 22, &#8220;Marketing&#8221;))<br />
emp.Add(New Employee(&#8220;Anna&#8221;, 28, &#8220;Advertising&#8221;))<br />
emp.Add(New Employee(&#8220;Linra&#8221;, 23, &#8220;Advertising&#8221;))<br />
emp.Add(New Employee(&#8220;Jacob&#8221;, 44, &#8220;Production&#8221;))<br />
emp.Add(New Employee(&#8220;Zinger&#8221;, 28, &#8220;PPC&#8221;))</p>
<p>GridView1.DataSource = emp<br />
GridView1.DataBind()</p>
<p>End Sub<br />
Well that was a quick overview of some of the most frequently used features of the GridView control. I hope you liked the article and I thank you for viewing it.</p>
<p>GridView Tips and Tricks using ASP.NET – Part III</p>
<p>The GridView control is quiet a handy control and is the most commonly used control when building an ASP.NET site. The more you work with it, the more you realize how powerful it can be while presenting data.<br />
Moving ahead with our GridView Tips and tricks series, I have added some more tips in this article. The previous two articles on the Tips and Tricks are mentioned below:<br />
GridView Tips and Tricks using ASP.NET 2.0 – Part I<br />
Some More GridView Tips and Tricks using ASP.NET &#8211; Part II<br />
For this article, we would be using the following template to populate the GridView.</p>
<p>GridView Tips and Tricks Part 2</p>
<div>
<p>&lt;asp:Label ID=&#8221;lblCategoryID&#8221; runat=&#8221;server&#8221; Text=&#8221;&gt;</p>
<p>&lt;asp:TextBox ID=&#8221;txtCategoryName&#8221; runat=&#8221;server&#8221; Text=&#8221;&gt;</p>
<p>&lt;asp:Label ID=&#8221;lblCategoryName&#8221; runat=&#8221;server&#8221; Text=&#8221;&gt;</p>
<p>&lt;asp:TextBox ID=&#8221;txtDesc&#8221; runat=&#8221;server&#8221; Text=&#8221;&gt;</p>
<p>&lt;asp:Label ID=&#8221;lblDesc&#8221; runat=&#8221;server&#8221; Text=&#8221;&gt;</p></div>
<p>The web.config holding the connection will look similar to the following:</p>
<p>&#8230;</p>
<p>Tip 1: Change the color of a GridView Row based on some condition<br />
C#<br />
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)<br />
{<br />
if (e.Row.DataItem != null)<br />
{<br />
DataRowView drv = (DataRowView)e.Row.DataItem;<br />
string catName = Convert.ToString(drv["CategoryName"]);<br />
if (catName.Trim() == &#8220;Confections&#8221;)<br />
e.Row.BackColor = System.Drawing.Color.LightBlue;<br />
}<br />
}<br />
VB.NET<br />
Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs)<br />
If Not e.Row.DataItem Is Nothing Then<br />
Dim drv As DataRowView = CType(e.Row.DataItem, DataRowView)<br />
Dim catName As String = Convert.ToString(drv(&#8220;CategoryName&#8221;))<br />
If catName.Trim() = &#8220;Confections&#8221; Then<br />
e.Row.BackColor = System.Drawing.Color.LightBlue<br />
End If<br />
End If<br />
End Sub<br />
Tip 2: How to create an Image Command Field Column and add to the GridView at runtime<br />
C#<br />
if (!Page.IsPostBack)<br />
{<br />
CommandField cmdField = new CommandField();<br />
cmdField.ButtonType = ButtonType.Image;<br />
cmdField.SelectImageUrl = &#8220;~/Images/Home_Np1.GIF&#8221;;<br />
cmdField.ShowSelectButton = true;<br />
cmdField.HeaderText = &#8220;Select&#8221;;<br />
GridView1.Columns.Add(cmdField);<br />
GridView1.DataBind();<br />
}<br />
VB.NET<br />
If (Not Page.IsPostBack) Then<br />
Dim cmdField As CommandField = New CommandField()<br />
cmdField.ButtonType = ButtonType.Image<br />
cmdField.SelectImageUrl = &#8220;~/Images/Home_Np1.GIF&#8221;<br />
cmdField.ShowSelectButton = True<br />
cmdField.HeaderText = &#8220;Select&#8221;<br />
GridView1.Columns.Add(cmdField)<br />
GridView1.DataBind()<br />
End If<br />
Tip 3: How to display images in the GridView from Filesystem based on an existing Column<br />
Let us imagine that you have a folder ‘Images’ where you have stored images for each category. Eg: 1.GIF, 2.GIF, 3.GIF and so on. Now you want to display a different image based on each CategoryID. So for CategoryID = 1, the image is 1.GIF; for CategoryID=2, the image is 2.GIF and so on.</p>
<p>&lt;asp:Image runat=&#8221;server&#8221; ImageUrl=&#8221; &gt;</p>
<p>Tip 4: How to Retrieve Images from the database and display it in a GridView<br />
I will assume that we have a image column called CatImg in the Categories table.<br />
The first step would be to create an ImageHandler. In such scenarios such as the gridview, usually prefer to go in for a handler when I have to return binary data directly from the database. It gives more control on the resource returned. Moreover it is a preferred solution when you have to set the image programmatically.<br />
To add a handler, right click project &gt; Add New Item &gt; Generic Handler &gt; ShowImage.ashx. The code shown below, uses the Request.QueryString[“id”] to retrieve the CategoryID from it. The ID is then passed to the ‘ShowCatImage()’ method where the image is fetched from the database and returned in a MemoryStream object. We then read the stream into a byte array. Using the OutputStream.Write(), we write the sequence of bytes to the current stream and you get to see your image.<br />
C#</p>
<p>using System;<br />
using System.Configuration;<br />
using System.Web;<br />
using System.IO;<br />
using System.Data;<br />
using System.Data.SqlClient;</p>
<p>public class ShowImage : IHttpHandler<br />
{<br />
public void ProcessRequest(HttpContext context)<br />
{<br />
Int32 catid;<br />
if (context.Request.QueryString["id"] != null)<br />
catid = Convert.ToInt32(context.Request.QueryString["id"]);<br />
else<br />
throw new ArgumentException(&#8220;No parameter specified&#8221;);</p>
<p>context.Response.ContentType = &#8220;image/jpeg&#8221;;<br />
Stream strm = ShowCatImage(catid);<br />
byte[] buffer = new byte[4096];<br />
int byteSeq = strm.Read(buffer, 0, 4096);</p>
<p>while (byteSeq &gt; 0)<br />
{<br />
context.Response.OutputStream.Write(buffer, 0, byteSeq);<br />
byteSeq = strm.Read(buffer, 0, 4096);<br />
}<br />
//context.Response.BinaryWrite(buffer);<br />
}</p>
<p>public Stream ShowCatImage(int catid)<br />
{<br />
string conn = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;<br />
SqlConnection connection = new SqlConnection(conn);<br />
string sql = &#8220;SELECT catImg FROM Categories WHERE CategoryID = @ID&#8221;;<br />
SqlCommand cmd = new SqlCommand(sql, connection);<br />
cmd.CommandType = CommandType.Text;<br />
cmd.Parameters.AddWithValue(&#8220;@ID&#8221;, catid);<br />
connection.Open();<br />
object img = cmd.ExecuteScalar();<br />
try<br />
{<br />
return new MemoryStream((byte[])img);<br />
}<br />
catch<br />
{<br />
return null;<br />
}<br />
finally<br />
{<br />
connection.Close();<br />
}<br />
}</p>
<p>public bool IsReusable<br />
{<br />
get<br />
{<br />
return false;<br />
}<br />
}</p>
<p>}</p>
<p>VB.NET</p>
<p>Imports System<br />
Imports System.Configuration<br />
Imports System.Web<br />
Imports System.IO<br />
Imports System.Data<br />
Imports System.Data.SqlClient</p>
<p>Public Class ShowImage<br />
Implements IHttpHandler<br />
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest<br />
Dim catid As Int32<br />
If Not context.Request.QueryString(&#8220;id&#8221;) Is Nothing Then<br />
catid = Convert.ToInt32(context.Request.QueryString(&#8220;id&#8221;))<br />
Else<br />
Throw New ArgumentException(&#8220;No parameter specified&#8221;)<br />
End If</p>
<p>context.Response.ContentType = &#8220;image/jpeg&#8221;<br />
Dim strm As Stream = ShowCatImage(catid)<br />
Dim buffer As Byte() = New Byte(4095){}<br />
Dim byteSeq As Integer = strm.Read(buffer, 0, 4096)</p>
<p>Do While byteSeq &gt; 0<br />
context.Response.OutputStream.Write(buffer, 0, byteSeq)<br />
byteSeq = strm.Read(buffer, 0, 4096)<br />
Loop<br />
&#8216;context.Response.BinaryWrite(buffer);<br />
End Sub</p>
<p>Public Function ShowCatImage(ByVal catid As Integer) As Stream<br />
Dim conn As String = ConfigurationManager.ConnectionStrings(&#8220;NorthwindConnectionString&#8221;).ConnectionString<br />
Dim connection As SqlConnection = New SqlConnection(conn)<br />
Dim sql As String = &#8220;SELECT catImg FROM Categories WHERE CategoryID = @ID&#8221;<br />
Dim cmd As SqlCommand = New SqlCommand(sql, connection)<br />
cmd.CommandType = CommandType.Text<br />
cmd.Parameters.AddWithValue(&#8220;@ID&#8221;, catid)<br />
connection.Open()<br />
Dim img As Object = cmd.ExecuteScalar()<br />
Try<br />
Return New MemoryStream(CType(img, Byte()))<br />
Catch<br />
Return Nothing<br />
Finally<br />
connection.Close()<br />
End Try<br />
End Function</p>
<p>Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable<br />
Get<br />
Return False<br />
End Get<br />
End Property</p>
<p>End Class</p>
<p>To access this image in the GridView based on the CategoryID, just add the following:</p>
<p>&lt;asp:Image runat=&#8221;server&#8221; ImageUrl=&#8221; &gt;</p>
<p>Tip 5: How to programmatically enable/disable a control in the GridView when in the Edit Mode<br />
If you want to quickly take a decision whether to enable or disable a control when the user edits the row, then use the Enabled attribute and set it to a method that returns a bool value:</p>
<p>&lt;asp:TextBox ID=&#8221;txtCategoryName&#8221; runat=&#8221;server&#8221; Enabled=&#8221; Text=&#8221;&gt;</p>
<p>&lt;asp:Label ID=&#8221;lblCategoryName&#8221; runat=&#8221;server&#8221; Text=&#8221;&gt;</p>
<p>C#<br />
protected bool EnableDisableTextBox()<br />
{<br />
if (1 == 1)<br />
return false;<br />
}<br />
VB.NET<br />
Protected Function EnableDisableTextBox() As Boolean<br />
If 1 = 1 Then<br />
Return False<br />
End If<br />
End Function<br />
You can test this code by adding a CommandField to the GridView as shown below</p>
<p>Tip 6: How to insert an Image in between Rows of a GridView using ASP.NET<br />
Please check my article on the same over here</p>
<p>http://www.dotnetcurry.com/ShowArticle.aspx?ID=152</p>
<p>At times, you need to perform these custom routines, to add your own data, when the data is being bound to a GridView control. In this article, we will explore how to insert image or text in between the rows of a GridView. We will also see how we can create new rows on the fly and attach them to the GridView control at runtime. Follow these steps:<br />
Step 1: Create a new ASP.NET website. Drag and drop a SqlDataSource Control to the page and use the wizard to connect to the Northwind database. Select the CustomerId, CompanyName, ContactName, Address and City from the Customers table. The wizard will also prompt you to save the connection string in the web.config file. Choose to do so. The design code will look similar to the following:<br />
&lt;asp:SqlDataSource ID=&#8221;SqlDataSource1&#8243; runat=&#8221;server&#8221; ConnectionString=&#8221;"<br />
SelectCommand=&#8221;SELECT [CustomerID], [CompanyName], [ContactName], [Address], [City] FROM [Customers]&#8220;&gt;</p>
<p>An entry will be added to the web.config file as shown below:</p>
<p>Step 2: Now add a GridView control to the page and using the smart tag, select the DataSource to be SqlDataSource1 in the GridView tasks panel. Using the same panel, click on the Enable Paging and Enable Sorting checkboxes. The source will look similar to the following.</p>
<p>Step 3: We will now need to think of a way to add our own custom row with the image, in between the existing rows of a GridView. The GridView renders as a table and contains rows and cells. If we could somehow create a cell on the fly, add our image to the cell and then add the cell to the row, we should be able to achieve our requirement. All this needs to be done while the row is being bound to data in the GridView control. Well the event that we will make use of to perform all the action, is the GridView_RowDataBound event. This event enables you to provide an event-handling method that performs a custom routine, such as modifying the values of the data bound to the row, whenever this event occurs. Before that, add a page level variable called pgSize which will hold the row position at which we need to insert the image. Also add an image to your project that is about the same width as that of your GridView. The comments have been marked inside the code to help you understand. The entire code will look similar to the following:<br />
C#<br />
public partial class _Default : System.Web.UI.Page<br />
{<br />
static int pgSize;</p>
<p>protected void Page_Load(object sender, EventArgs e)<br />
{<br />
if(!Page.IsPostBack)<br />
pgSize = 0;<br />
}</p>
<p>protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)<br />
{<br />
if (e.Row.RowType == DataControlRowType.DataRow)<br />
{<br />
TableCell tCell = new TableCell();<br />
// create image<br />
Image img = new Image();<br />
img.ImageUrl = &#8220;subheader.jpg&#8221;;<br />
// add the image to the cell<br />
tCell.Controls.Add(img);</p>
<p>GridView gView = (GridView)sender;<br />
// set the colspan to occupy the other cells in the row<br />
int colSpan = gView.Columns.Count;<br />
tCell.Attributes["ColSpan"] = colSpan.ToString();</p>
<p>GridViewRow gRow = new GridViewRow(-1, -1, DataControlRowType.DataRow, DataControlRowState.Normal);<br />
// add the cells to the gridviewrow<br />
gRow.Cells.Add(tCell);</p>
<p>Table tbl = (Table)e.Row.Parent;</p>
<p>// set the pagesize initially to the pagecount/2<br />
// in our case it is 10/2 = 5. So the first image will<br />
// displayed after the 5th row.<br />
if(pgSize == 0)<br />
pgSize = GridView1.PageCount / 2;</p>
<p>// This step is performed so that we can display the image only after every<br />
// 5, 15, 25 ,35 rows and so on &#8230;<br />
// The logic is not perfect but will give you the idea<br />
if (Convert.ToDouble(e.Row.DataItemIndex + 1) / Convert.ToDouble(pgSize) == 1.0)<br />
{<br />
tbl.Controls.AddAt(gView.Controls[0].Controls.Count, gRow);<br />
// add 10 to the pgsize so that the image can be displayed<br />
// at rows 5, 15, 25 and so on..<br />
pgSize = pgSize + 10;<br />
}<br />
}<br />
}<br />
}</p>
<p>VB.NET<br />
Public Partial Class _Default<br />
Inherits System.Web.UI.Page<br />
Private Shared pgSize As Integer</p>
<p>Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)<br />
If (Not Page.IsPostBack) Then<br />
pgSize = 0<br />
End If<br />
End Sub</p>
<p>Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)<br />
If e.Row.RowType = DataControlRowType.DataRow Then<br />
Dim tCell As TableCell = New TableCell()<br />
&#8216; create image<br />
Dim img As Image = New Image()<br />
img.ImageUrl = &#8220;subheader.jpg&#8221;<br />
&#8216; add the image to the cell<br />
tCell.Controls.Add(img)</p>
<p>Dim gView As GridView = CType(sender, GridView)<br />
&#8216; set the colspan to occupy the other cells in the row<br />
Dim colSpan As Integer = gView.Columns.Count<br />
tCell.Attributes(&#8220;ColSpan&#8221;) = colSpan.ToString()</p>
<p>Dim gRow As GridViewRow = New GridViewRow(-1, -1, DataControlRowType.DataRow, DataControlRowState.Normal)<br />
&#8216; add the cells to the gridviewrow<br />
gRow.Cells.Add(tCell)</p>
<p>Dim tbl As Table = CType(e.Row.Parent, Table)</p>
<p>&#8216; set the pagesize initially to the pagecount/2<br />
&#8216; in our case it is 10/2 = 5. So the first image will<br />
&#8216; displayed after the 5th row.<br />
If pgSize = 0 Then<br />
pgSize = GridView1.PageCount / 2<br />
End If</p>
<p>&#8216; This step is performed so that we can display the image only after every<br />
&#8216; 5, 15, 25 ,35 rows and so on &#8230;<br />
&#8216; The logic is not perfect but will give you the idea<br />
If Convert.ToDouble(e.Row.DataItemIndex + 1) / Convert.ToDouble(pgSize) = 1.0 Then<br />
tbl.Controls.AddAt(gView.Controls(0).Controls.Count, gRow)<br />
&#8216; add 10 to the pgsize so that the image can be displayed<br />
&#8216; at rows 5, 15, 25 and so on..<br />
pgSize = pgSize + 10<br />
End If<br />
End If<br />
End Sub<br />
End Class</p>
<p>The rendered GridView at the end will look similar to the following</p>
<p>Well I hope this example has given you some insights of the various possibilities of customizing the GridView to suit our requirements. Keep visiting the site as we will explore more of these ‘unusual’ requirements that you could encounter while dealing with the GridView. I hope this article was useful and I thank you for viewing it</p>
<p>Tip 7: How to loop through all the rows in all the pages of a GridView<br />
One simple way to loop through all the rows in all the pages of a GridView is to access its DataSource. In this example, we will loop through the SQLDataSource to retrieve all the rows in a GridView and access its cell value. You can modify the logic depending on the type of controls you have added to the GridView<br />
C#<br />
protected void Button1_Click(object sender, EventArgs e)<br />
{<br />
DataSourceSelectArguments dsaArgs = new DataSourceSelectArguments();<br />
DataView view = (DataView)SqlDataSource1.Select(dsaArgs);<br />
DataTable dt = view.ToTable();<br />
for (int i = 0; i &lt; dt.Rows.Count; i++)<br />
{<br />
for (int j = 0; j &lt; dt.Columns.Count; j++)<br />
{<br />
string s = dt.Rows[i][j].ToString();<br />
}<br />
}<br />
}<br />
VB.NET<br />
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)<br />
Dim dsaArgs As DataSourceSelectArguments = New DataSourceSelectArguments()<br />
Dim view As DataView = CType(SqlDataSource1.Select(dsaArgs), DataView)<br />
Dim dt As DataTable = view.ToTable()<br />
For i As Integer = 0 To dt.Rows.Count &#8211; 1<br />
For j As Integer = 0 To dt.Columns.Count &#8211; 1<br />
Dim s As String = dt.Rows(i)(j).ToString()<br />
Next j<br />
Next i<br />
End Sub<br />
Well that was a quick overview of some of the most frequently used features of the GridView control. I hope you liked the article and I thank you for viewing it.</p>
<p>Scrollable GridView with fixed headers in asp.net C# vb.net<br />
Html Source of the page look like this</p>
<div>
<p>&lt;asp:SqlDataSource ID=&#8221;SqlDataSource1&#8243; runat=&#8221;server&#8221;<br />
ConnectionString=&#8221;"<br />
SelectCommand=&#8221;SELECT [ID], [Name], [Location] FROM [Details]&#8220;&gt;</p></div>
<p>Now Add below mention css style in the head section of page</p>
<p>Creating scrollable GridView with fixed headers</p>
<p>.header { font-weight:bold;<br />
position:absolute;<br />
background-color:White;<br />
}</p>
<p>Highlight gridview row on mouse over using javascript in asp.net and C# c-sharp<br />
If you want to highlight rows in Gridview on mouse hover or mouseover event by using client side javascript than you can do it in following way.</p>
<p>For this we need to create a css class and define the color we want to use for highlighting in html source of page.</p>
<p>.normal<br />
{<br />
background-color:white;<br />
}<br />
.highlight<br />
{<br />
background-color:#cccccc;<br />
}</p>
<p>html source of the whole page is like</p>
<p>Untitled Page</p>
<p>.normal<br />
{<br />
background-color:white;<br />
}<br />
.highlight<br />
{<br />
background-color:#cccccc;<br />
}</p>
<p>&lt;asp:SqlDataSource ID=&#8221;SqlDataSource1&#8243; runat=&#8221;server&#8221;<br />
ConnectionString=&#8221;"<br />
SelectCommand=&#8221;SELECT [Name], [City], [Country] FROM [Location]&#8220;&gt;</p>
<p>Now in code behind file we need to add the onmouseover and onmouseout attributes to rows of gridview.</p>
<p>For this we need to use RowCreated event of Gridview<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
if (!IsPostBack)<br />
{<br />
GridView1.DataBind();<br />
}</p>
<p>}<br />
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)<br />
{<br />
if (e.Row.RowType == DataControlRowType.DataRow)<br />
{<br />
e.Row.Attributes.Add(&#8220;onmouseover&#8221;, &#8220;this.className=&#8217;highlight&#8217;&#8221;);<br />
e.Row.Attributes.Add(&#8220;onmouseout&#8221;, &#8220;this.className=&#8217;normal&#8217;&#8221;);<br />
}</p>
<p>}</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/giteshsankhe.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/giteshsankhe.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/giteshsankhe.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/giteshsankhe.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/giteshsankhe.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/giteshsankhe.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/giteshsankhe.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/giteshsankhe.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/giteshsankhe.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/giteshsankhe.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/giteshsankhe.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/giteshsankhe.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/giteshsankhe.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/giteshsankhe.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=giteshsankhe.wordpress.com&amp;blog=8976745&amp;post=7&amp;subd=giteshsankhe&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://giteshsankhe.wordpress.com/2009/08/12/7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3edbd7dbd12b702734dd43ef44655d7f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">giteshsankhe</media:title>
		</media:content>
	</item>
		<item>
		<title>dot net</title>
		<link>http://giteshsankhe.wordpress.com/2009/08/12/hello-world/</link>
		<comments>http://giteshsankhe.wordpress.com/2009/08/12/hello-world/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 11:47:05 +0000</pubDate>
		<dc:creator>giteshsankhe</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[ip of asp.net site http://66.129.67.4/p/1228229/2211122.aspx mms://220.227.208.195/p_star ////////get details in dotnet 2003 from gridview1 public void getdetails()     {         foreach (DataGridItem dg in GridView1.Items)         {             if (((CheckBox)dg.FindControl(&#8220;CheckBox1&#8243;)).Checked == true)             {                 txtinstdt.Text = dg.Cells[3].Text.ToString();                 txtintrgtdt.Text = dg.Cells[4].Text.ToString();                 ViewState["TDATE"] = dg.Cells[4].Text.ToString();                 ddlMil.SelectedIndex = ddlMil.Items.IndexOf(ddlMil.Items.FindByText(dg.Cells[2].Text.ToString()));                 ddproj.Enabled = false;                 ddphase.Enabled [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=giteshsankhe.wordpress.com&amp;blog=8976745&amp;post=1&amp;subd=giteshsankhe&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>ip of asp.net site<br />
<a href="http://66.129.67.4/p/1228229/2211122.aspx">http://66.129.67.4/p/1228229/2211122.aspx</a></p>
<p>mms://220.227.208.195/p_star</p>
<p>////////get details in dotnet 2003 from gridview1</p>
<p>public void getdetails()<br />
    {<br />
        foreach (DataGridItem dg in GridView1.Items)<br />
        {<br />
            if (((CheckBox)dg.FindControl(&#8220;CheckBox1&#8243;)).Checked == true)<br />
            {<br />
                txtinstdt.Text = dg.Cells[3].Text.ToString();<br />
                txtintrgtdt.Text = dg.Cells[4].Text.ToString();<br />
                ViewState["TDATE"] = dg.Cells[4].Text.ToString();<br />
                ddlMil.SelectedIndex = ddlMil.Items.IndexOf(ddlMil.Items.FindByText(dg.Cells[2].Text.ToString()));<br />
                ddproj.Enabled = false;<br />
                ddphase.Enabled = false;<br />
                ddlMil.Enabled = false;<br />
                TD1.Visible = true;<br />
                TD2.Visible = true;<br />
                btnadd.Text = &#8220;Update&#8221;;<br />
            }<br />
        }<br />
    }<br />
////////////////////////////////////<br />
get details in dotnet 2005 from gridview1</p>
<p> public void getdetails()<br />
    {</p>
<p>        foreach (GridViewRow row in gd.Rows)<br />
        {<br />
            if (((CheckBox)row.FindControl(&#8220;CheckBox1&#8243;)).Checked == true)<br />
            {<br />
                    <br />
                txtPerHr.Text = row.Cells[1].Text.ToString();<br />
                txtOnHr.Text = row.Cells[2].Text.ToString();<br />
                txtGapHr.Text = gd.DataKeys[row.RowIndex]["PR_HR_PER_GAP"].ToString(); //hidden fields<br />
                txtTempHr.Text = row.Cells[4].Text.ToString();<br />
                txtOnHrB.Text = row.Cells[5].Text.ToString();<br />
                txtGapHrB.Text = gd.DataKeys[row.RowIndex]["PR_HR_TEMP_GAP"].ToString();<br />
                txtOpsPer.Text = row.Cells[7].Text.ToString();<br />
                txtOpsOnb.Text = row.Cells[8].Text.ToString();<br />
                txtGapOps.Text = gd.DataKeys[row.RowIndex]["PR_OPS_PER_GAP"].ToString();<br />
                txtOPsTemp.Text = row.Cells[10].Text.ToString();<br />
                txtOpsOnbB.Text = row.Cells[11].Text.ToString();<br />
                txtGapOpsB.Text = gd.DataKeys[row.RowIndex]["PR_OPS_TEMP_GAP"].ToString();<br />
                txtHrUti.Text = gd.DataKeys[row.RowIndex]["PR_HR_UTILIZED"].ToString();<br />
                txtPlanPlug.Text = gd.DataKeys[row.RowIndex]["PR_PLANS_PLUG_IN_GAP"].ToString();<br />
//// ddlPrio.SelectedIndex=ddlPrio.Items.IndexOf(ddlPrio.Items.FindByText(row.Cells[15].Text.ToString()));//drop down list<br />
            }<br />
        }<br />
    }</p>
<p> &lt;asp:GridView ID=&#8221;gd&#8221; runat=&#8221;server&#8221; AutoGenerateColumns=&#8221;False&#8221; Height=&#8221;1px&#8221; Width=&#8221;85px&#8221; DataKeyNames=&#8221;PR_HR_PER,PR_HR_PER_ONBOARD,PR_HR_PER_GAP,PR_HR_TEMP,PR_HR_TEMP_ONBOARD,PR_HR_TEMP_GAP,PR_HR_UTILIZED,PR_OPS_PER,PR_OPS_PER_ONBOARD,PR_OPS_PER_GAP,PR_OPS_TEMP,PR_OPS_TEMP_ONBOARD,PR_OPS_TEMP_GAP,PR_PLANS_PLUG_IN_GAP&#8221;&gt;<br />
                                    &lt;Columns&gt;<br />
                                       <br />
                                        &lt;asp:TemplateField&gt;<br />
                                            &lt;ItemTemplate&gt;<br />
                                                &lt;asp:CheckBox ID=&#8221;CheckBox1&#8243; runat=&#8221;server&#8221; /&gt;<br />
                                            &lt;/ItemTemplate&gt;<br />
                                        &lt;/asp:TemplateField&gt;<br />
                                        &lt;asp:BoundField DataField=&#8221;PR_HR_PER&#8221; HeaderText=&#8221;HR Permanent(A)&#8221; SortExpression=&#8221;PR_HR_PER&#8221; /&gt;<br />
                                        &lt;asp:BoundField DataField=&#8221;PR_HR_PER_ONBOARD&#8221; HeaderText=&#8221;HR Onboard(B)&#8221; SortExpression=&#8221;PR_HR_PER_ONBOARD&#8221; /&gt;<br />
                                        &lt;asp:BoundField DataField=&#8221;PR_HR_PER_GAP&#8221; HeaderText=&#8221;HR Gap(A-B)&#8221; SortExpression=&#8221;PR_HR_PER_GAP&#8221; Visible=&#8221;False&#8221;/&gt;  <br />
                                        &lt;asp:BoundField DataField=&#8221;PR_HR_TEMP&#8221; HeaderText=&#8221;HR Temporary(A)&#8221; SortExpression=&#8221;PR_HR_TEMP&#8221; /&gt;<br />
                                        &lt;asp:BoundField DataField=&#8221;PR_HR_TEMP_ONBOARD&#8221; HeaderText=&#8221;HR Temporary Onboard(B)&#8221; SortExpression=&#8221;PR_HR_TEMP_ONBOARD&#8221; /&gt;<br />
                                        &lt;asp:BoundField DataField=&#8221;PR_HR_TEMP_GAP&#8221; HeaderText=&#8221;HR Temporary Gap(A-B)&#8221;  SortExpression=&#8221;PR_HR_TEMP_GAP&#8221; Visible=&#8221;False&#8221; /&gt;<br />
                                        &lt;asp:BoundField DataField=&#8221;PR_OPS_PER&#8221; HeaderText=&#8221;OPS Permanent(A)&#8221; SortExpression=&#8221;PR_OPS_PER&#8221; /&gt;<br />
                                        &lt;asp:BoundField DataField=&#8221;PR_OPS_PER_ONBOARD&#8221; HeaderText=&#8221;OPS Onboard(B)&#8221; SortExpression=&#8221;PR_OPS_PER_ONBOARD&#8221; /&gt;<br />
                                        &lt;asp:BoundField DataField=&#8221;PR_OPS_PER_GAP&#8221; HeaderText=&#8221;OPS Gap(A-B)&#8221; SortExpression=&#8221;PR_OPS_PER_GAP&#8221; Visible=&#8221;False&#8221; /&gt;<br />
                                        &lt;asp:BoundField DataField=&#8221;PR_OPS_TEMP&#8221; HeaderText=&#8221;OPS Temporary(A)&#8221; SortExpression=&#8221;PR_OPS_TEMP&#8221; /&gt;<br />
                                        &lt;asp:BoundField DataField=&#8221;PR_OPS_TEMP_ONBOARD&#8221; HeaderText=&#8221;OPS Temporary Onboard(B)&#8221; SortExpression=&#8221;PR_OPS_TEMP_ONBOARD&#8221; /&gt;<br />
                                        &lt;asp:BoundField DataField=&#8221;PR_OPS_TEMP_GAP&#8221; HeaderText=&#8221;OPS Temporary Gap(A-B)&#8221; SortExpression=&#8221;PR_OPS_TEMP_GAP&#8221; Visible=&#8221;False&#8221; /&gt;<br />
                                        &lt;asp:BoundField DataField=&#8221;PR_HR_UTILIZED&#8221; HeaderText=&#8221;Shared/Exsting HR Utilized&#8221; SortExpression=&#8221;PR_HR_UTILIZED&#8221; Visible=&#8221;False&#8221; /&gt;<br />
                                        &lt;asp:BoundField DataField=&#8221;PR_PLANS_PLUG_IN_GAP&#8221; HeaderText=&#8221;Plans to Plug in Gaps&#8221; SortExpression=&#8221;PR_PLANS_PLUG_IN_GAP&#8221; Visible=&#8221;False&#8221; /&gt;<br />
                                    &lt;/Columns&gt;<br />
                                &lt;/asp:GridView&gt;<br />
                   <br />
function funNumber()<br />
    {<br />
     if (event.keyCode &gt;= 48 &amp;&amp; event.keyCode &lt;= 57)<br />
     {<br />
      return true;<br />
     }<br />
     else if (event.keyCode &gt;= 45 &amp;&amp; event.keyCode &lt;= 46)<br />
     {<br />
     }<br />
     else<br />
     {<br />
      event.returnValue = false;<br />
      return false;<br />
     }<br />
    }<br />
      </p>
<p>//////////// working with gridview in dot net 2005<br />
 public void GridBind()<br />
    {<br />
        if (conn.State.ToString() != &#8220;Open&#8221;)<br />
            conn.Open();<br />
        OracleCommand cmd = new OracleCommand();<br />
        OracleDataAdapter da = new OracleDataAdapter(cmd);<br />
        cmd.CommandText = &#8220;select CM_COMPANY_ID, CM_BUS_COMPANY_NAME, CM_GROUP_NAME, CM_CREATE_DT from COMPANY_MASTER where CM_BUS_COMPANY_NAME like &#8216;%&#8221; + txtCompNmae.Text.ToString() + &#8220;%&#8217; and CM_DELETE_DT is null &#8220;;<br />
        cmd.Connection = conn;<br />
        DataSet ds = new DataSet();<br />
        da.Fill(ds);<br />
        comGriView.DataSource = ds;<br />
        comGriView.DataBind();<br />
        conn.Close();<br />
    }<br />
    protected void comGriView_RowEditing(object sender, GridViewEditEventArgs e)<br />
    {<br />
        comGriView.EditIndex = e.NewEditIndex;<br />
        GridBind();<br />
    }<br />
    protected void comGriView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)<br />
    {<br />
        comGriView.EditIndex =-1;<br />
        GridBind();<br />
    }<br />
    protected void comGriView_RowUpdating(object sender, GridViewUpdateEventArgs e)<br />
    {<br />
        GridViewRow row = (GridViewRow)comGriView.Rows[e.RowIndex];<br />
        string comid = ((Label)row.FindControl(&#8220;lblCM_COMPANY_ID&#8221;)).Text.ToString();<br />
        string comname = ((TextBox)row.FindControl(&#8220;txtCM_BUS_COMPANY_NAME&#8221;)).Text.ToString();<br />
        string comGrname = ((TextBox)row.FindControl(&#8220;txtCM_GROUP_NAME&#8221;)).Text.ToString();<br />
        if (conn.State.ToString() != &#8220;Open&#8221;)<br />
        conn.Open();<br />
        OracleCommand cmd = new OracleCommand();<br />
        cmd.CommandText = &#8220;update COMPANY_MASTER SET CM_BUS_COMPANY_NAME=&#8217;&#8221; + comname + &#8220;&#8216;,CM_GROUP_NAME=&#8217;&#8221; + comGrname + &#8220;&#8216;,CM_CREATE_DT=sysdate WHERE CM_COMPANY_ID=&#8217;&#8221; + comid + &#8220;&#8216;&#8221;;<br />
        cmd.Connection = conn;<br />
        cmd.ExecuteNonQuery();<br />
        conn.Close();<br />
        comGriView.EditIndex = -1;<br />
        GridBind();<br />
    }<br />
    protected void btnCancel_Click(object sender, EventArgs e)<br />
    {<br />
        cancel();<br />
    }<br />
    protected void comGriView_RowDeleting(object sender, GridViewDeleteEventArgs e)<br />
    {<br />
        GridViewRow row = (GridViewRow)comGriView.Rows[e.RowIndex];<br />
        string comid = ((Label)row.FindControl(&#8220;lblCM_COMPANY_ID&#8221;)).Text.ToString();<br />
        if (conn.State.ToString() != &#8220;Open&#8221;)<br />
            conn.Open();<br />
        OracleCommand cmd = new OracleCommand();<br />
        cmd.CommandText = &#8220;update COMPANY_MASTER SET CM_DELETE_DT=SYSDATE WHERE CM_COMPANY_ID=&#8217;&#8221; + comid + &#8220;&#8216;&#8221;;<br />
        cmd.Connection = conn;<br />
        cmd.ExecuteNonQuery();<br />
        conn.Close();<br />
        comGriView.EditIndex = -1;<br />
        GridBind();<br />
    }<br />
}<br />
&lt;asp:GridView ID=&#8221;comGriView&#8221; runat=&#8221;server&#8221; AutoGenerateColumns=&#8221;False&#8221; Height=&#8221;112px&#8221; Width=&#8221;512px&#8221; OnRowCancelingEdit=&#8221;comGriView_RowCancelingEdit&#8221; OnRowEditing=&#8221;comGriView_RowEditing&#8221; OnRowUpdating=&#8221;comGriView_RowUpdating&#8221; CellPadding=&#8221;4&#8243; ForeColor=&#8221;#333333&#8243; GridLines=&#8221;None&#8221; OnRowDeleting=&#8221;comGriView_RowDeleting&#8221;&gt;<br />
            &lt;Columns&gt;<br />
               &lt;asp:TemplateField HeaderText=&#8221;COMPANY ID&#8221;&gt;<br />
              <br />
               &lt;ItemTemplate&gt;<br />
               &lt;asp:Label ID=&#8221;lblCM_COMPANY_ID&#8221; runat=&#8221;server&#8221; Text=&#8217;&lt;%# Eval(&#8220;CM_COMPANY_ID&#8221;) %&gt;&#8217;&gt;&lt;/asp:Label&gt;<br />
               &lt;/ItemTemplate&gt;<br />
              <br />
               &lt;/asp:TemplateField&gt;<br />
              <br />
  &lt;asp:TemplateField HeaderText=&#8221;COMPANY NAME&#8221;&gt;<br />
               &lt;ItemTemplate&gt;<br />
                &lt;asp:Label ID=&#8221;lblCM_BUS_COMPANY_NAME&#8221; runat=&#8221;server&#8221; Text=&#8217;&lt;%# Eval(&#8220;CM_BUS_COMPANY_NAME&#8221;) %&gt;&#8217;&gt;&lt;/asp:Label&gt;<br />
               &lt;/ItemTemplate&gt;<br />
               &lt;EditItemTemplate&gt;<br />
               &lt;asp:TextBox ID=&#8221;txtCM_BUS_COMPANY_NAME&#8221; runat=&#8221;server&#8221; Text=&#8217;&lt;%# Eval(&#8220;CM_BUS_COMPANY_NAME&#8221;) %&gt;&#8217;&gt;&lt;/asp:TextBox&gt;<br />
               &lt;/EditItemTemplate&gt;<br />
               &lt;/asp:TemplateField&gt;</p>
<p>               &lt;asp:TemplateField HeaderText=&#8221;GROUP NAME&#8221;&gt;<br />
               &lt;ItemTemplate&gt;<br />
                &lt;asp:Label ID=&#8221;lblCM_GROUP_NAME&#8221; runat=&#8221;server&#8221; Text=&#8217;&lt;%# Eval(&#8220;CM_GROUP_NAME&#8221;) %&gt;&#8217;&gt;&lt;/asp:Label&gt;<br />
               &lt;/ItemTemplate&gt;<br />
               &lt;EditItemTemplate&gt;<br />
               &lt;asp:TextBox ID=&#8221;txtCM_GROUP_NAME&#8221; runat=&#8221;server&#8221; Text=&#8217;&lt;%# Eval(&#8220;CM_GROUP_NAME&#8221;) %&gt;&#8217;&gt;&lt;/asp:TextBox&gt;<br />
               &lt;/EditItemTemplate&gt;<br />
               &lt;/asp:TemplateField&gt;<br />
               <br />
                &lt;asp:CommandField HeaderText=&#8221;EDIT&#8221; ShowDeleteButton=&#8221;True&#8221; ShowEditButton=&#8221;True&#8221;<br />
                    ShowHeader=&#8221;True&#8221; ShowSelectButton=&#8221;True&#8221; SelectText=&#8221;" /&gt;<br />
               <br />
            &lt;/Columns&gt;<br />
                         &lt;FooterStyle BackColor=&#8221;#5D7B9D&#8221; Font-Bold=&#8221;True&#8221; ForeColor=&#8221;White&#8221; /&gt;<br />
                         &lt;RowStyle BackColor=&#8221;#F7F6F3&#8243; ForeColor=&#8221;#333333&#8243; /&gt;<br />
                         &lt;PagerStyle BackColor=&#8221;#284775&#8243; ForeColor=&#8221;White&#8221; HorizontalAlign=&#8221;Center&#8221; /&gt;<br />
                         &lt;SelectedRowStyle BackColor=&#8221;#E2DED6&#8243; Font-Bold=&#8221;True&#8221; ForeColor=&#8221;#333333&#8243; /&gt;<br />
                         &lt;HeaderStyle BackColor=&#8221;#5D7B9D&#8221; Font-Bold=&#8221;True&#8221; ForeColor=&#8221;White&#8221; /&gt;<br />
                         &lt;EditRowStyle BackColor=&#8221;#999999&#8243; /&gt;<br />
                         &lt;AlternatingRowStyle BackColor=&#8221;White&#8221; ForeColor=&#8221;#284775&#8243; /&gt;<br />
        &lt;/asp:GridView&gt;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
sequence</p>
<p>public void seqExp()<br />
    {<br />
        if (conn.State.ToString() != &#8220;Open&#8221;)<br />
            conn.Open();<br />
        string str = &#8220;select lpad(SEQ_CRITICAL_ISSUE_TRACKING.nextval,5,0) from dual&#8221;;<br />
        OracleCommand cmd = new OracleCommand();<br />
        cmd.Connection = conn;<br />
        cmd.CommandText = str;<br />
        txtid.Text = Convert.ToString(cmd.ExecuteScalar());<br />
        conn.Close();<br />
    }<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
fill ddl</p>
<p>    public void fillddlProj()<br />
    {<br />
        if (conn.State.ToString() != &#8220;Open&#8221;)<br />
            conn.Open();<br />
        string qry = &#8220;SELECT PM_NAME,PM_PROJECT_CD FROM PROJECT_MASTER where exists (select &#8216;x&#8217; from IT_FUNCTION_UNIT_MASTER,USER_IT_MAP where UIM_IT_ID =IT_ID and  IT_ID=PM_IT_FUNC_UNIT and UIM_USER_ID =&#8217;&#8221; + Session["user_id"].ToString() + &#8220;&#8216;)&#8221;;<br />
        OracleDataAdapter adp = new OracleDataAdapter(qry, conn);<br />
        DataSet ds = new DataSet();<br />
        adp.Fill(ds);<br />
        ddlProj.DataSource = ds;<br />
        ddlProj.DataTextField = &#8220;PM_NAME&#8221;;<br />
        ddlProj.DataValueField = &#8220;PM_PROJECT_CD&#8221;;<br />
        ddlProj.DataBind();<br />
        ddlProj.Items.Add(new ListItem(&#8220;Select&#8221;, &#8220;0&#8243;));<br />
        ddlProj.SelectedValue = &#8220;0&#8243;;<br />
        conn.Close();<br />
    }</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
public void createCSV()<br />
    {<br />
        try <br />
 <br />
     {       <br />
        <br />
        //Server.MapPath(&#8220;~/demo.csv&#8221;)<br />
         StreamWriter objSw = new StreamWriter(Server.MapPath(&#8220;~/demo.csv&#8221;),false);<br />
         //get table from grdAllDetails <br />
       <br />
         DataTable objDt = ((DataSet)grdAllDetails.DataSource).Tables[0]; <br />
         //Get No Of Column in GridView       <br />
         int NoOfColumn = objDt.Columns.Count;     <br />
         //Create Header       <br />
         for (int i = 0; i &lt; NoOfColumn; i++)   <br />
         {               objSw.Write(objDt.Columns[i]);        <br />
             //check not last column        <br />
             if (i &lt; NoOfColumn &#8211; 1)    <br />
             {      <br />
                 objSw.Write(&#8220;,&#8221;);     <br />
             }     <br />
         }        <br />
         objSw.Write(objSw.NewLine);  <br />
         //Create Data        <br />
         foreach (DataRow dr in objDt.Rows)<br />
         {             <br />
             for (int i = 0; i &lt; NoOfColumn; i++)      <br />
             {              <br />
                 objSw.Write(dr[i].ToString());  <br />
                 if (i &lt; NoOfColumn &#8211; 1)      <br />
                 {       <br />
                     objSw.Write(&#8220;,&#8221;);  <br />
                 }           <br />
             }           <br />
             objSw.Write(objSw.NewLine);<br />
         }         <br />
         objSw.Close();<br />
        <br />
     }     <br />
     catch (Exception ex)<br />
     {         <br />
         Response.Write(&#8220;Can Not Generate CSV File&#8221;);  <br />
     }   <br />
    }<br />
 private void ExportGridView()</p>
<p>    {</p>
<p>        string attachment = &#8220;attachment; filename=Contacts.xls&#8221;;</p>
<p>        Response.ClearContent();</p>
<p>        Response.AddHeader(&#8220;content-disposition&#8221;, attachment);</p>
<p>        Response.ContentType = &#8220;application/ms-excel&#8221;;</p>
<p>        StringWriter sw = new StringWriter();</p>
<p>        HtmlTextWriter htw = new HtmlTextWriter(sw);</p>
<p>         // Create a form to contain the grid</p>
<p>        HtmlForm frm = new HtmlForm();</p>
<p>        grdAllDetails.Parent.Controls.Add(frm);</p>
<p>        frm.Attributes["runat"] = &#8220;server&#8221;;</p>
<p>        frm.Controls.Add(grdAllDetails);</p>
<p>        frm.RenderControl(htw);</p>
<p>        //grdAllDetails.RenderControl(htw);</p>
<p>        Response.Write(sw.ToString());</p>
<p>        Response.End();</p>
<p>   }</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;insert row for each selected check box in gridview&#8212;&#8212;&#8212;&#8212;<br />
public void fillDetails()<br />
    {<br />
    foreach (GridViewRow row in GVinc.Rows)<br />
    {  <br />
        //if(((CheckBox)row.FindControl(&#8220;chk&#8221;)).Checked==true)<br />
       //CheckBox chk = row.Cells[0].Controls[0] as CheckBox;<br />
       CheckBox chk = row.FindControl(&#8220;Chk&#8221;) as CheckBox;<br />
       if (chk != null &amp;&amp; chk.Checked)<br />
        {<br />
           string str = row.Cells[1].Text;<br />
           lblErrMsg.Text = str;</p>
<p>  code for insert row in database on condition of  str value<br />
        }<br />
       else  <br />
        {<br />
            lblErrMsg.ForeColor = Color.Red;<br />
            lblErrMsg.Text = &#8220;Select atleast one checkBox&#8221;;<br />
        } <br />
    }<br />
    }<br />
      <br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;select one check at time&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>&lt;asp:TemplateField&gt;<br />
&lt;ItemTemplate&gt;<br />
&lt;asp:CheckBox ID=&#8221;Chk&#8221; runat=&#8221;server&#8221; OnClick=&#8221;IsCheckBoxSelected(this)&#8221; /&gt;<br />
&lt;/ItemTemplate&gt;<br />
&lt;/asp:TemplateField&gt;</p>
<p>&lt;asp:Button ID=&#8221;btnView&#8221; runat=&#8221;server&#8221; Font-Bold=&#8221;True&#8221;<br />
Text=&#8221;View  &#8221; OnClick=&#8221;btnView_Click&#8221; OnClientClick=&#8221;IsCheckBoxSelected(this)&#8221; /&gt;</p>
<p>without content place holder</p>
<p>function selectAll(involker) {</p>
<p>        // Since ASP.NET checkboxes are really HTML input elements</p>
<p>        //  let&#8217;s get all the inputs<br />
        var inputElements = document.getElementsByTagName(&#8216;input&#8217;);</p>
<p> </p>
<p>        for (var i = 0 ; i &lt; inputElements.length ; i++) {</p>
<p>            var myElement = inputElements[i];</p>
<p> </p>
<p>            // Filter through the input types looking for checkboxes<br />
            if (myElement.type === &#8220;checkbox&#8221;) {</p>
<p> </p>
<p>               // Use the involker (our calling element) as the reference</p>
<p>               //  for our checkbox status</p>
<p>                myElement.checked = involker.checked;</p>
<p>            }</p>
<p>        }</p>
<p>    } <br />
with content place holder</p>
<p>&lt;asp:Content ID=&#8221;Content1&#8243; ContentPlaceHolderID=&#8221;ContentPlaceHolder1&#8243; Runat=&#8221;Server&#8221;&gt;<br />
&lt;script language=&#8221;javascript&#8221; type=&#8221;text/javascript&#8221; &gt;<br />
function IsCheckBoxSelected(gridview)<br />
{<br />
  if(gridview != null)<br />
    {           <br />
       var chkBoxes =document.getElementById(&#8216;ctl00_ContentPlaceHolder1_GVinc&#8217;).getElementsByTagName(&#8220;input&#8221;);<br />
       var Cnt=0;<br />
        for(i=0; i&lt;chkBoxes.length; i++)<br />
        {<br />
          if(chkBoxes[i].type == &#8220;checkbox&#8221; || chkBoxes[i].type == &#8220;CHECKBOX&#8221;)<br />
          {<br />
           if(chkBoxes[i].checked == true)<br />
           { <br />
              Cnt=Cnt+1;<br />
           }<br />
        }<br />
    }<br />
    if(Cnt==0)<br />
    {<br />
    //document.getElementById(&#8220;txtEditMsg&#8221;).value=&#8217;ERROR : To Edit please select atleast one CHECKBOX.&#8217;;<br />
    alert(&#8220;Atleast one Checkbox needs to be selected!&#8221;);<br />
    return false;<br />
    }<br />
    else if(Cnt&gt;1)<br />
    {<br />
    //document.getElementById(&#8220;txtEditMsg&#8221;).value=&#8217;ERROR : To Edit please select one CHECKBOX at a time.&#8217;;<br />
    alert(&#8220;Please Select One Checkbox At a Time&#8221;);<br />
    return false;<br />
    }<br />
    }<br />
}<br />
&lt;/script&gt;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
&lt;body oncontextmenu=&#8221;return false&#8221; lang=&#8221;EN-US&#8221; onselectstart=&#8221;return false&#8221; ondragstart=&#8221;return false&#8221;</p>
<p>for avoid printing&#8212;- onload=&#8221;setInterval(&amp;quot;window.clipboardData.setData(&#8216;text&#8217;,&#8221;)&amp;quot;,2)&amp;quot;&#8221;&gt;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
find control</p>
<p>(((TextBox)((ctlrating)this.FindControl(&#8220;ctlrating1&#8243;)).FindControl(&#8220;txtcomp3&#8243;)).Text.Trim()==&#8221;"<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
pdf report in 2005</p>
<p>using CrystalDecisions.Shared;<br />
using CrystalDecisions.ReportSource;<br />
using CrystalDecisions.CrystalReports.Engine;</p>
<p>protected void viewreport()<br />
       {<br />
           try<br />
           {<br />
            OracleDataAdapter ad = new OracleDataAdapter(&#8220;SELECT CAF_NO,DN,CPGNO,DCPG,SO_NO,BG_ID FROM CCAFDN where caf_no=&#8217;11010010252340&#8242;&#8221;, conn);<br />
            string FilePath = Server.MapPath(&#8220;CrystalReport.rpt&#8221;);<br />
            dst dst1 = new dst();<br />
            ad.Fill(dst1.Tables["tab"]);<br />
            ReportDocument rDoc = new ReportDocument();<br />
            rDoc.Load(FilePath);<br />
            DataSet dsGrid = new DataSet();<br />
            dsGrid = (DataSet)Session["data"]; //Took the dataset in Session<br />
            rDoc.SetDataSource(dst1.Tables["tab"]);<br />
                 //CrystalReportViewer1.ReportSource = rDoc;<br />
            MemoryStream oStream;<br />
                 //oStream = (MemoryStream)rDoc.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel);<br />
            oStream = (MemoryStream)rDoc.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);<br />
            Response.Clear();<br />
            Response.Buffer = true;<br />
            Response.ContentType = &#8220;application/pdf&#8221;;<br />
                 //Response.ContentType = &#8220;application/.xls&#8221;;<br />
            Response.AddHeader(&#8220;Content-Disposition&#8221;, &#8220;attachment;filename=SearchResult.pdf&#8221;);<br />
                 //Response.AddHeader(&#8220;Content-Disposition&#8221;, &#8220;attachment;filename=SearchResult.xls&#8221;);<br />
            Response.BinaryWrite(oStream.ToArray());<br />
            Response.End();<br />
          }<br />
            catch (Exception ex)<br />
           {<br />
               Response.Write(ex.ToString());<br />
           }</p>
<p>       }</p>
<p>in 2003</p>
<p>private void btn_pdf_Click(object sender, System.EventArgs e)<br />
  {<br />
   CrystalDecisions.Shared.ExportOptions  myexportoption =new CrystalDecisions.Shared.ExportOptions();<br />
   CrystalDecisions.Shared.DiskFileDestinationOptions mydiskfiledestinationoptions =new CrystalDecisions.Shared.DiskFileDestinationOptions();<br />
   string myexportfile;<br />
   ClosureCrystalReport dareport =new ClosureCrystalReport();<br />
   conn.Open();<br />
   if(conn.State.ToString() ==&#8221;Open&#8221;)<br />
   {<br />
    OracleDataAdapter  ad = new OracleDataAdapter(&#8220;&#8221;,conn);<br />
    ad.Fill( diadataset_active1.Tables["ele2"]);<br />
    <br />
    //////////to add table header</p>
<p>    DataTable dtbl=new DataTable();<br />
    dtbl=diadataset_active1.Tables["Basic_Details"];<br />
    DataRow drow;<br />
    drow=dtbl.NewRow();<br />
    drow["title"]=&#8221;CLOSURE REPORT&#8221;;<br />
    dtbl.Rows.Add(drow);</p>
<p>    /////////////////////////</p>
<p>    dareport.SetDataSource(diadataset_active1);<br />
    myexportfile =Server.MapPath(&#8220;abc.pdf&#8221;);<br />
    mydiskfiledestinationoptions = new CrystalDecisions.Shared.DiskFileDestinationOptions();<br />
    mydiskfiledestinationoptions.DiskFileName = myexportfile;<br />
    myexportoption = dareport.ExportOptions;<br />
    myexportoption.DestinationOptions=mydiskfiledestinationoptions;<br />
    myexportoption.ExportDestinationType = ExportDestinationType.DiskFile;<br />
    myexportoption.ExportFormatType =ExportFormatType.PortableDocFormat;<br />
   {<br />
    dareport.Export();<br />
    Response.ClearContent();<br />
    Response.ClearHeaders();<br />
    Response.ContentType = &#8220;application/pdf&#8221;;<br />
    Response.WriteFile(myexportfile);<br />
    Response.Flush();<br />
    Response.Close();<br />
   }<br />
   }<br />
  }<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
mail with image</p>
<p>1&gt; protected void Button1_Click(object sender, EventArgs e)<br />
    {<br />
        string strMailContent = &#8220;Welcome new user&#8221;;<br />
        string fromAddress = &#8220;<a href="mailto:eBSSPortal@relianceada.com">eBSSPortal@relianceada.com</a>&#8220;;<br />
        string toAddress = &#8220;<a href="mailto:amol.a.mhatre@relianceada.com">amol.a.mhatre@relianceada.com</a>&#8220;;<br />
        string contentId = &#8220;image1&#8243;;<br />
        string path = Server.MapPath(@&#8221;images/Logo.jpg&#8221;); // my logo is placed in images folder<br />
        MailMessage mailMessage = new MailMessage(fromAddress, toAddress);<br />
        mailMessage.Bcc.Add(&#8220;<a href="mailto:prakhaya.narayana@relianceada.com">prakhaya.narayana@relianceada.com</a>&#8220;); // put your id here<br />
        mailMessage.Subject = &#8220;Mail with Image&#8221;;<br />
       <br />
        LinkedResource logo = new LinkedResource(path);<br />
        logo.ContentId = &#8220;companylogo&#8221;;<br />
        // done HTML formatting in the next line to display my logo<br />
        AlternateView av1 = AlternateView.CreateAlternateViewFromString(&#8220;&lt;html&gt;&lt;body&gt;&lt;img src=&#8217;http:\\10.8.116.248\\les1.jpg&#8217;/&gt;&lt;br&gt;&lt;/body&gt;&lt;/html&gt;&#8221; + strMailContent, null);<br />
        av1.LinkedResources.Add(logo);<br />
        mailMessage.AlternateViews.Add(av1);<br />
        mailMessage.IsBodyHtml = true;<br />
        SmtpClient mailSender = new SmtpClient(&#8220;10.8.54.12&#8243;); //use this if you are in the development server<br />
        mailSender.Send(mailMessage);<br />
    }</p>
<p>2&gt;<br />
public class ClassMail<br />
{<br />
    public static Boolean Mail(string From, string Receiver, string Subject, string Body, string CC_mail,string BCC ) //string Attach)<br />
    {<br />
        bool Mailflag;<br />
        MailMessage objMail = new MailMessage();<br />
        objMail.From = new MailAddress(From);<br />
        //objMail.To.Add(new MailAddress(Receiver));<br />
        objMail.To.Add(Receiver);<br />
        if (CC_mail.Trim() != &#8220;&#8221;)<br />
        {<br />
           // objMail.CC.Add(new MailAddress(CC_mail));<br />
            objMail.CC.Add(CC_mail);<br />
        }<br />
        if (BCC.Trim() != &#8220;&#8221;)<br />
        {<br />
            objMail.Bcc.Add(BCC);<br />
        }<br />
        objMail.Subject = Subject;<br />
        objMail.IsBodyHtml = true;<br />
        objMail.Body = Body;<br />
        objMail.Priority = MailPriority.Normal;<br />
        SmtpClient ObjSend = new SmtpClient(&#8220;10.8.54.12&#8243;);<br />
        //if (Attach.Trim() != &#8220;&#8221;)<br />
        //{<br />
        //    objMail.Attachments.Add(new Attachment(Attach));<br />
        //}<br />
        try<br />
        {<br />
            ObjSend.Send(objMail);<br />
            Mailflag = true;<br />
            return Mailflag;<br />
        }</p>
<p>        catch (Exception ex)<br />
        {<br />
            string str;<br />
            str = ex.Message;<br />
            Mailflag = false;<br />
            return Mailflag;<br />
        }<br />
    }<br />
}<br />
//////////////////////////////////<br />
Place the following JavaScript redirect code between the &lt;HEAD&gt; and &lt;/HEAD&gt; tags of your HTML code.</p>
<p>This example is setup to redirect to another page in 2 seconds. When a page contains this JavaScript, it will be redirected to another page that you specify in the &#8220;window.location=&#8221;. You can change the number of refresh seconds by changing the &#8220;move()&#8217;,2000 to the number of seconds you&#8217;d like.</p>
<p>Example:</p>
<p>1000 = 1 second<br />
3000 = 3 seconds</p>
<p>Place this code between the &lt;head&gt; and &lt;/head&gt; tags &lt;script language=&#8221;JavaScript&#8221;&gt;<br />
&lt;!&#8211;Script courtesy of <a href="http://www.web-source.net">http://www.web-source.net</a> &#8211; Your Guide to Professional Web Site Design and Development<br />
var time = null<br />
function move() {<br />
window.location = &#8216;http://www.yourdomain.com&#8217;<br />
}<br />
//&#8211;&gt;<br />
&lt;/script&gt;</p>
<p> </p>
<p>Place this code in your &lt;body&gt; tag &lt;body onload=&#8221;timer=setTimeout(&#8216;move()&#8217;,2000)&#8221;&gt;</p>
<p>/////////////////////////////////////////////////////</p>
<p> string str2;<br />
                str2 = &#8220;&lt;script language=&#8217;javascript&#8217;&gt;window.open(&#8216;Question1stpage.aspx&#8217;,&#8221;,config=&#8217;fullscreen=yes, top=0, left=0 toolbar=no, scrollbars=yes,location=no resizable=no,status=no&#8217;);window.close();&lt;/script&gt;&#8221;;<br />
                Page.RegisterStartupScript(&#8220;new&#8221;, str2);<br />
window.open(&#8220;Excel_Like_GridView_Demo.aspx&#8221;,&#8221;DemoWindow&#8221;,&#8221;status=0, toolbar=0, width=1024, height=768, scrollbars=1, resizable=0&#8243;).focus();</p>
<p>/////////////////////////////////////////////////////////////////////////////////////////<br />
How to: Wrap the data of a Particular Column in GridView<br />
One of the member at the <a href="http://forums.asp.net">http://forums.asp.net</a> ask if how to wrap the data in the GridView Control. See this thread (<a href="http://forums.asp.net/t/1417574.aspx">http://forums.asp.net/t/1417574.aspx</a>). I decided to post the solution that I was provided in that thread as a reference for all who needs a solution for the same issue.</p>
<p> <br />
Here’s the code block below:</p>
<p> <br />
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)<br />
    {<br />
        if (e.Row.RowType == DataControlRowType.DataRow)<br />
        {<br />
            e.Row.Cells[0].Attributes.Add(&#8220;style&#8221;, &#8220;word-break:break-all;word-wrap:break-word&#8221;);<br />
        }<br />
    }<br />
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)<br />
    {<br />
        //just changed the index of columns and the value of Unit based on your requirements<br />
        this.GridView1.Columns[0].ItemStyle.Width = new Unit(100);<br />
    }<br />
 </p>
<p> <br />
As you can see, we just add an attribute to a particular column in the GridView and set the style “word-break:break-all;word-wrap:break-word&#8221;” and at RowCreated event of GridView we set the Width of the column that we need to wrap.</p>
<p> <br />
That’s it! Hope you will find this post useful!<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>Back button asp dot net<br />
&lt;INPUT type=&#8221;button&#8221; id=&#8221;btnback&#8221; name=&#8221;btnback&#8221; onclick=&#8221;javascript:history.go(-1);&#8221; value=&#8221;Back&#8221; align=&#8221;middle&#8221;&gt;</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
C# .NET &#8211; Printing only specific part of page<br />
Shreya Trivedi replied to Pragya Jaiswal at 12-Jun-08 05:31<br />
 create a css as follows in javascript:</p>
<p>&lt;STYLE type=&#8221;text/css&#8221; media=&#8221;print&#8221;&gt;<br />
   .hidePrint {     visibility:hidden;   display:none;}<br />
 &lt;/STYLE&gt;<br />
then apply that css class to the elements you want to hide.<br />
 <br />
PRINT PAGE</p>
<p>&lt;input type=&#8221;button&#8221; value=&#8221;Print&#8221; onclick=&#8221;window.print();&#8221;&gt;</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>btnsave.Attributes.Add(&#8220;Onclick&#8221;, &#8220;return validate(txtemail)&#8221;);<br />
           <br />
btnEdit.Attributes.Add(&#8220;Onclick&#8221;, &#8221; return IsCheckBoxSelected(gridview)&#8221;);</p>
<p>FileUpload1.Attributes.Add(&#8220;onkeypress&#8221;, &#8220;return false&#8221;);</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/giteshsankhe.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/giteshsankhe.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/giteshsankhe.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/giteshsankhe.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/giteshsankhe.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/giteshsankhe.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/giteshsankhe.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/giteshsankhe.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/giteshsankhe.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/giteshsankhe.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/giteshsankhe.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/giteshsankhe.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/giteshsankhe.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/giteshsankhe.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=giteshsankhe.wordpress.com&amp;blog=8976745&amp;post=1&amp;subd=giteshsankhe&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://giteshsankhe.wordpress.com/2009/08/12/hello-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3edbd7dbd12b702734dd43ef44655d7f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">giteshsankhe</media:title>
		</media:content>
	</item>
	</channel>
</rss>
