How do I insert custom @ Register tags into the aspx file from my custom control

In the custom control’s custom designer’s Initialize override, do something like this: [C#] public override void Initialize(IComponent component) { base.Initialize (component); IDesignerHost host = component.Site.Container as IDesignerHost; IDesigner designer = host.GetDesigner(host.RootComponent); // Calling GetHTMLFromWebControlTool with the following custom toolboxitem will insert the // Register directives for the type associated with that . MethodInfo mi = designer.GetType.GetMethod(‘GetHTMLFromWebControlTool’, BindingFlags.NonPublic | BindingFlags.Instance); if(mi != null) { // DependantType is a custom type defined in DependantAssembly.dll mi.Invoke(designer, new object[]{new WebControlToolboxItem(typeof(SomeNamespace.DependantType))}); } } Then when the user drags and drops the item from the toolbox, besides the default @ register entry it makes, it will also make an entry like this: <%@ Register TagPrefix=’cc1′ Namespace=’SomeNamespace’ Assembly=’DependantAssembly, Version=2.0.0.1, Culture=neutral, PublicKeyToken=3d6dfsd1fdsd44c89′ %> The assembly will not be strong named in the above tag if it’s not in the GAC.

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’; } }