0% found this document useful (0 votes)
33 views14 pages

Customizing The Datagrid To Project The Selected Columns

This document provides steps for customizing a DataGrid control in ASP.NET to perform various functions including selecting columns, adding sorting functionality, inserting/deleting/updating records using a disconnected data model, and adding buttons for edit, update, cancel, delete, and select operations. The steps include setting properties in the property builder, binding datasets and data members, and handling button click events.

Uploaded by

Fenil Desai
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views14 pages

Customizing The Datagrid To Project The Selected Columns

This document provides steps for customizing a DataGrid control in ASP.NET to perform various functions including selecting columns, adding sorting functionality, inserting/deleting/updating records using a disconnected data model, and adding buttons for edit, update, cancel, delete, and select operations. The steps include setting properties in the property builder, binding datasets and data members, and handling button click events.

Uploaded by

Fenil Desai
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 14

Customizing the DataGrid to

project the selected columns


 This is being done after binding the dataset
and the datamember to the datagrid control.
 The 2nd way 
 View 
 Server Explorer 
 Connection Name 
 Tables 

 TableName  (drag the table name to the form it will

create the connection and the data adapter]


 Right click on the datagrid control and select
property builder and click on columns tab.
 Uncheck “Create Column automatically at
runtime” checkbox
Customizing the DataGrid to
project the selected columns
(2)
 Select the column names from the available
column list and pass the columns to the selected
column list as per the requirement.
 To set the Column Header for the selected
columns select the column name from the
selected columns list and set the header Text
Property for that columns.
 After that write the code in the page_load
 OracleDataAdapter1.fill(dataset11,”emp”)
 Datagrid.databind()
{see example}
Customizing the DataGrid to
Support Sort Functionality
 Steps to do after generating the dataSet 
 Click on the data tab present in the tool box and
place the data view control on the form.
 Set the table properties for the dataview control
with the data member name present in the dataset.
 Place the datagrid control on the form and set the
DataSource value on the dataview name.
 Allow Sorting = True
Steps to Insert a record using
the Disconnected Model
 Define a datarow.
 Syntax  dim row as datarow.
 Bind the newRow of the datamember of
DataSet to the datarow variable.
 Syntax  row =
datasetName.DataMemberName.NewRow()
 Assign the Values to the datacolumns of the
datarow
 Syntax  row(columnIndex / ColumnName) =
value
Steps to Insert a record using the
Disconnected Model (2)
 Add the Datarow variable to the datarow
collection of the datamembers of dataset.
 Syntax 
datasetName.DataMemberName.Rows.add
(Row)
 Update the DataAdapter with the data
present in the datamember of the dataset
 Syntax 
 dataAdapterName.Update(datasetName,[data
memberName])
Steps to delete a record
using Disconnected Model
 Delete the datarow from the datamember of
the dataset
 Syntax
 Datasetname.datamembername.rows(row
index).delete()
 And then update the record.
Steps to customize the datagrid
control to provide the delete option
 Right click on the datagrid control and select property
builder and click on columns tab.
 Then uncheck create controls automatically at runtime
checkbox.
 Select the column(s) to be projected from the available
column(s) list and pass it to the selected column(s) list
and set the header text for those columns.
 Expand the button column node present in the available
coulmns list and pass the delete node to the selected
coulmns list
 By default the delete option button type will be a link
button to have the style as push button then set the
button type property for the delete node.
 When ever the user clicks on the delete button then it
fires an event called as “DeleteCommand”.
For Delete Option
 When ever the user clicks on the delete button
then it fires an event called as
“DeleteCommand”.
DEPTNO DEPTNAME

DeleteCommand(sender,e)
0 DELETE

1 DELETE

e.item.itemIndex  returns the indexno


of the row selected by the user
Steps to Update the record using the
disconnected Model
 Step 1 define the datarow
 Syntax  dim row as datarow
 Assign the datarow to the modified at the datamember of
the dataset to the datarow variable
 Syntax 
row=
datasetname.datamembername.rows(rowIndex)
 Convert the selectedmode of the datarow variable to the
edit mode such the manipulations can be performed on
the datacolumns of the datarow variable.
 Syntax  row.beginEdit()
 Assign the values to the data columns to be modified in
the datarow.
 Syntax  row(column Index / Column Name) =
value
 End the edit mode.
 Syntax  row.endEdit()
Datagrid Control

Header template
Item template

Alternating Item template


Selected Item template

Edit Item template

Footer template
Steps to customize the datagrid control to
provide update operation:
 To do after the binding the dataset and
datamember to the datagrid control.
 Right click on the datagrid control and click on the
property builder and click on the columns tab.
 Uncheck “create columns automatically at
runtime” check box.
 Select the columns to be projected from the
available columns list and pass it on to the
selected columns list and set their header Text
property.
 Expand the button column node from the available
columns list and pass the edit,update,cancel node
to the selected columns list.
Tablecell / Cells(0)/controls(0) Controls(1) Controls(2) EditItemIndex = rowIndex(-1)

DeptNo DeptName Loc


10 SALES HYD EDIT
0

20 Marketing BANG
1 UPDATE CANCEL

e.item.itemIndex  returns the indexno


of the row selected by the user
Steps to customize the datagrid control to
provide update operation
 (Optional) If any columns has to be set as readonly such that
no manipulations has to be performed then select the column
name from the selected columns list and check ReadOnly
CheckBox.
 To extract the value from the table cell
 Variable = ctype(e.item.controls(index),controltype).propertyName
 to extract the value from the control present in the table cell 
 Variable =
ctype (e.items.controls(index).controls(0),controltype).propertyname
Customizing the datagrid control to
provide selection option
 To do after passing the columns from the
available columns list to the selected
columns list.
 Expand the button column node from the
available columns list and pass the select
node to the selected columns list.

You might also like