Why do I get ‘Could not lock file’ and ‘cannot open file’ exceptions when bound to a mdb file?

You could get this error for the following reasons: When you create a project afresh, add a new OleDbDataAdapter to the form and link to the mdb file, the connection object created in the process will keep an open connection to the mdb file which is what will cause the above ‘Could not lock file’ exception during runtime. To workaround this, go to ‘Server Explorer’ in your IDE, right click on the corresponding ‘Connection entry’ and select Close Connection. This should fix the problem. The ‘cannot open file’ exception could then occur if you have not provided enough permissions on the mdb file to allow the .net runtime to lock it. To ensure enough permissions, open it’s properties, select the Security tab and add a ‘Everyone’ account granting ‘Full Control’ to it. This should let the .net runtime lock the file.

How to get the count of rows in a Excel file

Add reference -> COM tab ->Microsoft Excel 11.0 Object Library <asp:Label id=’Label1′ runat=’server’></asp:Label> VB.NET Dim excelApp As New Microsoft.Office.Interop.Excel.Application excelApp.Workbooks.Open(Server.MapPath(‘excel1.xls’)) Label1.Text = excelApp.ActiveSheet.Usedrange.count.ToString excelApp.Workbooks.Close() C# Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application(); excelApp.Workbooks.Open ( Server.MapPath (‘excel1.xls’), Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing ); Microsoft.Office.Interop.Excel.Worksheet wks; wks =(Microsoft.Office.Interop.Excel.Worksheet)excelApp.ActiveSheet; Label1.Text =wks.UsedRange.Count.ToString(); excelApp.Workbooks.Close();

How to change the HeaderText of the Datagrid

Method 1 : Set the HeaderText Property of the BoundColumn/TemplateColumn <asp:DataGrid id=’DataGrid1′ AutoGenerateColumns=’False’ runat=’server’> <Columns> <asp:BoundColumn DataField=’EmployeeID’ HeaderText=’Employee ID’> </asp:BoundColumn> <asp:BoundColumn DataField=’FirstName’ HeaderText=’First Name’> </asp:BoundColumn> <asp:TemplateColumn HeaderText=’LastName’> <ItemTemplate> <#%DataBinder.Eval(Container.DataItem, ‘LastName’).ToString()%> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:DataGrid> Method 2 : Dynamically change the HeaderText in the ItemDataBound Event of the DataGrid <asp:DataGrid id=’DataGrid1′ OnItemDataBound=’ItemDB’ runat=’server’></asp:DataGrid> VB.NET Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ’Populate the DataGrid End Sub protected Sub ItemDB(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) If e.Item.ItemType = ListItemType.Header Then e.Item.Cells(0).Text = ‘Employee ID’ e.Item.Cells(1).Text = ‘First Name’ e.Item.Cells(2).Text = ‘Last Name’ End If End Sub C# private void Page_Load(object sender, System.EventArgs e) { //Populate the DataGrid } protected void ItemDB(Object sender ,System.Web.UI.WebControls.DataGridItemEventArgs e ) { if (e.Item.ItemType == ListItemType.Header) { e.Item.Cells[0].Text = ‘Employee ID’; e.Item.Cells[1].Text = ‘First Name’; e.Item.Cells[2].Text = ‘Last Name’; } }

Why does my page show up poorly in Mozilla based browsers like Netscape and Firefox?

The .Net framework recognizes the capabilities of the latest version of the above browsers poorly. This is because, by default, the BrowserCaps section of the machine.config file (usually found under a folder like ‘C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\CONFIG’) declares the capabilities of the Mozilla based browser poorly. So, you will have to replace the default entry in your install with this one: Mozilla BrowserCaps. In case the above link didn’t work, this is the content from the above link, captured as of (4/10/2005): <browserCaps> <!– Name: BrowserCaps update for modern browsers, http://slingfive.com/pages/code/browserCaps/ Author: Rob Eberhardt, http://slingfive.com/ History: 2004-11-19 improved detection of Safari, Konqueror & Mozilla variants, added Opera detection 2003-12-21 updated TagWriter info 2003-12-03 first published –> <!– GECKO Based Browsers (Netscape 6+, Mozilla/Firefox, …) //–> <case match=’^Mozilla/5\.0 \([^)]*\) (Gecko/[-\d]+)(?’VendorProductToken’ (?’type’[^/\d]*)([\d]*)/(?’version’(?’major’\d+)(?’minor’\.\d+)(?’letters’\w*)))?’> browser=Gecko <filter> <case match='(Gecko/[-\d]+)(?’VendorProductToken’ (?’type’[^/\d]*)([\d]*)/(?’version’(?’major’\d+)(?’minor’\.\d+)(?’letters’\w*)))’> type=${type} </case> <case> type=Mozilla </case> </filter> frames=true tables=true cookies=true javascript=true javaapplets=true ecmascriptversion=1.5 w3cdomversion=1.0 css1=true css2=true xml=true tagwriter=System.Web.UI.HtmlTextWriter <case match=’rv:(?’version’(?’major’\d+)(?’minor’\.\d+)(?’letters’\w*))’> version=${version} majorversion=0${major} minorversion=0${minor} <case match=’^b’ with=’${letters}’> beta=true </case> </case> </case> <!– AppleWebKit Based Browsers (Safari…) //–> <case match=’AppleWebKit/(?’version’(?’major’\d?)(?’minor’\d{2})(?’letters’\w*)?)’> browser=AppleWebKit version=${version} majorversion=0${major} minorversion=0.${minor} frames=true tables=true cookies=true javascript=true javaapplets=true ecmascriptversion=1.5 w3cdomversion=1.0 css1=true css2=true xml=true tagwriter=System.Web.UI.HtmlTextWriter <case match=’AppleWebKit/(?’version’(?’major’\d)(?’minor’\d+)(?’letters’\w*))(.* )?(?’type’[^/\d]*)/.*( |$)’> type=${type} </case> </case> <!– Konqueror //–> <case match=’.+[K|k]onqueror/(?’version’(?’major’\d+)(?’minor’(\.[\d])*)(?’letters’[^;]*));\s+(?’platform’[^;\)]*)(;|\))’> browser=Konqueror version=${version} majorversion=0${major} minorversion=0${minor} platform=${platform} type=Konqueror frames=true tables=true cookies=true javascript=true javaapplets=true ecmascriptversion=1.5 w3cdomversion=1.0 css1=true css2=true xml=true tagwriter=System.Web.UI.HtmlTextWriter </case> <!– Opera //–> <case match=’Opera[ /](?’version’(?’major’\d+)(?’minor’\.(?’minorint’\d+))(?’letters’\w*))’> <filter match='[7-9]’ with=’${major}’> tagwriter=System.Web.UI.HtmlTextWriter </filter> <filter> <case match=’7′ with=’${major}’> <filter> <case match='[5-9]’ with=’${minorint}’> ecmascriptversion=1.5 </case> <case> ecmascriptversion=1.4 </case> </filter> </case> <case match='[8-9]’ with=’${major}’> ecmascriptversion=1.5 </case> </filter> </case> </browserCaps>

How to validate a CheckBox

<asp:CheckBox runat=’server’ id=’chkbox’></asp:CheckBox> <asp:CustomValidator runat=’server’ ErrorMessage=’Error!’ OnServerValidate=’ServerValidation’ ClientValidationFunction=’ClientValidation’ ID=’Customvalidator1′ /> <asp:Button runat=’server’ text=’submit’ ID=’Button1′ /> <script language=’javascript’> function ClientValidation(source, args) { args.IsValid = document.all[‘chkbox’].checked; } </script> VB.NET <script runat=’server’ language=’vb’> sub ServerValidation( source as object, args as ServerValidateEventArgs ) args.IsValid = chkbox.Checked end sub </script> C# <script runat=’server’ language=’cs’> void ServerValidation(object source, ServerValidateEventArgs args) { args.IsValid = chkbox.Checked; } </script>