Skip to main content

Posts

Showing posts from April, 2015

Featured Post

How to use Tabs in ASP.NET CORE

I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component  public class AllViewComponent : ViewComponent     {         private readonly UserManager<ApplicationUser> _userManager;         public AllViewComponent(UserManager<ApplicationUser> userManager)         {             _userManager = userManager;         }         public async Task<IViewComponentResult> InvokeAsync()         {             List<StudentViewModel> allUsers = new List<StudentViewModel>();             var items = await _userManager.Users.ToListAsync();             foreach (var item in items)             {                 allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email });             }            

How to use SQL LIKE operator in asp.net c#

Today when we wrote a program for online job portal. On that time i want to show the job detail from job table using single English alphabet letter. So first of all i bind Dropdownlist with the alphabet letters then also bind Gridview from selected DropdownList letter. For this type of query i need SQL LIKE operator because i want to search items from the table on the basis of selected letter.  Bind the gridview with SqlDataSource with where clause.  <p>         Please Select any one letter from given list:</p>     <asp:DropDownList ID="Letters" DataSource='<%# Alphabet %>' runat="server" />     <asp:Button ID="Button1" runat="server" Text="Get Job List"  /> <p>         <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="JobId" DataSourceID="SqlDataSource1">             <Columns>  

How to bind Dropdownlist with whole english characters in ASP.NET C#

I want to say that how to add English alphabets at run time in DropdownList. A intermediate programmer know that each char contain a ASCII value like 65 is a ASCII value of letter 'A'. Similarly again 66 to 90 is a ASCII value of Letter B to Z.  So add a DropdownList in the design page also bind with Alphabet public property. Look like this: Source page: <asp:DropDownList ID="Letters" DataSource='<%# Alphabet %>' runat="server" /> Code Behind Page: public partial class Bynamejobsearch : System.Web.UI.Page {     protected void Page_Load(object sender, EventArgs e)     {         if (!Page.IsPostBack)         {             DataBind();         }     }     private List<char> _Alphabet;     protected List<char> Alphabet     {         get         {             if (_Alphabet == null)             {                 _Alphabet = new List<char>();                 for (int i = 65; i < 91; i++)              

Creating a Database in SQL Mgt Studio 2012

Creating a Database is to occupy some space in physical drive for the records saving through the application. These saved records can easily be listed or modified as per user’s requirement. To perform operations like add/edit/delete on these records a person used to create some application having capability of doing so. In earlier article, we have installed SQL Server Management Studio 2012 following some easy steps. This time we will establish a connection with server and create a database EmpDb having only a single table Employee . Start Management studio through all programs or whatever shortcut you have on your system and follow these steps. First screen will prompt you to establish a connection with server requiring some values as                below: Just write (LocalDb)\v11.0  because i have only local db installed in my system, you can change as per your server installation. On the left side there are some options "Database, Security, Replication, Management"

Nested Gridview example in asp.net c#

Before we talk about nested gridview asp.net c#. First we talk about gridview control. It is a data source control through which we can bind data in the form of table. In this article, we will take two gridview asp.net controls and we will arrange both control in this way, please see the mentioned picture. Lets to start how to design it First to add asp.net gridview in the source page Add a <Columns> tag inside it. Add single column inside it using TemplateField with HeaderText property, if you want to add more than one column then add equal number of TemplateField inside it. Show the data in the browser with the help of ItemTemplate, so add it inside Template Field. Now, the article's main point is here, Add another gridview asp.net controls inside the ItemTemplate, Now your code look like: <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"> <Columns> <asp:TemplateField HeaderText="Subject

Display filter ads on the webpage in ASP.NET

If we want to display ads on the webpage then we use  Adrotator control  in ASP.NET. Without filter ads adrotator control display all ads, which is exist in the xml file. But all ads are not good for website owner because only a content related ad earn more money compare to all ads. So lastly developers decide that they have to design user choice ad system. The KeywordFilter property is created by visual studio developers for ads filtration. Through this property you can display only those ads, which is related to content. How to use KeywordFilter Property Advertisements.xml file <ad> <Keyword> name of the keyword </Keyword> <ad> Adrotator control property KeywordFilter = name of the keyword which is mentioned in Advertisements file For more clearance please watch this video:

Installing SQL Server Mgt Studio 2012

Installing SQL Server is as simple as installing a software following a list of steps. SQL Server 2012 was released in April 2012 and because of its list of features and easiness to use made favorite among professionals and beginners. We will learn about to creating database in SQL Server Management studio after installing it in the system. Microsoft SQL Server is a powerful and free data management tool, designed for easy development and utilities including: LocalDB (MSI installer)  LocalDB is a lightweight version of Express that has all its programmability features. It can be bundled with Application and Database Development tools like Visual Studio and or embedded with an application that needs local databases. Express (Containing only the database engine)  Use this if you need to accept remote connections or administer remotely. Express with Tools (with LocalDB)  Choose either LocalDB or Express depending on your needs above. SQL Server Management Studio Express (Tools onl

Nested gridview asp.net c# with expand and collapse example

In previous example we have already learn about nested gridview asp.net . Now, today we will learn nested gridview asp.net  with expand and collapse feature. Parent Gridview bind with country database table and child Gridview bind with State database table when we select any country. Child Gridview appeared according to country_id column like. Lets start to design parent GridView: <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="GridView1_RowDataBound"> <Columns> <asp:TemplateField> <ItemTemplate> <a href="JavaScript:expandcollapse('<%# Eval("country_id") %>');"> <img src="plus.gif" border="0" id='img<%#Eval("country_Id") %>' /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="country_Id" HeaderText="Country Id" /> <asp:BoundField

Listing with Insert and Update MVC Part 1

Listing of records is binding the model with custom list of objects and show on the view page. For this process we will create custom class that will be used to create objects list and then will bind that list with model. We have learnt how to use default process and create listing with CRUD actions. In this article we will create with our own code blocks. Create a class  CategoryD  having all the fields saved in the database table  Category  as: public class CategoryD { public int Id { get; set; } public string Title { get; set; } public string Description { get; set; } public bool IsActive { get; set; } } Create a controller  CategoriesController  with default Index action. This action is empty and write following code fragment in this action: public ActionResult Index() { List<CategoryD> categories = new List<CategoryD>(); using (EmpDbEntities db = new EmpDbEntities()) { categories = db.Categories.Select(a => new CategoryD { Id = a.CategoryId, T

Working with Database First: edmx in MVC

Database First approach creates all the model classes, properties and its context from the selecting database and then let the user access those classes for performing CRUD actions. User first have to create database and then follow this article to create an edmx file. An edmx file is an XML file defines a model used to perform CRUD operations on database. This file can also be used with Entity Framework and contains some information to be used by EF designer. User can change this file to change EF designer and sometimes have to change in edmx file manually. In previous article we have created a database  EmpDb  with single table, now we will create an edmx file for this database. By using the same MVC project (used in earlier articles) follow below steps: Right click on Models folder and  Add New Item  and then select  ADO.NET Entity Data Model , name it whatever you want and click Add. The next window is for choosing model contents whether from an existing database or an em

Creating a Model in Asp.Net MVC

Creating a Model means create a database table with required fields in form of simple class and its properties. This class must be added to the pre-added folder  Models  which differentiate this from all the simple classes in the MVC application. In earlier article we have created a view for an existing action method  Index  which is by default added. At the same time we have passed some values from the same action to the respective view page. Those values have been passed through ViewBag, used to dynamically share values from controller to view. Models folder contains all the classes used to represent application model for the application including validation logic and data access. Right click on the  Models  folder and add a new class  Product  and add some properties in that class as shown below: public class Product { public int Id {get; set;} public string Name {get; set;} public string Description {get; set;} public string Color {get; set;} public string Type {get; s

Creating a View in Asp.Net MVC

Creating a View means adding an HTML file for an existing action method in controller. View is the page that is shown to user, whatever HTML you write or CSS you embed is fully applicable for that view. In earlier article we have created a controller having an “Index” action method which is by default added. We have changed this action method and returns a string to be displayed on browser directly. When working with views programmer should know about HTML language and should have a little bit knowledge of CSS style-sheets. In this article we will create a view page checking the options that can be applied on creating a view. Change  index  action method as it was when created: public ActionResult Index() { return View(); } Right click on  Index  and click on  Add View . It will show  Add View  dialog box having a list of options as in below screenshot. We will discuss all these options in later articles, by now just click on  Add  button. Expand the  Views  folde

Creating a Controller in Asp.Net MVC

What is the MVC architecture and how it can be used to build a web application has been discussed in our earlier article. We will discuss about the concept of MVC in context of classes that can be easily accessible in our application. These classes can be created as simply as other classes including properties to be get/set values. MVC stands for Model, View and Controller that divides a web application into three parts. These parts are data, user-interfaces and logics which differentiates everything about an application. Here is a one-line definition about MVC: Model : these are the classes representing your application data including the properties your database have. View: a simple page that will show to user and redirect your complex code into basic HTML. Decides the design in which data will show. Controller: these classes are responsible for what is to be shown in which view. In earlier article, we have created a simple internet application having all the basic folders

How to retrieve data from two tables in MVC

Introduction In this article, i want to bind  hyperlink from one database table like department and when we click on any department name then we will get all employee name, which is stored in second database table. In my previous example, we have to learn how to retrieve data from single database table also learn how-to bind hyperlink in mvc. Today, we will take help of both articles and learn how to retrieve data from two tables in mvc. First to prepare department class with some data members also mapped this with department table, this is already mentioned in previous post. Also add employee class in it. using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Web; namespace WebApplication11.Models { [Table("Department")] public class Department { public int Id { get; set; } public string Name { get; set; } public List<Employee> Employee { get; set; } } } Create DepartmentContext cla

fix parameters dictionary contains a null entry

Introduction Basically that's type of error occurs due to null value. But i have already try to pass some value, manually in the controller function. Always i get this error. Ok let's start to story of the error. I want to get the record from single department table and that's name is hyperlinked. Now, When i click to any hyperlink then open respective employee details, which is stored in another table. What i was done. First i was write the code for retrieving the value from single data base table, on that time, my code run successfully. But in Next time when i wrote the code for retrieving the record from two database table, on that time, i got the error. What steps i have taken First step to prepare classes for employee and department Second step to create a context for both class third step to prepare a controller for department, as well as prepare view for department forth step to prepare controller for employee, as well as prepare view for employee. Erro

Access data from database table in MVC

In MVC, we can access data from database easily. When we send any request to the server, respond generated by the controller. Data access from the Model and render by the View. First to make a database table using visual studio 2010 or higher. we have database table that is "Employee", in which have some attributes, these are CREATE TABLE [dbo].[Employee] ( [Id] INT NOT NULL PRIMARY KEY IDENTITY, [Name] NVARCHAR(50) NULL, [Age] INT NULL ) First to install entity framework by the "Nuget packages", which is available in tools-->Library Package Manager This is already available in 4.5 framework or 4.5.1. Now, add the employee class in model folder with some public properties  like   namespace WebApplication10.Models { public class Employee { public int ID { get; set; } public string Name { get; set; } public int age { get; set; } } } Now, add another class which is EmployeeContext.cs class, which is inherit from DBContext class. DBContext class is

Data Binding in MVC

In MVC, we can access data from database easily. When we send any request to the server, respond generated by the controller. Data access from the Model and render by the View. First to make a database table using visual studio 2010 or higher. we have database table that is "Employee", in which have some attributes, these are CREATE TABLE [dbo].[Employee] ( [Id] INT NOT NULL PRIMARY KEY IDENTITY, [Name] NVARCHAR(50) NULL, [Age] INT NULL ) First to install entity framework by the "Nuget packages", which is available in tools-->Library Package Manager This is already available in 4.5 framework or 4.5.1. Now, add the employee class in model folder with some public properties  like namespace WebApplication10.Models { public class Employee { public int ID { get; set; } public string Name { get; set; } public int age { get; set; } } } Now, add another class which is EmployeeContext.cs class, which is inherit from DBContext class. DBContext class is available