Grid View[Bound Field and Template Field ]

Grid view is a data control.

It is used to display the records.

Grid View has two properties-

1. Data Source(it always equals to dr[datareader] )

2. Data Bind 

How to insert Grid view in our project- 

1. Select Grid view from toolbox (in data tools) 

2. Select Grid View > Master tag  

3. Select Auto format (can select the desired format) 

Bound Field- 

It is used to connect the database column to Grid View.

Bound field has two properties-

1. Header text(give the column name which will be displayed in the grid view ..Not mandatory to give the column name as same as the data base column )

2. Data field(Mandatory to give the name as same as database column ) 


How to insert bound field- 

Steps- 

Select grid view >Master tag >Edit columns >Select bound field >Click on add.

then- 

fill the data field and header text. 

Note:- Unchecked the auto generate check box.


How to show the data base records in Grid View-

Select a Button > change text property to display > Double click on it. 

CODE-

{

string k = @"path";

cn = new SqlConnection(k); 

cn.Open();


string q = "select * from Table_name "; 

cm = new SqlCommand(q,cn); 

dr = cm.ExecuteReader(); 

GridView1.DataSource = dr;

GridView1.DataBind();


Template Field-

It is used to connect controls with the Grid view.

It has only one property-

Header Text.

 

How to insert Template field in data Grid view- 

Steps- 

Select the Grid View > master tag > Edit columns > Select Template Field > fill the Header text > Set the position of template in the grid view > ok  


How to insert control in Grid view- 

Steps- 

Select the Grid View > Go to source > Put the cursor in between the Template Field > Create an Item Template tag > Put the cursor in between > Select a control from toolbox.







 


Comments

Popular posts from this blog

Parameter Query

Final Project

Grid View Paging