Search This Blog

Thursday, September 29, 2011

How to use GridViewDataRow with html contents.

If datasource(datatable) has html contents and bind this datasource to the gridview.
The GridView will show the data as it is in datatable.It means it will show the html content as it is.
For Example:
Your DataTable has html content "<Strong>Testing</Strong>" but gridview display same "<Strong>Testing</Strong>" instead of "Testing".

Solution:

Add the following code into gridView's Rowdatabound event.

protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
foreach (TableCell cell in e.Row.Cells)
{
cell.Text = Server.HtmlDecode(cell.Text);
}
}

Tuesday, September 27, 2011

How to swap column value of a sql table.

Create Table tmp (A varchar(10),B VARCHAR(10))


insert into tmp values('a','1')
insert into tmp values('b','2')
insert into tmp values('v','3')

Select * from tmp

output
A B
a 1
b 2
v 3

Update #tmp Set A=B, B=A

Select * from tmp
swapped output
A B
1 a
2 b
3 v

Sunday, September 25, 2011

Handler "PageHandlerFactory-Integrated" has a bad module "ManagedPipelineHandler" in its module list

This error comes when you are trying to access iis7.0 or upgraded and iis is not register for asp.net.
Solution:Register IIS with ASPNET4.0 as follows......

c:\windows\microsoft.net\framework\v4.0.30319>aspnet_regiis -i

Friday, August 19, 2011

External table is not in the expected format.

"External table is not in the expected format." typically occurs when trying to use an Excel 2007 file with a connection string that uses: Microsoft.Jet.OLEDB.4.0 and Extended Properties=Excel 8.0

Using the following connection string seems to fix most problems.

public static string path = @"C:\src\RedirectApplication\RedirectApplication\301s.xlsx";
public static string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;HDR=Yes;IMEX=1;";

Print Using Javascript.

function tablePrint(tblId)
{

var display_setting="toolbar=yes,location=no,directories=yes,menubar=yes,";
display_setting+="scrollbars=yes,width=750, height=600, left=100, top=25";
var lbtnPrint = document.getElementById('ctl00_CPHVmanage_FvVendorBillEntry_lbtnPrint');
lbtnPrint.style.display = 'none';
var content_innerhtml = document.getElementById(tblId).innerHTML;
var document_print = window.open("","",display_setting);
//document_print.document.open();
document_print.document.write('<html><head><title>Vendor Bill </title></head>');
document_print.document.write('<body onLoad="self.print();self.close();" >');
document_print.document.write(content_innerhtml);
document_print.document.write('</body> //document_print.print();
document_print.document.close();
lbtnPrint.style.display = 'block';
return false;
}

HTML:
<table id="tbl_display" style="text-align:left;" width="100%" cellpadding="2" cellspacing="2" border="0">
<tr>
<td align="left">
<p> Thank you valuable user for signing up.</p>
<p> We think you’ve made a bold decision, and look forward to a productive meeting.</p>
<p> Please print out a copy of this invitation - it will serve as your boarding pass on this tour. </p>
<p> For additional information, you can email <a href="mailto:someone@someone.com">someone@someone.com</a> or call -
xxx-xxx-xxxx, xxx-xxx-xxx and look for Mr. Someone.</p>
</td>
</tr>
</table>

<input type="ctl00_CPHVmanage_FvVendorBillEntry_lbtnPrint" value="Print" onclick="tablePrint('tbl_display');">

Friday, August 12, 2011

Keyword 'this' is not valid in a static property, static method, or static field initialize.

'this' object is not a static property, static method, or static field initialize , so it can not be used to call a static method.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ArnoldBaseModule
{
public class Message
{
public static string GetMessage(int ModuleId, int UserId, int AppId, int ConAppId, bool Successed, int indicator)
{
if (Successed)
{
this.GenerateMessage(ModuleId, UserId, AppId, ConAppId, Successed, indicator);
//Use below line without 'this' to call a methos instead of above............
GenerateMessage(ModuleId, UserId, AppId, ConAppId, Successed, indicator);
}
return "";
}
private static string GenerateMessage(int ModuleId, int UserId, int AppId, int ConAppId, bool Successed, int indicator)
{
return "";
}
}
}

SqlConnection.ConnectionTimeout Property.

Gets the time to wait while trying to establish a connection before terminating the attempt and generating an error.

Namespace: System.Data.SqlClient
Assembly: System.Data (in System.Data.dll)
Type: System.Int32
The time (in seconds) to wait for a connection to open. The default value is 15 seconds.