DATA BASE CONNECTIVITY /CLASS & OBJECT /MVC /PROJECT CONTROLLER / INTEGRATION & ETC
DATA BASE
CONNECTIVITY:-
(agar kabhi solution explore miss hojaye toh ye use kare)
Window-> reset window .
1 IN DOTNET frame work provide a facility to connect
database in web form.
2 there are following steps is used to connect database to
web form.
STEPS1:- INCLUDE DATA BASE LIBARARY
USING
SYSTEM.DATA.SQLCLINT
STEPS2:- CREATE DATA BASE OBJECT
A)
Connection object
B)
Command object
C)
Data reader object
A) Connection object:-
-This object used to find database location.
-in data base concept location is called connection String.
SYNTEX:-
SqlConnection obj;
EX:-
SqlConnection con;
B) Command object:-
-command object is represent data base query (insert,update,select,delete)
SYNTEX:-
SqlCommand obj;
EX:-
SqlCommand com;
C ) Data Reader Object:-
-in data only used select query.
SYNTEX:-
SqlDatareader
obj;
EX:-
SqlDatareader dr;
DATABASE CODE STEPS:-
Step1:-Open data base
Step2 :-Apply command (query)
Step3:-execute command(query)
HOW TO
WRITE DATABASE CODING IN C-SHARP:-
-All types od database coding is based on object oriented
programming
STEPS NO.1=
Variable<=information
String K=’’select query’’
String K=’’Update query’’
STEPS NO.2=
Variable passed to the object.
SqlCommand com;
Com=new SqlCommand(K)
EX:-
String A=’’delete query’’
Com=new SqlCommand(A)
String B=’’update query’’
Com=new SqlCommad(B)
Strring C=’’database’’
Con = new SqlConnection(C)
HOW TO OPEN DATABASE USING CODE ENVIRONMENT :-
-
In this concept using open()
Ex-
String k=”database”
Con=new SqlConnection(k)
Con.open();
HOW TO CONNECT SQL
SERVER DATA BASE TO DOT NET FRAMEWORK :-
-
There are following steps is used to connect SQL
server Data base in DOT net framwork
-
STEPS:-
1) Open data
base and copy your data base server name.
2) Open DOT
net framework
3) GO to
server explorer window
4) Right
click on data connection option
5) Click add
connection option
6) Select
Microsoft SQL server option
7) Write
your server name in server name textbox.
8) Write
your data base name in data base textbox.
9) Click
text connection button.
10) Final
click.
LAPTOP-KTNGB4Q7\SQLEXPRESS01
LAPTOP-KTNGB4Q7\SQLEXPRESS01
HOW TO
GET DATA BASE CONNECTION STRING (data base location/path):-
-
There are following steps to get data base
connection string
STEPS:-
-
Go to server explorer
-
Drag and drop any one table name inside the web
form
-
Select SQL data source control
-
Click arrow operator in select data source
control
-
Click on configure data source option
-
Click connection string checkbox
DATA BASE PATH:-
Data
Source=LAPTOP-KTNGB4Q7\SQLEXPRESS01;Initial Catalog=MARKSHEET;Integrated
Security=True
HOW TO
SET CONNECTION STRING IN CONFLICT FILE:-
-
In this concept using < APPSETTING >
-
Inside < APPSETTING> using <ADD>
THERE ARE
TWO ATTRIBUTES IN <ADD > :-
1) KEY (keyword)
2) value (data base path/connection string)
<appSettings>
<add key="MYDB" value="Data
Source=LAPTOP-KTNGB4Q7\SQLEXPRESS01;Initial Catalog=MARKSHEET;Integrated
Security=True"/>
</appSettings>
NOTE:-
ACCESS CONFIGARTION INSIDE THE WEB FORM USING
CONFIGRATION LIBARARY:-
LIBARARY:-
USING SYSTEM.CONFIGRATION
REVISED :-
-
Connect SQL server to DOT net framwork
-
Get connection string
-
Connection string inside the web conflict file.
CREATE
TABLE connectdb(roll int, Name varchar(50))
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//STEPS NO.1 INCLUDE DATA BASE LIBRABRY
using System.Data.SqlClient;
namespace WebApplication1
{
public partial
class DATACONNECT : System.Web.UI.Page
{
//STEP NO.2
CREATE DATABASE OBJECT
SqlConnection
CON;
SqlCommand
COM;
SqlDataReader
DR;
protected void
Page_Load(object sender, EventArgs e)
{
//STEP
NO.3 using not is PostBackOptions;
if
(!IsPostBack)
{
}
}
protected void
Button1_Click(object sender, EventArgs e)
{
//perfrom
code STEPS
//steps
no.1 = open data base connection
string
k=@"Data Source=LAPTOP-KTNGB4Q7\SQLEXPRESS01;Initial
Catalog=MARKSHEET;Integrated Security=True";
CON = new
SqlConnection(k);
CON.Open();
//steps
no.2 apply command (query)
string A =
"INSERT INTO CONNECTDB VALUES(@ROLL1,@NAME1)";
COM = new
SqlCommand(A, CON);
COM.Parameters.AddWithValue("ROLL1", TextBox1.Text);
COM.Parameters.AddWithValue("NAME1", TextBox2.Text);
// steps
no.3 execute command
COM.ExecuteNonQuery(); //for insert update or DELETE
Response.Write("record save successfully");
}
}
}
SERVER
NAME:-
LAPTOP-KTNGB4Q7\SQLEXPRESS01
DATA-BASE
CONNECTION:-
Data
Source=LAPTOP-KTNGB4Q7\SQLEXPRESS01;Initial Catalog=MARKSHEET;Integrated
Security=True
@operationg
representing data base path.
*How to work Select Query*
1-Select
Query is used to Data Reader Object
2-Select
Query cannot used Execute Non-Query Method
protected void Button2_Click(object sender, EventArgs e)
{
//select
query implementation
string k = @"Data Source=LAPTOP-4P2C7L8R;Initial
Catalog=college;Integrated Security=True";
con = new SqlConnection(k);
con.Open();
//perform select query
string a = "SELECT * FROM connectdb where roll=@roll1 ";
com = new SqlCommand(a, con);
com.Parameters.AddWithValue("roll1", TextBox1.Text);
//work on datareader object
dr = com.ExecuteReader(); //read select query
//check datareader where data is present or not
if(dr.Read())//check data available or not
{
//read database column and display in a specific control
TextBox2.Text = dr["name"].ToString();
}
else
{
Response.Write("record not found");
}
//close datareader
dr.Close();
}
}
}
*Delete
Query*
protected void Button3_Click(object sender, EventArgs e)
{
//perform
delete query
string k = @"Data Source=LAPTOP-4P2C7L8R;Initial
Catalog=college;Integrated Security=True";
con = new SqlConnection(k);
con.Open();
string b = "delete from connectdb where roll=@roll1";
com = new SqlCommand(b, con);
com.Parameters.AddWithValue("roll1", TextBox1.Text);
com.ExecuteNonQuery();
Response.Write("record deleted");
}
}
*Update Query*
protected void Button4_Click(object sender, EventArgs e)
{
//update
query
string k = @"Data Source=LAPTOP-4P2C7L8R;Initial
Catalog=college;Integrated Security=True";
con = new SqlConnection(k);
con.Open();
string c = "update connectdb set name=@name1 where roll=@roll1";
com = new SqlCommand(c, con);
com.Parameters.AddWithValue("roll1", TextBox1.Text);
com.Parameters.AddWithValue("name1", TextBox2.Text);
com.ExecuteNonQuery();
Response.Write("record updated");
}
}
}
BOUND
CONTROL :-
-
Bound control directly communicates to database
column.
-
There are following property used to bound
control.
A)
DataSource
B)
DataTextField
C)
DataBind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace WebApplication1
{
public partial
class DISPLAY_DATA : System.Web.UI.Page
{
SqlConnection
CON;
SqlCommand
COM;
SqlDataReader
DR;
protected void
Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
}
}
protected void
Button1_Click(object sender, EventArgs e)
{
//open
data base connectionn
string k =
@"Data Source=LAPTOP-KTNGB4Q7\SQLEXPRESS01;Initial
Catalog=MARKSHEET;Integrated Security=True";
CON = new
SqlConnection(k);
CON.Open();
//apply
command
string A =
"SELECT NAME FROM CONNECTDB";
COM = new
SqlCommand(A, CON);
DR =
COM.ExecuteReader();
//bound
column to dropdown list
DropDownList1.DataSource = DR;
DropDownList1.DataTextField = "NAME";
DropDownList1.dataBind();
DR.Close();
}
}
}
PERFORM
SQL FUNCTION:-
-
SQL function cannot use DATA reader object.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace WebApplication1
{
public partial
class SQL_FUNCTION : System.Web.UI.Page
{
SqlConnection
CON;
SqlCommand
COM;
SqlDataReader
DR;
protected void
Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
}
}
protected void
Button1_Click(object sender, EventArgs e)
{
//open
data base connectionn
string k =
@"Data Source=LAPTOP-KTNGB4Q7\SQLEXPRESS01;Initial
Catalog=MARKSHEET;Integrated Security=True";
CON = new
SqlConnection(k);
CON.Open();
//apply
command
string A =
"SELECT COUNT(*)FROM CONNECTDB";
COM = new
SqlCommand(A, CON);
Label1.Text = COM.ExecuteScalar().ToString();
}
}
}
TASK 1 DEGREE TASK:-
WSP IMAGE:-
-
TASK 1) DROPDOWNLIST
-
TASK 2) SQL FUNCTION COUNT()
-
SUBMIT INSERT QUERIES
-
GENEREATE BUTTON COUNT FUNCTION
---------------------------------------------------------------------------------------------------------------------------------
**Data
Control**
-Data Control is used to display data visualisation(report)
-There are following Data Control
a-Grid view
b-Repeat
c-Data List
d-Detail View
e-Form View
f-List View
Note-all
data control is used only two property
1-Data
Source
2-Data
Bind
A)
Grid View
-Display data in tabular format
-There are following implementation used in grid view
control
A-Basic Binding
b-Control Binding
c-Footer
d-Image display
e-Evalve Function
f-Auto Generate Column
g-Paging
h-Auto Formatting
i-Excel Conversion
1-Basic
Binding
-In this concept using bound field property and there are
2main property is used in bound field
1-Headertext-any types of heading
2-Datafield-column name
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace WebApplication1
{
public partial class Datadisplay :
System.Web.UI.Page
{
//database object
SqlConnection
con;
SqlCommand com;
SqlDataReader dr;
protected void
Page_Load(object sender, EventArgs e)
{
//using if postback
if(!IsPostBack)
{
}
}
protected void
Button1_Click(object sender, EventArgs e)
{
//perform codestep
//step1-open database connection
string k = @"Data Source=LAPTOP-4P2C7L8R;Initial
Catalog=college;Integrated Security=True";
con = new SqlConnection(k);
con.Open();
string a = "SELECT * FROM CONNECTDB";
com = new SqlCommand(a, con);
dr = com.ExecuteReader();
//bind gridview
GridView1.DataSource = dr;
GridView1.DataBind();
dr.Close();
}
}
}
**GridView
Auto Formatting**
Click arrow >> select auto format
**GridView
Footer Concept**
1-Activate footer in a gridview using show footer attribute.
*How
to Display in Gridview Footer*
In this concept is used to footerrowmethod.
2-Gridview column is to be started zero index
//display
data in gridview footer
GridView1.FooterRow.Cells[1].Text="Total Amount";
*How to
insert control in gridview*
1-In this concept using templatefield
2-Under template field we have to
used<ItemTemplate></ItemTemplate>
<asp:TemplateField HeaderText="Control">
<ItemTemplate>
<asp:TextBox
ID="TextBox1" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="button">
<ItemTemplate>
<asp:Button ID="Button2" runat="server"
Text="Button" />
</ItemTemplate>
</asp:TemplateField>
*Display
Database Value*
In this concept using Eval()
Syntax-‘<%# Eval(“Column”) %>’
Eval() only used TEXT property using single quote
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Eval("name") %>'></asp:TextBox>
</ItemTemplate>
*Stock Assignment*
1-calculate button-calculate total[cost*quantity]
2-duplicate id not accepted(without primary key)
3-quantity only accept >5
4-in gridview display all data inside textbox
control(eval())
5-display sum in gridview footer
Ans:- string k =”Select sum (total) from table name”
Com=new sql command (K,cn);
Gridview1.footerrow.cell[3].text=com.executescaller.tostring();
6-sum of >3000 then provide 10% discount
Ans:-
7-display final amount after discount(label)
________________________________________________________________________________
GRIDVIEW
EVEND HANDLING (COURD VIEW) :-
-INSIDE control (naming container)
-outside control (for each)
//CREATE FOR EACH LOOP
foreach(GridViewRow obj in GridView1.Rows)
{
//FIND
CONTROL
//SYNTEX
obj1 =
(TextBox)obj.FindControl("txtname");
Response.Write(objt1.text);
HOW TO
PROVIDE CONTROL ID :-
-
Textbox-txt
-
Label-lbl
-
Dropdownlist- ddl
-
Button-btn
HOW TO
DIPSLAY AUTOGENERATE SERIAL NUMBER IN GRIDVIEW:-
-IN this concept using container menthod
<asp:TemplateField HeaderText="SERIAL
NO.">
<ItemTemplate>
<%# Container.DataItemIndex +1 %>
</ItemTemplate>
HOW TO
PERFORM EVELL INSIDE CONTROL:-
-in this concept using naming container method
SYNTEX:-
GridViewRow obj=((control)sender).namingContainer AS
GridViewRow
//naming container
GridViewRow
objR1 = ((Button)sender).NamingContainer as GridViewRow;
//find
control
TextBox
objT1 = (TextBox)objR1.FindControl("txtname");
Response.Write(objT1.Text);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace WebApplication1
{
public partial
class DATA_SHOW : System.Web.UI.Page
{
SqlConnection
CON;
SqlCommand
COM;
SqlDataReader
DR;
protected void
Page_Load(object sender, EventArgs e)
{
if
(!IsPostBack)
{
}
}
protected void
GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void
Button1_Click(object sender, EventArgs e)
{
string k =
@"Data Source=LAPTOP-KTNGB4Q7\SQLEXPRESS01;Initial
Catalog=MARKSHEET;Integrated Security=True";
CON = new
SqlConnection(k);
CON.Open();
string A =
"SELECT* FROM CONNECTDB";
COM = new
SqlCommand(A, CON);
DR =
COM.ExecuteReader();
//BIND
GRIDVIEW
GridView1.DataSource = DR;
GridView1.DataBind();
DR.Close();
}
protected void
Button2_Click(object sender, EventArgs e)
{
//CREATE
FOR EACH LOOP
foreach(GridViewRow obj in GridView1.Rows)
{
//FIND
CONTROL
//SYNTEX
TextBox objt1 =
(TextBox)obj.FindControl("txtname");
Response.Write(objt1.Text );
}
}
protected void
BtnView_Click(object sender, EventArgs e)
{
//naming
container
GridViewRow objR1 = ((Button)sender).NamingContainer as GridViewRow;
//find
control
TextBox
objT1 = (TextBox)objR1.FindControl("txtname");
Response.Write(objT1.Text);
}
}
}
Source side :-
<%@ Page Language="C#"
AutoEventWireup="true" CodeBehind="DATA-SHOW.aspx.cs"
Inherits="WebApplication1.DATA_SHOW" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form
id="form1" runat="server">
<div>
GRIVEDVIEW
IMPLEMENTAION:-<br />
<br
/>
<asp:Button ID="Button1" runat="server"
Text="SHOW" OnClick="Button1_Click" />
<asp:Button
ID="Button2" runat="server"
OnClick="Button2_Click" Text="DISPLAY-DATA" />
<br
/>
<br
/>
ID ,NAME
<br
/>
<br
/>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="SERIAL NO.">
<ItemTemplate>
<%# Container.DataItemIndex +1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="STUDENT ID">
<ItemTemplate>
<asp:TextBox ID="txtName" runat="server"
Text='<%# Eval("roll") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="STUDNET NAME">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%# Eval("name") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ACTION">
<ItemTemplate>
<asp:Button ID="BtnView" runat="server"
Text="View" OnClick="BtnView_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br
/>
<br
/>
</div>
</form>
</body>
</html>
TASK ON
WTSP STUDENT MARK ALLOTMENT:-
Task on group wts up:-
-bracnch dropdown list (cse It civil)
-duplicate college code not accepted
-if student can lpog in studentpanel.aspx
If faculty can ;log in than open facultypanel.aspx
-if faculty can log In cse department than dipslya only cSe
log in list
Faculty log in -
-
Faculty can update particular mark in mark table
-
Faculty can delete particular record in mark
table
-
If faculty can click update all button than
update all mark in mark table
-If student can log in than open student panel
- name, branch , mark automatic
Error:-
-Login button mei faculty ko
choose karne ke bad error aarha leking student log in aaarha hai
- student ne log in karne bad
Studentpanel mei automatic data nahi aarha hai
-faculty panel error
DISPLAY
IMAGE IN GRIDVIEW CONTROL:-
-IN this concept using imagefield property and there
following property use to image field.
1 header text. (column heading)
2 dataImageURLfield.
(column name)
3 dataimageURLformalstring= Imageloaction (~/ Folder name/
{0} )
Use in database for name change :--
UPDATE CONNECTDB SET NAME='A1.jpg';
HOW TO
SET HEIGHT AND WIDTH IN GRIDVIEW IMAGE:-
Only image field change in source :-
</asp:TemplateField>
<asp:ImageField DataImageUrlField="Name"
DataImageUrlFormatString="~/PIC/{0}" HeaderText="Student
Photo">
<ControlStyle Height="150px" Width="150px"/>
</asp:ImageField>
GRIDVIEW
PAGING:-
-in this concept display page number in gridview.
-in paging concept using allow page attributes In gridview.
-activate paging in gridview using OnPageIndexChanging event
<asp:GridView
ID="GridView1" runat="server"
AutoGenerateColumns="False"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AllowPaging="true"
OnPageIndexChanging="GridView1_PageIndexChanging">
(balance
topic) (kajal notes copy code)
Activate paging using code:-
-
At the time of apging concept display only 10
records in a gridview
-
Datareader only read single record at the time
-
Reading bulk data in a databse using DataSet or dataAdapter
-
Dataset or dataAdapter is used data library
-
using System;
-
using System.Collections.Generic;
-
using System.Linq;
-
using System.Web;
-
using System.Web.UI;
-
using System.Web.UI.WebControls;
-
using System.Data.SqlClient;
-
using System.Data;
-
-
namespace DataConnectivity
-
{
-
public
partial class DataShow : System.Web.UI.Page
-
{
-
SqlConnection con;
-
SqlCommand com;
-
SqlDataReader dr;
-
protected void Page_Load(object sender,
EventArgs e)
-
{
-
if(!IsPostBack)
-
{
-
displayData();
-
}
-
}
-
-
-
protected void displayData()
-
{
-
string d = @"Data
Source=.\SQLEXPRESS;Initial Catalog=COLLEGE;Integrated Security=True";
-
con = new SqlConnection(d);
-
con.Open();
-
-
string s = "SELECT * FROM
CONNECTDB";
-
DataSet ds = new DataSet();
-
SqlDataAdapter adp = new
SqlDataAdapter(s,con);
-
//fill adapter object using dataset
-
adp.Fill(ds);
-
//bind dataset object to gridview
control
-
GridView1.DataSource = ds;
-
GridView1.DataBind();
-
-
-
}
-
-
protected void Button1_Click(object
sender, EventArgs e)
-
{
-
string d = @"Data
Source=.\SQLEXPRESS;Initial Catalog=COLLEGE;Integrated Security=True";
-
con = new SqlConnection(d);
-
con.Open();
-
-
string s = "SELECT * FROM
CONNECTDB";
-
com = new SqlCommand(s, con);
-
dr = com.ExecuteReader();
-
-
GridView1.DataSource = dr;
-
GridView1.DataBind();
-
dr.Close();
-
-
-
}
-
-
protected void Button2_Click(object
sender, EventArgs e)
-
{
-
// create forEach loop outside
event
-
foreach(GridViewRow obj in
GridView1.Rows)
-
{
-
// find control
-
// syntax control obj =
(control)rowObject.FindControl("ControlID");
-
-
TextBox objt1 =
(TextBox)obj.FindControl("txtName");
-
Response.Write(objt1.Text);
-
}
-
}
-
-
protected void BtnView_Click(object
sender, EventArgs e)
-
{
-
// namingContainer
-
GridViewRow objR1 =
((Button)sender).NamingContainer as GridViewRow;
-
-
// findcontrol
-
TextBox objt1 =
(TextBox)objR1.FindControl("txtName");
-
Response.Write(objt1.Text);
-
-
}
-
-
protected void
GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
-
{
-
// activate page concept
-
-
GridView1.PageIndex =
e.NewPageIndex;
-
displayData();
-
}
-
-
protected void Button3_Click(object
sender, EventArgs e)
-
{
-
-
}
-
}
-
}
** Repeater Control:-
- Display data only
for row format.
- Repeater is used eval()
for binding data inside the repeater
- string d = @"Data
Source=.\SQLEXPRESS;Initial Catalog=COLLEGE;Integrated
Security=True";
- con = new SqlConnection(d);
- con.Open();
- string s = "SELECT * FROM
CONNECTDB ";
- com = new SqlCommand(s, con);
- dr = com.ExecuteReader();
- Repeater1.DataSource = dr;
- Repeater1.DataBind();
- dr.Close();
**
Repaeter Event Handling:
-
In repeater event handling can not use “onClick
Event .
-
It Used to commandName attribute
-
Activate CommandName using OnItemCommand Event
// Activate CommandName
if(e.CommandName == "btnshow")
{
//
FindControl
TextBox objt1 = (TextBox)e.Item.FindControl("TextBox1");
Response.Write(objt1.Text);
Source :
<br />
<asp:Button ID="Button2" runat="server"
Text="Show" CommandName="btnshow"/>
<asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox>
<hr />
**
Display All Repeater Data Using for Loop:-
// Display All Label data
for(int i
=0;i<Repeater1.Items.Count; i++)
{
//
findControl
Label
lblname = Repeater1.Items[i].FindControl("Label2") as Label;
Response.Write(lblname.Text);
** Task :-
-
Perform CRUD Opeartion using repeater
** DETAILVEIWCONTROL :-
-
Detailview
control is used to display data in detail format.
-
Output:
-
Role 101
-
Name
kajal
-
City
Nagpur
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace WebApplication1
{
public partial
class detailview : System.Web.UI.Page
{
SqlConnection
con;
SqlCommand
com;
SqlDataReader
dr;
protected void
Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
}
}
protected void
DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e)
{
//
activate command
if
(e.CommandName == "btn-display")
{
//
find control
TextBox objt1 =
(TextBox)DetailsView1.Rows[2].FindControl("TextBox1");
Response.Write(objt1.Text);
}
}
protected void
Button1_Click(object sender, EventArgs e)
{
//display
button logic
string K =
@"Data Source=LAPTOP-KTNGB4Q7\SQLEXPRESS01;Initial
Catalog=MARKSHEET;Integrated Security=True";
con = new
SqlConnection(K);
con.Open();
string A =
"SELECT* FROM connectdb";
com = new
SqlCommand(A,con);
dr =
com.ExecuteReader();
DetailsView1.DataSource = dr;
DetailsView1.DataBind();
dr.Close();
}
}
}
Source :-
<asp:DetailsView ID="DetailsView1"
runat="server" AutoGenerateRows="False"
Height="50px" Width="125px"
OnItemCommand="DetailsView1_ItemCommand">
<Fields>
<asp:BoundField DataField="roll" HeaderText="ID"
/>
<asp:BoundField DataField="Name"
HeaderText="NAME" />
<asp:TemplateField HeaderText="MESSAGE">
<ItemTemplate>
<asp:TextBox
ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button
ID="Button2" runat="server" Text="Display" CommandName="btn-display"/>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
DATA LIST
CONTROL:=
-
Data list control use to display data in column
format.
-
Data list control generally used to design
e-commerce layout.
-
Data list control similar to repeater handling.
-
There are two basic attributes use in data list
control.
1.repeat direction
2.repeat column
SOURCE:--
<asp:DataList ID="DataList1"
runat="server" RepeatDirection="Horizontal"
RepeatColumns="4" OnItemCommand="DataList1_ItemCommand">
<ItemTemplate>
<img src="PIC/A1.jpg" height="200px"
width="200px" />
<br />
<b> ROLL </b>
<asp:Label ID="Label1" runat="server"
Text='<%# Eval("ROLL") %>'></asp:Label>
<br />
<b> NAME </b>
<asp:Label ID="Label2" runat="server"
Text='<%# Eval("NAME") %>'></asp:Label>
<br />
<asp:Button ID="Button2" runat="server"
Text="BUY NOW" CommandName="btn-buy" />
</ItemTemplate>
</asp:DataList>
DESIGN :-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//using libarary
using System.Data.SqlClient;
namespace WebApplication1
{
public partial
class Ecommerce : System.Web.UI.Page
{
SqlConnection
con;
SqlCommand
com;
SqlDataReader
dr;
protected void
Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
}
}
protected void
DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if(e.CommandName=="btn-buy")
{
Label
objl1 = (Label)e.Item.FindControl("label2");
Response.Write(objl1.Text);
}
}
protected void
Button1_Click(object sender, EventArgs e)
{
//open
connection
string K =
@"Data Source=LAPTOP-KTNGB4Q7\SQLEXPRESS01;Initial
Catalog=MARKSHEET;Integrated Security=True";
con = new
SqlConnection(K);
con.Open();
//select
query
string A =
"SELECT* FROM connectdb";
com = new
SqlCommand(A,con);
//for
daata r
dr =
com.ExecuteReader();
DataList1.DataSource = dr;
DataList1.DataBind();
dr.Close();
}
}
}
Assignment:-
-
Create user registration page
-
Login.aspx
-
Product.aspx (name, photo and cost)
automactic
-
Add product.aspx – product id, product name,
cost, photo
-
Add button-> than card.aspx -> display
all product details as per user login.
-
And calculate total amount in grid view.
-
Order bill button than open bill.aspx page automatic data all and
18% gst.
FORMVIEW
CONTROL:-
-
Formview control is use to display data and information in form format
-
Formview control only display single record at a
time
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace WebApplication1
{
public partial
class DataForm : System.Web.UI.Page
{
SqlConnection
con;
SqlCommand
com;
SqlDataReader
dr;
protected void
Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
}
}
protected void
Button1_Click(object sender, EventArgs e)
{
string K =
@"Data Source=LAPTOP-KTNGB4Q7\SQLEXPRESS01;Initial
Catalog=MARKSHEET;Integrated Security=True";
con = new
SqlConnection(K);
con.Open();
string A =
"SELECT* FROM connectdb";
com = new
SqlCommand(A,con);
dr =
com.ExecuteReader();
FormView1.DataSource = dr;
FormView1.DataBind();
dr.Close();
}
}
}
<%@ Page Language="C#"
AutoEventWireup="true" CodeBehind="DataForm.aspx.cs"
Inherits="WebApplication1.DataForm" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form
id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server"
Text="DISPLAY" OnClick="Button1_Click" />
<br
/>
<br
/>
<br
/>
<asp:FormView ID="FormView1" runat="server">
<ItemTemplate>
SB
JAIN<br />
<br />
<a
href="mailto:sbjain@gmail.com">sbjain@gmail.com</a><br
/>
<br />
_________________________________________________<br />
<br />
STUDENT ROLL NO.:-<br />
<br />
<asp:Label ID="Label1" runat="server"
Text='<%# Eval("roll") %>'></asp:Label>
<br />
<br />
STUDENT NAME:-<br />
<br />
<asp:Label ID="Label2" runat="server"
Text='<%# Eval("name") %>'></asp:Label>
<br />
<br />
ENTER MARK:-<br />
<br />
<asp:TextBox
ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="DISPLAY" runat="server"
Text="Button" />
<br />
<br />
</ItemTemplate>
</asp:FormView>
</div>
</form>
</body>
</html>
FORM VIEW
Event HANDLING:-
-
In form view event handling is use to command name attribute.
<asp:FormView ID="FormView1"
runat="server" OnItemCommand="FormView1_ItemCommand1">
<ItemTemplate>
SB
JAIN<br />
<br />
<a
href="mailto:sbjain@gmail.com">sbjain@gmail.com</a><br
/>
<br />
_________________________________________________<br />
<br />
STUDENT ROLL NO.:-<br />
<br />
<asp:Label ID="Label1" runat="server"
Text='<%# Eval("roll") %>'></asp:Label>
<br />
<br />
STUDENT NAME:-<br />
<br />
<asp:Label ID="Label2" runat="server"
Text='<%# Eval("name") %>'></asp:Label>
<br />
<br />
ENTER MARK:-<br />
<br />
<asp:TextBox
ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="DISPLAY" runat="server"
Text="Button" CommandName="btn-display" />
<br />
<br />
</ItemTemplate>
</asp:FormView>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace WebApplication1
{
public partial
class DataForm : System.Web.UI.Page
{
SqlConnection
con;
SqlCommand
com;
SqlDataReader
dr;
protected void
Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
}
}
protected void
Button1_Click(object sender, EventArgs e)
{
string K =
@"Data Source=LAPTOP-KTNGB4Q7\SQLEXPRESS01;Initial
Catalog=MARKSHEET;Integrated Security=True";
con = new
SqlConnection(K);
con.Open();
string A =
"SELECT* FROM connectdb";
com = new
SqlCommand(A,con);
dr =
com.ExecuteReader();
FormView1.DataSource = dr;
FormView1.DataBind();
dr.Close();
}
protected void
FormView1_ItemCommand(object sender, FormViewCommandEventArgs e)
{
}
protected void
FormView1_ItemCommand1(object sender, FormViewCommandEventArgs e)
{
if(e.CommandName=="btn-display")
{
//create form view
FormViewRow R1 = FormView1.Row;
TextBox obj1 = (TextBox)R1.FindControl("TextBox1");
Response.Write(obj1.Text);
}
}
}
}
DATABASE
CONNECTIVITY USING CLASS AND OBJECT:-
-
In class and object manage all data base concept
class object.
Create class object :-
Add-> new->search class -> class select-> add
STUDENT
CLASS CODE :-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
namespace WebApplication1
{
public class
Student
{
SqlConnection
con;
SqlCommand
com;
SqlDataReader
dr;
public string
SubmitData(int R1, string N1)
{
string K =
@"Data Source=LAPTOP-KTNGB4Q7\SQLEXPRESS01;Initial
Catalog=MARKSHEET;Integrated Security=True";
con = new
SqlConnection(K);
con.Open();
string A =
"INSERT INTO connectdb values(@roll1,@name1)";
com = new
SqlCommand(A,con);
com.Parameters.AddWithValue("roll1",R1);
com.Parameters.AddWithValue("name1",N1);
com.ExecuteNonQuery();
return A;
}
}
}
MAIN PAGE
PROGCLASS CODE :- (ONLY CALL )
protected void Button1_Click(object sender, EventArgs e)
{
//create
class object
Student s
= new Student();
//
s.SubmitData(int.Parse(TextBox1.Text),TextBox2.Text);
Response.Write("record successfully");
}
TASK :-
LOGIC 1:-
Logic 1:- perform all operation using class and object
-
If role number alerdy register then display
alredy registration massage on computer screen using class and object
-
Every massage like : record save successfully ,
RECORD UPDATED SUCCESSFULLY, DELETED USING CLAS AND OBJECT
-
DISPLAY GRIDVIEW DATA USING CLASS AND OBJECT
TASK 2:-
RESEARCH IMPLENTATION:-
-
How to pass dotnet control in class and object and create any 1 ex. With
your choice.
STORED PRODURE REVISE FOR NEXT TOPIC -
STORED
PROCEDURE CONNECTIVITY:-
-
Include data library
-
Inside sqlcommand() pass procedure name
-
Using commandType() for activating
commandProcedure
DATABASE :-
CREATE PROCEDURE SUBMITDATA(@roll1 AS INT,@Name1 AS
VARCHAR(50))
AS
BEGIN
INSERT INTO connectdb(roll,Name) VALUES(@roll1,@Name1)
END
CODE:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
namespace WebApplication1
{
public partial
class PageProcedure1 : System.Web.UI.Page
{
SqlConnection
con;
SqlCommand
com;
SqlDataReader
dr;
protected void
Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
}
}
protected void
Button1_Click(object sender, EventArgs e)
{
string K =
@"Data Source=LAPTOP-KTNGB4Q7\SQLEXPRESS01;Initial
Catalog=MARKSHEET;Integrated Security=True";
con = new
SqlConnection(K);
con.Open();
//ACCESS
PRODURE
com = new
SqlCommand("SUBMITDATA", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("roll1", TextBox1.Text);
com.Parameters.AddWithValue("Name1", TextBox2.Text);
com.ExecuteNonQuery();
Response.Write("RECORD SAVE SUCCESSFULLY");
}
}
}
TASK 1:-
-Convert class and object to storedprocedure
-Pass control to class and object any one damo
-Access storedprocedure class and object any one demo
REVIEW POINTS:-
-C# PROGRAMMING
1variable concepts
2 conditional and looping
3 function concept
4 class and object fundamental
5 array concepts
6 acception handling
7 nameSpace
-DATABASE:-
1 database terminology
2 basic query (insert update delete select)
3 foreign key concepts
4 alter query
5
joining concepts
6 stored procedure
-DOT NET DEVELOPMENT:-
1 Dot net file extension
2 control programming
3 state management( session ,query, string, management)
4 file uploading
5 master page creation
6 web form creation
7 control id concepts
8 form tag fundamental
DATABASE CONNECTIVITY:-
1 basic crud operation
2 class and object database connectivity **
3 stored procedure database connectivity **
4 web configuration connection string
5 gridview crud operation *****
6 registration and log in model *****
7 external database connectivity ( sql server )
8 assignment model
PLACEMENET PROCESS:-
1
resume preparation
-
Career objective :- Career Objective ( AFTER YOUR PHOTO )
Motivated and detail-oriented
Junior .NET Developer with strong knowledge of C#, ASP.NET, SQL Server, and web
technologies. Seeking an entry-level role to apply technical and
problem-solving skills in a dynamic team environment and grow as a full-stack .NET
developer.
-
Education detail
-
Work experience (non IT mention) old
experience ,Current experience
-
Current experience ;- organisation
NRSolution4U ,
-
designation – junior Dot net developer,
-
DOJ- 1-1-2025 -present
-
Role and responsibility - .Develop
Applications, Support Database Development, Assist in Front-End Integration, Participate
in Code Reviews, Debugging and Testing, Documentation, Collaborate with Teams, Learn
and Grow:
-
PROJECT WORKING :- project working
Title ( defuse )
line description with module
technology used ( dot net , c# , sql server )
-
KEY SKILL :- C#, ASP.NET, SQL Server, Stored
Procedures, HTML, CSS, JavaScript, jQuery, Bootstrap, AJAX, Visual Studio , Debugging
& Troubleshooting, Basic knowledge of OOPs, SDLC
2
SALARY STRUCTURE :- 10 K cash in hand
-
DOCUMENT LIST :- offer letter, appointment
letter, reliveing letter, salary structure, work experience
3
HOW TO APPLY :-
1 cover letter for mail
2 TARGET LOCATION
Google search – DOT net developer opening for
fresher candidate in city name / experience
LINKDN PROFILE :-
Naukari.com :- immediate joining open
Indeed :-
Apna app:-
Glassdore:-
Resume + self introduction
1 kajal – Hyderabad
Create google excel sheet
Option- sr no, company
name, hr-email, mobile, resume send
status, follow up remark , date
2 mahesh - PUNE
Same as kajal
TARGET :- DAILY BASIS 15
RESUME
MNC TARGET :- HCL, COGINZWNT
,ACCENTURE, GLOBAL LOGIC, SMART DATA, CGI HYDERABAD, WIPRO,
OLD EXPERIENCE :-
END DATE :- NOV 2024
MVC
AND WEB API:-
MVC :- (Model View controller)
-
Model – create a class.
-
View – create design page. (.CSHTML)
-
Controller – inside a controller create all
logic.
1.
MVC is provide light weight development model.
And it maintained only single web page where user can design and perform all
logic
2.
as
compare .NET framework MVC is use light weight environment.
3.
Inside
MVC is use to create .CSHTML page.
HOW TO
CREATE 1 MVC APPLICATION:-
-
Select MVC option at the time of application
creation.
HOW TO
CREATE A MODEL :- ( CLASS) extention :- (.CS)
-
Right click on model folder -> click add
option -> click class option-> name of your class (.CS extention)
HOW TO
CREATE A MEMBER INSIDE CLASS :-
-
All member inside class used in public specifier
with the help of get set property.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace PROJMVC.Models
{
public class
Student
{
//crate member
public int age
{ get; set; }
public string
name { get; set; }
public string
city { get; set; }
public string
country { get; set; }
}
}
HOW TO
CRETE CONTROLLER :-
STEPS :- right click on controller folder -> click add option
-> select controller -> select MVC 5 controller – Empty -> than add-> add name controller.
NOTE :- all controller name is to be specified with
controller keyword.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace PROJMVC.Controllers
{
public class
CompanyController : Controller
{
// GET:
Company
public
ActionResult Index()
{
return
View();
}
}
}
HOW TO
RUN CONTROLLER IN WEB BROWSER :-
-
All controller is to be return direct data value
using return keyword.
-
There are two basic type of method used in
return keyword.
1.
ActionResult Method :-
– in this type of method only use if user can
create any type of logic inside the controller
2.
String Method :-
-In this method only use if user not required any type of logics.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace PROJCONTROLLER.Controllers
{
public class
StudentController : Controller
{
// GET:
Student
public
ActionResult Index()
{
return
View(); // go to the design page. extention(.CSHTML)
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace PROJCONTROLLER.Controllers
{
public class
StudentController : Controller
{
// GET:
Student
public string
Index()
{
return
"this my 1st controller programm";
// this
message directly display on web browser
}
}
}
HOW TO
RUN CONTROLLER IN WEB BROWSER :-
SYNTEX:-
HTTPS://Localhost/ControllerName/MethodName
-default method in MVC is index
EX.:-
HTTPS://localhost/student/ =>
http://localhost:28573/student
namespace PROJCONTROLLER.Controllers
{
public class
StudentController : Controller
{
// GET:
Student
public string
Index()
{
return
"this my 1st controller programm";
// this
message directly display on web browser
}
HOW TO
PASS PARAMETER IN CONTROLLER ():-
SYNTEX:-
https://localhost/controllername/methodname
? variable = value
https://localhost:28573/student/ShowData?data=Nagpur
public string showData(string data)
{
return
"You are selected " + data;
}
TASK 1:-
-
DISPLAY FOLLOWING
information(name,city,state,branch) using controller URL.
MON = DB- REVIEW
FRI MORNING 9 AM = COMPLETE C#
INTEGRATION
BETWEEN MODEL VIEW AND CONTROLLER :-
MODELS:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebApplication1.Models
{
public class
STUDENT
{
// Models
public int
studentid { get; set; }
public string
studentname { get; set; }
public int age
{ get; set; }
}
}
//INCLUDE
MODEL LIBARARY- USING ROUTENAME.MODEL
using
WebApplication1.Models; (SOLUTIONS EXPLORER KA NAME HOTA HAI ROUTNAME MEANS)
CONTROLLER
:-
//CREATE A METHOD
static
IList<STUDENT> studentlist = new List<STUDENT>
{
//store
all data elment in model.
new
STUDENT() {studentid=101,studentname="Ramesh",age=20},
new
STUDENT() {studentid=102,studentname="Mahesh",age=24},
new
STUDENT() {studentid=103,studentname="Ganesh",age=30},
new
STUDENT() {studentid=104,studentname="rahul",age=25},
new
STUDENT() {studentid=105,studentname="Ritu",age=32}
};
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
//INCLUDE MODEL LIBARARY- USING ROUTENAME.MODEL
using WebApplication1.Models;
namespace WebApplication1.Controllers
{
public class
STUDENTController : Controller
{
//CREATE A
METHOD
static
IList<STUDENT> studentlist = new List<STUDENT>
{
//store
all data elment in model.
new
STUDENT() {studentid=101,studentname="Ramesh",age=20},
new
STUDENT() {studentid=102,studentname="Mahesh",age=24},
new
STUDENT() {studentid=103,studentname="Ganesh",age=30},
new
STUDENT() {studentid=104,studentname="rahul",age=25},
new
STUDENT() {studentid=105,studentname="Ritu",age=32}
};
// GET:
STUDENT
public
ActionResult Index()
{
return
View(studentlist); //return all data to view page
}
}
}
VIEW
(CS.HTML)
-HOW TO CREATE => INDEX RIGHT CLICK=> ALL remove click
=> add
//libarary in cshtml
-ienumenrable only use list object otherwise not using.
@model IEnumerable<WebApplication1.Models.STUDENT>
@model IEnumerable<WebApplication1.Models.STUDENT>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta
name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
@foreach(var item
in Model)
{
<b>
@item.studentid</b>
<br />
<b>
@item.studentname</b>
<br />
<b>
@item.age</b>
}
</body>
</html>
TASK:-
DISPLAY STUDENT DATA IN <TABLE>.
@model IEnumerable<WebApplication1.Models.STUDENT>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta
name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<table border="1">
@foreach (var item in Model)
{
<TR>
<th>
<b> @item.studentid</b></th>
<th>
<b> @item.studentname</b></th>
<th>
<b> @item.age</b></th>
</TR>
}
</table>
</body>
</html>
RESULT:-
STUDENT ID
STUDENTNAME AGE
-----------------------------------------------------------------------------------------------------------------------------
DATE :-
4/5/2026 REVISED
CREATE TABLE MY11(ID INT,'NAME'VARCHAR());
--revised autogenrate column,create table query
CREATE TABLE STU(ID INT,NAME VARCHAR(50))
INSERT INTO STU VALUES(101,'MADDY');
--REVISED INLINE INSERT, REvised DB View, REVISED SELECT
QUERY METHOD,
CREATE TABLE COLLEGE(ID INT PRIMARY KEY,NAME VARCHAR(50))
INSERT INTO COLLEGE VALUES(101,'RAHUL'),(102,'SAGAR')
CREATE TABLE ADDMITION(ID INT,NAME VARCHAR(50))
--REVISED FOREIGN KEY
ALTER NAME FROM COLLEGE;
--REVISED ALTER QUERY, DELETE QUERY
--REVISED PROCEDURE CONCEPTS
CREATE PROCEDURE
AS
BEGIN
END
CREATE TABLE AR(ID INT,NAME VARCHAR(50))
INSERT INTO AR VALUES(1,'KK'),(2,'RR')
CREATE TABLE RM(ID INT,NAME VARCHAR(50))
INSERT INTO RM VALUES(11,'UU'),(22,'LL')
--REVISED UNION METHOD AND RELATED
CREATE TABLE MANGO(ID INT,NAME VARCHAR(50),CHECK CONSTRAINT
SALARY INT)
INSERT INTO MANGO VALUES(101
--REVISED CONSTRAINT
INSERT INTO MANGO VALUES(ID
NOT NULL, )
-- NULL CONCEPT REVISED
--------------------------------------------------------------------------------------------------------------------------------
MVC VIEWDATA, VIEWBAG, TEMPDATA CONCEPTS
*********
VIEWDATA:-
-
Viewdata is special type of dissnory for use to
storing and accessing data from control to View page.
Note:-
-
Viewdata is required type casting.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace VIEWDATA.Controllers
{
public class
StudentController : Controller
{
// GET:
Student
public
ActionResult Index()
{
List<string> Course = new List<string>();
Course.Add("CSE");
Course.Add("IT");
Course.Add("Civil");
Course.Add("MBA");
Course.Add("MCA");
//create
Viewbag
ViewData["Courses"] = Course;
return
View();
}
}
}
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta
name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<h2>List of
Courses</h2>
<br />
<b>
STRUCTURE OF C# PROGRAMMING </b>
@{
//coding for
C#
foreach(var
course1 in ViewData["Courses"] as List<string>)
{
<p>
@course1 </p>
}
}
</body>
</html>
TASK:-
Display list element using order list.
Ans:-
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta
name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<h2>List of
Courses</h2>
<br />
<b>
STRUCTURE OF C# PROGRAMMING </b>
<ol>
@{
//coding for
C#
foreach (var
course1 in ViewBag.Courses)
{
<li>
@course1 </li>
}
}
</ol>
</body>
</html>
VIEWBAG:-
*******
-View bag cannot use type casting
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace VIEWDATA.Controllers
{
public class
StudentController : Controller
{
// GET:
Student
public
ActionResult Index()
{
List<string> Course = new List<string>();
Course.Add("CSE");
Course.Add("IT");
Course.Add("Civil");
Course.Add("MBA");
Course.Add("MCA");
//create
Viewbag
ViewBag.Courses = Course;
return
View();
}
}
}
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta
name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<h2>List of
Courses</h2>
<br />
<b>
STRUCTURE OF C# PROGRAMMING </b>
@{
//coding for
C#
foreach (var
course1 in ViewBag.Courses)
{
<p>
@course1 </p>
}
}
</body>
</html>
TEMPDATA:-
-
Similar to View data and its reserve temporary
location.
-
using System;
-
using System.Collections.Generic;
-
using System.Linq;
-
using System.Web;
-
using System.Web.Mvc;
-
-
namespace TEMPDATA.Controllers
-
{
-
public class StudentController : Controller
-
{
-
// GET: Student
-
public ActionResult Index()
-
{
-
List<string> Course = new List<string>();
-
Course.Add("MBA");
-
Course.Add("MCA");
-
Course.Add("BBA");
-
Course.Add("B.COM");
-
Course.Add("B-TECH");
-
-
//create Tempdata
-
-
TempData["Courses"] = Course;
-
-
-
return View();
-
}
-
}
-
}
-
@{
-
Layout
= null;
-
}
-
-
<!DOCTYPE html>
-
-
<html>
-
<head>
-
<meta name="viewport"
content="width=device-width" />
-
<title>Index</title>
-
</head>
-
<body>
-
-
<h3>LIST OF COURSES</h3>
-
<br
/>
-
<b>STRUCTURE OF PROGRAMMING</b>
-
<ol>
-
@{
-
//CODING FOR C#
-
-
foreach(var course1 in
TempData["Courses"]as List <string>)
-
{
-
-
<li>@course1</li>
-
}
-
-
-
}
-
</ol>
-
</body>
-
</html>
Comments
Post a Comment