ASP .NET DataGrid DropDown Column - DotNet Zone - DNzone.COM
Use the ASP DataGrid DropDownColumn to create a single selection drop-down list control in each cell of DataGrid column. You can control the appearance of the ASP DataGrid DropDownColumn by setting the BackColor, ForeColor, BorderColor, BorderStyle, and other properties. The control displays in a datagrid cell a single value that is selected from a collection by clicking the button of the control. Your user can enter text in the control if the string typed in matched an item in the collection to be accepted.

|
|
' Define DropDown variable as an object of DropDownColumn class
' and assign it to the DataGrid1 'State' column.
Dim DropDown As DropDownColumn = DataGrid1.Columns(5)
' Assign DataSource property for DropDown object as tblStates
' data table where states’s names are stored.
DropDown.DataSource = tblStates
' Specify DisplayMember as "Name" field of tblStates table
DropDown.DisplayMember = "Name"
' Specify ValueMember as "State" field of tblStates table
DropDown.ValueMember = "State"
' Identify "State" column's foreground color
DropDown.ForeColor = Color.DarkMagenta
' Identify "State" column characters' font and size
DropDown.Font_Name = "Tahoma"
DropDown.Font_Size = FontUnit.Point(8)
' Adjust 'State' column's width
DropDown.Width = Unit.Point(60)
C#
// Define DropDown variable as an object of DropDownColumn class
// and assign it to the DataGrid1 'State' column.
DropDownColumn DropDown = (DropDownColumn)DataGrid1.Columns[5];
// Assign DataSource property for DropDown object as tblStates
// data table where states’s names are stored.
DropDown.DataSource = tblStates;
// Specify DisplayMember as "Name" field of tblStates table
DropDown.DisplayMember = "Name";
// Specify ValueMember as "State" field of tblStates table
DropDown.ValueMember = "State";
// Identify "State" column's foreground color
DropDown.ForeColor = Color.DarkMagenta;
// Identify "State" column characters' font and size
DropDown.Font_Name = "Tahoma";
DropDown.Font_Size = FontUnit.Point(8);
// Adjust 'State' column's width
DropDown.Width = Unit.Point(60);
No comments:
Post a Comment