Tuesday, April 16, 2013

How to bind drop down with grid-view in MVC3


  

   @grid.GetHtml(
      tableStyle: "grid",
 
       columns: grid.Columns(
                grid.Column("Name"),
                          grid.Column("Address"),                                 grid.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { id = item.Value.ID })),                                        grid.Column(format: (item) => Html.ActionLink("Delete", "Delete", new { id = item.Value.ID })),                                 grid.Column("Class")                               
       )
    )
 



 public class HomeController : Controller

    {

        entityFrameworkDataEntities obj = new entityFrameworkDataEntities();

        public ActionResult Index()

        {



            var Result = from C in obj.TblDetails

                        select C;

            ViewBag.webgriddata = Result.ToList();

            List abc = new List(2);

            var q = from a in obj.TblDepts

                    select a;

            foreach (var i in q)

            {

                abc.Add(i.Dept);

            }

            ViewBag.Names = abc;

            return View(q);

           

        }


        public ActionResult About(string  val)

        {

         

            return View();

        }

        public ActionResult CategoryDetails(string Id)      

{        

            int id = (from d in obj.TblDepts

                     where d.Dept == Id

                     select d.Id).FirstOrDefault();


            var Result = from C in obj.TblDetails

                         where C.DeptID == id

                         select C;

            ViewBag.webgriddata = Result.ToList();


         

            List abc = new List(2);

            var q = from a in obj.TblDepts

                    select a;

            foreach (var i in q)

            {

                abc.Add(i.Dept);

            }

            ViewBag.Names = abc;

           

            return View("Index");


        }

        public ActionResult Edit(int id)

        {

            TblDetail obj2 = new TblDetail();

          var dd = getdata(id);


          obj2.Address = dd.Address;

               obj2.Class= dd.Class;

               obj2.Name = dd.Name;

               obj2.DeptID = dd.DeptID;


          

           return View(obj2);

        }

        [HttpPost]

        public ActionResult edit(TblDetail model)

        {

            TblDetail obj2 = new TblDetail();

            obj2.ID = model.ID;

            obj2.Address = model.Address;

            obj2.Class = model.Class;

            obj2.Name = model.Name;

            obj2.DeptID = model.DeptID;

            obj.TblDetails.Attach(obj2);

            obj.ObjectStateManager.ChangeObjectState(obj2, System.Data.EntityState.Modified);

            obj.SaveChanges();

             return RedirectToAction("index");

        }


        public TblDetail getdata(int id)

        {

            entityFrameworkDataEntities obj = new entityFrameworkDataEntities();

            var dd = from e in obj.TblDetails

                     where e.ID == id

                     select e;


            return dd.FirstOrDefault();

        }

        public ActionResult Delete(int id)

        {

            TblDetail obj2 = new TblDetail();


            TblDetail Product = (from c in obj.TblDetails

                                          where c.ID == id

                                          select c).FirstOrDefault();


            obj.TblDetails.DeleteObject(Product);

            obj.SaveChanges();



            return RedirectToAction("index");

        }

    }

}

Sunday, October 28, 2012

What is a Delegate?

Delegate is a type which  holds the method(s) reference in an object. It is also referred to as a type safe function pointer.





Declaration


public delegate double Delegate_Prod(int a,int b);
class Class1
{
    static double fn_Prodvalues(int val1,int val2)
    {
        return val1*val2;
    }
    static void Main(string[] args)
    {
        //Creating the Delegate Instance
        Delegate_Prod delObj = new Delegate_Prod(fn_Prodvalues);
        Console.Write("Please Enter Values");
        int v1 = Int32.Parse(Console.ReadLine());
        int v2 = Int32.Parse(Console.ReadLine());
        //use a delegate for processing
        double res = delObj(v1,v2);
        Console.WriteLine ("Result :"+res);
        Console.ReadLine();
    }
}

Explanation

Here I have used a small program which demonstrates the use of delegate.
The delegate "Delegate_Prod" is declared with double return type and accepts only two integer parameters.
Inside the class, the method named fn_Prodvalues is defined with double return type and two integer parameters. (The delegate and method have the same signature and parameter type.)
Inside the Main method, the delegate instance is created and the function name is passed to the delegate instance as follows:
Delegate_Prod delObj = new Delegate_Prod(fn_Prodvalues);
After this, we are accepting the two values from the user and passing those values to the delegate as we do using method:
delObj(v1,v2);
Here delegate object encapsulates the method functionalities and returns the result as we specified in the method.

Friday, July 20, 2012

How To call Mvc Function With Json



    $(document).ready(function () {
        $("#ddlModelSeries").change(function () {

            var Mname = $(this).val();

            $.getJSON("AddModelSeries/LoadBrand", { id: Mname }, function (AreaData) {
                var select = $("#ddlBrand"); select.empty(); select.append($('
                $.each(AreaData, function (index, itemData) {

                    select.append($('
                        value: itemData.Value,
                        text: itemData.Text
                    }));
                });

            });

        });


    });

             



how to hide menu in mvc 3 on master page





@if(Session["username"] !=null)
    {
 

 
     
 @Html.ActionLink("Manange Step", "Index", "Adminmanage")
 &nbsp 
@Html.ActionLink("Manange Errorcode", "Index", "Admin")&nbsp&nbsp

 @Html.ActionLink("LogOut", "LogOn", "Account")&nbsp&nbsp
     

        }

how pass value from page to javascript with hidden varible


@model UFixnow.Models.ModelSeries
@{
    ViewBag.Title = "Index";
   Layout = "~/Views/Shared/_Adminlayout.cshtml";
    var id = Session["SeriesId1"];
}





Tuesday, July 10, 2012

oops Concepts



 Abstraction

The process of picking out (abstracting) common features of objects and procedures. A programmer would use abstraction, for example, to note that two functions perform almost the same task and can be combined into a single function. Abstraction is one of the most important techniques in software engineering and is closely related to two other important techniques -- encapsulation and information hiding. All three techniques are used to reduce complexity.



Difference between Struct and Class

Struct are Value type and are stored on stack, while Class are Reference type and are stored on heap.
Struct “do not support” inheritance, while class supports inheritance. However struct can implements interface.
Struct should be used when you want to use a small data structure, while Class is better choice for complex data structure.



Boxing and Un-Boxing

Boxing: means converting value-type to reference-type.

Eg:

int I = 20;

string s = I.ToSting();


UnBoxing: means converting reference-type to value-type.

Eg:

int I = 20;

string s = I.ToString(); //Box the int

int J = Convert.ToInt32(s); //UnBox it back to an int.


Note: Performance Overheads due to boxing and unboxing as the boxing makes a copy of value type from stack and place it inside an object of type System.Object in the heap.




http://dng-oops.blogspot.in/









Virtual Method

By declaring base class function as virtual, we allow the function to be overridden in any of derived class.

Eg:

Class parent

{

virtual void hello()

{ Console.WriteLine(“Hello from Parent”); }

}


Class child : parent

{

override void hello()

{ Console.WriteLine(“Hello from Child”); }

}


static void main()

{

parent objParent = new child();

objParent.hello();

}

//Output

Hello from Child.





Access Modifiers

Access Modifiers are keywords used to specify the declared accessibility of a member of a type.

Public is visible to everyone. A public member can be accessed using an instance of a class, by a class's internal code, and by any descendants of a class.


Private is hidden and usable only by the class itself. No code using a class instance can access a private member directly and neither can a descendant class.

Protected members are similar to private ones in that they are accessible only by the containing class. However, protected members also may be used by a descendant class. So members that are likely to be needed by a descendant class should be marked protected.




Encapsulation

Is the ability of an object to hide its data and methods from the rest of the world. It is one of the fundamental principles of OOPs.

Real time
e.g. / Ink is the important component in pen but it is hiding by some other material

Say we create a class, named Calculations. This class may contain a few members in the form of properties, events, fields or methods. Once the class is created, we may instantiate the class by creating an object out of it. The object acts as an instance of this class, the members of the class are not exposed to the outer world directly; rather, they are encapsulated by the class.

For example code

Public class Calculations
{
  private void fnMultiply(int x, int y)
  {
  return x * y;
  }
}
...
...
Calculations obj;
int Result;
Result = obj.fnMultiply(5,10)




ENCAPSULATION MEANS HIDING ALL THE INTERNAL DETAILS OF THE METHODS.

EXAMPLE cars and owners...
all the functions of cars are encapsulated with the owners..
No one else can access it...





Friday, June 8, 2012

how to set dropdownlist max item in asp net


Set these value in dropdown

onmouseover="this.size=4;"
onmouseout="this.size=1;"