GridView
Session 13-14
Objectives
• Introduction of DataSet
• Gridview control
• Several operation with GridView
DataSet Object
• Replaces the ADO Recordset
• Represents a cache of data that contains tables,
columns, relationships, and...
As revolutionary as a DataSet might be, it is not the
best choice in every situation. Often, using a DataSet
might not be ...
Gridview
• The GridView control is a powerful data grid control
that allows you to display an entire collection of
data,ad...
• Customizing Columns in the
GridView:
If you have your grid configured to automatically
generate columns based on the bou...
Field Control Description
BoundField Displays the value of a field in a data source. This is
the default column type of th...
Edit,Update,Delete Operation
in GridView
Event Generate Code
• GridView_course.RowDeleting += new
GridViewDeleteEventHandler(GridView_course_RowDe
leting);
• GridV...
RowCancelingEdit Event Execution
Code
• void GridView_course_RowCancelingEdit(object
sender, GridViewCancelEditEventArgs e...
RowEditing Event Execution
Code• void GridView_course_RowEditing(object sender,
GridViewEditEventArgs e)
• {
• GridView_co...
RowDeleting Event Execution Code
• void GridView_course_RowDeleting(object sender,
GridViewDeleteEventArgs e)
• {
• dcon.i...
RowUpdating Event Execution Code
• void GridView_course_RowUpdating(object sender,
GridViewUpdateEventArgs e)
• {
• TextBo...
• DataSet ds_Row = new DataSet();
• ds_Row = dcon.Data_inventer("Select
Subject as Subject,courseOffer as
Courses_Offer fr...
“FirstSample” is the key name in web config.
Now Connection open & close
• public SqlConnection open()
• {
• con_course.Op...
Simple code analysis
Creating a connection class:
Using system.Data.Sqlclient;
SqlConnection con_course;
• //Connection Es...
Insert Update Delete Command for
DataBase
• public void inupdl(string str)
• {
• SqlCommand comm = new SqlCommand();
• com...
Fill Datatable into DataSet From
DataBase
• public DataSet Data_inventer(string str)
{
SqlDataAdapter adpt_inven = new
Sql...
Execute statement
Default.aspx.cs page:
Create a object for connec class
 connec com_info = new connec();
Now run insert,...
Binding Data into Table
 GridView1.DataSource = ds;
 GridView1.DataBind();
Summery
• GridView Controls.
• Several Operation into Gridview Control.
• Connection with SQL.Server program and
execute S...
ASP.NET Session 13 14
ASP.NET Session 13 14
Upcoming SlideShare
Loading in...5
×

ASP.NET Session 13 14

299

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
299
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

ASP.NET Session 13 14

  1. 1. GridView Session 13-14
  2. 2. Objectives • Introduction of DataSet • Gridview control • Several operation with GridView
  3. 3. DataSet Object • Replaces the ADO Recordset • Represents a cache of data that contains tables, columns, relationships, and constraints, just like a database • Regardless of where the source data comes from, data can all be placed into DataSet objects • Tracks changes that are made to the data it holds before updating the source data.
  4. 4. As revolutionary as a DataSet might be, it is not the best choice in every situation. Often, using a DataSet might not be appropriate; instead, using a DataReader might be better. Because the DataSet is a disconnected copy of the data, you can work with the same records repeatedly without having to go back to the data store. This capability can greatly increase performance and lessen the load upon the server.
  5. 5. Gridview • The GridView control is a powerful data grid control that allows you to display an entire collection of data,add sorting and paging, and perform inline editing. • GridView by dragging the control onto the design surface of an ASP.NET Web page. • In column definition TemplateField &ItemTemplate we will insert any control .
  6. 6. • Customizing Columns in the GridView: If you have your grid configured to automatically generate columns based on the bound data source, the grid creates fields for each public property exposed by the data source.
  7. 7. Field Control Description BoundField Displays the value of a field in a data source. This is the default column type of the GridView control. CheckBoxField Displays a check box for each item in the GridView control. This column field type is commonly used to display fields with a Boolean value. HyperLinkField Displays the value of a field in a data source as a hyperlink. This column field type allows you to bind a second field to the hyperlink’s URL. ButtonField Displays a command button for each item in the GridView control. This allows you to create a column of custom button controls, such as an Add or Remove button. ImageField Automatically displays an image when the data in the field represents an image.
  8. 8. Edit,Update,Delete Operation in GridView
  9. 9. Event Generate Code • GridView_course.RowDeleting += new GridViewDeleteEventHandler(GridView_course_RowDe leting); • GridView_course.RowEditing += new GridViewEditEventHandler(GridView_course_RowEditi ng); • GridView_course.RowUpdating += new GridViewUpdateEventHandler(GridView_course_RowU pdating); • GridView_course.RowCancelingEdit += new GridViewCancelEditEventHandler(GridView_course_Ro wCancelingEdit);
  10. 10. RowCancelingEdit Event Execution Code • void GridView_course_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) • { • GridView_course.EditIndex = -1; • DataSet ds_Row = new DataSet(); • ds_Row = dcon.Data_inventer("Select Subject as Subject,courseOffer as Courses_Offer from Course order by Subject"); • GridView_course.DataSource = ds_Row; • GridView_course.DataBind(); • }
  11. 11. RowEditing Event Execution Code• void GridView_course_RowEditing(object sender, GridViewEditEventArgs e) • { • GridView_course.EditIndex = e.NewEditIndex; • DataSet ds_Row = new DataSet(); • ds_Row = dcon.Data_inventer("Select Subject as Subject,courseOffer as Courses_Offer from Course order by Subject"); • GridView_course.DataSource = ds_Row; • GridView_course.DataBind(); • • }
  12. 12. RowDeleting Event Execution Code • void GridView_course_RowDeleting(object sender, GridViewDeleteEventArgs e) • { • dcon.inupdl("delete from Course where Subject='" + GridView_course.Rows[e.RowIndex].Cells[3].Text + "'"); • DataSet ds_Row = new DataSet(); • ds_Row = dcon.Data_inventer("Select Subject as Subject,courseOffer as Courses_Offer from Course order by Subject"); • GridView_course.DataSource = ds_Row; • GridView_course.DataBind(); • }
  13. 13. RowUpdating Event Execution Code • void GridView_course_RowUpdating(object sender, GridViewUpdateEventArgs e) • { • TextBox T_Subject = (TextBox)GridView_course.Rows[e.RowIndex].Cells[ 3].Controls[0]; • TextBox T_CourseOff = (TextBox)GridView_course.Rows[e.RowIndex].Cells[ 4].Controls[0]; • dcon.inupdl("Update Course set courseOffer='" + T_CourseOff.Text + "' Where Subject='" + T_Subject.Text + "'");
  14. 14. • DataSet ds_Row = new DataSet(); • ds_Row = dcon.Data_inventer("Select Subject as Subject,courseOffer as Courses_Offer from Course order by Subject"); • GridView_course.DataSource = ds_Row; • GridView_course.EditIndex = -1; • GridView_course.DataBind(); • }
  15. 15. “FirstSample” is the key name in web config. Now Connection open & close • public SqlConnection open() • { • con_course.Open(); • return con_course; • } • public SqlConnection close() • { • con_course.Close(); • return null; • }
  16. 16. Simple code analysis Creating a connection class: Using system.Data.Sqlclient; SqlConnection con_course; • //Connection Establishment With siliguri DataBase • public SqlConnection Siliguri_conn() • { • con_course = new SqlConnection(ConfigurationManager.AppSettings["Fi rstSample"]); • return con_course; • }
  17. 17. Insert Update Delete Command for DataBase • public void inupdl(string str) • { • SqlCommand comm = new SqlCommand(); • comm.Connection = Siliguri_conn(); • comm.CommandText = str; • open(); • comm.ExecuteNonQuery(); • close(); • }
  18. 18. Fill Datatable into DataSet From DataBase • public DataSet Data_inventer(string str) { SqlDataAdapter adpt_inven = new SqlDataAdapter(str, Siliguri_conn()); • DataSet ds = new DataSet(); • adpt_inven.Fill(ds); • return ds; • }
  19. 19. Execute statement Default.aspx.cs page: Create a object for connec class  connec com_info = new connec(); Now run insert,Update & Delete command  com_info.inupdl("insert into TestValue values('" + TextBox1.Text + "','" + TextBox2.Text + "')"); Now retrieve data from Table:  DataSet ds=new DataSet();  ds. Data_inventer(“Select * From TestValue);
  20. 20. Binding Data into Table  GridView1.DataSource = ds;  GridView1.DataBind();
  21. 21. Summery • GridView Controls. • Several Operation into Gridview Control. • Connection with SQL.Server program and execute SQL command.
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×