August 19, 2012

ASP.Net Tips-Create object for delegate ,Paste data using code,Delete lines in dataTable

 namespace Akadia.BasicDelegate  
 // Declaration  
 public delegate void SimpleDelegate();  
 class TestDelegate  
 public static void MyFunc()  
 Console.WriteLine("I was called by delegate ...");  
 public static void Main()  
 // Instantiation  
 SimpleDelegate simpleDelegate = new SimpleDelegate(MyFunc);  
 // Invocation  
 simpleDelegate(); it's the object of delegate.  
 objectname.Eventname += new objectname.delegatename(functionname());  
in this we are calling events by creating an object of that particular class providing events but when we attaching delegates we are not using the object name or we cannot use object name, instead we are using class name of that particular delegate provided .

Delegate is neither meant to do any action nor to persist a value. so there is no need to access the delegate by an object. And we can even declare the delegate outside of the class. There is no significant in declaring the delegate inside the class.

 Class object = new objectOfClass();  
 where objectOfClassName is object of Class.  
 objectname.Eventname += new Classneme.delegatename(functionname());  
Delete lines in dataTable using

 public DataTable deleteLine(DataTable dtLines, int RowIndex, String Column)  
       for (int j = RowIndex; j < dtLines.Rows.Count; j++)  
         dtLines.Rows[j][Column] = (j + 1) * 10;  
       return dtLines;  
Paste data using code in
This is a simple code to Paste data using language. Here textbox control is in a form you can get data from textbox then you can execute past command using execCommand.
 PastedText = document.Form1.txtArea.createTextRange();  

Function to Get value of Data table using query in

 Public Function GetTable(ByVal str As String) As DataTable  
 Dim dt As New DataTable  
 Dim cmd As New SqlCommand(str, objCn.openDb())  
 Dim adp As New SqlDataAdapter(cmd)  
 Return dt  
 Catch ex As Exception  
 MsgBox("Error" + ex.Message)  
 Return Nothing  
 End Try  
 End Function