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> <!-- plain Mozilla if no VendorProductToken found --> 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>

Which control should I use when binding a multidimensional array

Use a DataList as follows. .aspx <asp:datalist id='DataList1' runat='server'> <ItemTemplate> <asp:repeater datasource='<%#Container.DataItem%>' runat=server ID='Repeater1' > <ItemTemplate> <%# Container.DataItem %> </ItemTemplate> </asp:repeater> </ItemTemplate> </asp:datalist> VB.NET Private Sub Page_Load(sender As Object, e As System.EventArgs) ’ Put user code to initialize the page here ’ Create and populate a multi-dimensional array Dim MyArray(4) As Integer() Dim i As Integer For i = 0 To 3 MyArray(i) = New Integer(5) {} Dim x As Integer For x = 0 To 4 MyArray(i)(x) = x + 5 * i Next Next DataList1.DataSource = MyArray DataList1.DataBind() End Sub ’Page_Load C# private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here // Create and populate a multi-dimensional array int [][] MyArray = new int[4][]; for (int i=0; i<4; i++) { MyArray[i] = new int[5]; for (int x=0; x<5; x++) { MyArray[i][x] = x+(5*i); } } DataList1.DataSource = MyArray; DataList1.DataBind(); }