Subscribe:

Pages

Monday, September 12, 2011

Working with GridView in Code Behind

1. I add GridView into my .aspx page. My database table consist with four columns(Id, FirstName, LastName, DateCreated)

2. Bind your Grid
    
   In this example I used Microsoft Enterprise Library. For further details you can access my previous post, Working with SqlServer using Microsoft Enterprise Library

3. You can add data while binding data in your grid. In this example I add a java script function to each row.     

4. Allow to change your page index. 
   

5. I add two command field (Edit & Delete) into the Grid. You can add any command fields into the Grid. 


6. Allow to delete row data
   

Friday, September 9, 2011

Working with Java Script in code behind

There are two ways to add a java script function in to a Controller. But those behaviors are different to each other.
1. Run in ScriptManager   
          This is the best way to implement the java_script into code behind of asp.net. This can run when we want functionality.
 
2. Add attributes
            This is not a perfect way. When we add to button, which trigger, after the button click. That mean is you must click twice that button and you can't change that functionality in direct.
      

Friday, September 2, 2011

Access the Parent class controlers thruogh the User Controles

I had a problem when I used User Controller in my first time. Problem was how to access the parent class items through the User Controller. Our project Tech Lead, Nalaka ayya gave me a good solution to it. Solution was access the controls through the interface. In this post I tried to share that solution with you.  

1. Create the interface
             

2. Create the User Controller (WebUserControl). In user controller I add two button field, those button used to change the  visibility of label in Default.aspx class
             

Button commands call to DoJob method.
           

This DoJob method call to the Interface and pass the value
            

3. I used User Controller (WebUserControl) in Default.aspx page       
          

In Default.aspx code behind class I implement the Interface (IControler)

4. According to the command this can control the visibility of the lable (lblName)
         

I create Code class and add Enum (Commands) to save to constant value.(Optional)