Datagrid|datagrid tks!
A, Introduction
The DataGrid is located under the System.Web.UI.WebControls namespace, and when using this namespace, make sure you add System.Web.DLL this assemble (assembly) to the current project reference.
B, subject
In this article I will share some of my preliminary knowledge of the DataGrid with you and how to binding the CheckBoxList control in the DataGrid colums [and so on, you can easily bind other WebControls].
C, Some importants pionts
Events that must be understood:
Datagrid.itemdatabound: Occurs after data is bind
Several classes:
DataGridItem: Represents a row of data, while Datagrid.items is a collection of DataGridItem
TableCell: A cell that represents a table
DataGridItemEventArgs: Inheriting from EventArgs
D, to achieve
private void Datagrid1_itemdatabound (object sender, DataGridItemEventArgs e)
{
DataGridItem item = E.item; Gets the current line, that is, the DataGridItem
int id = Int. Parse (item. Cells[0]. Text); Get the database keyword for the related query, here I put an ID in the first column
CheckBoxList productslist; Declare a CheckBoxList variable
Productslist = new CheckBoxList (); Instance a CheckBoxList object
DataTable products = productaccessor.getproducts (ID); Querying the database based on the ID taken
for (int i = 0; I < products. Rows.Count; i++)
{
ListItem ListItem = new ListItem (); Declare and instance a ListItem
Listitem.value = products. Rows[i][0]. ToString ();
Listitem.text = products. ROWS[I][1]. ToString ();
if (products. ROWS[I][2]. ToString () = = "1")
Listitem.selected = true;
PRODUCTSLIST.ITEMS.ADD (ListItem); Add ListItem to the CheckBoxList.
}
Productslist.selectedindexchanged +=new EventHandler (productslist_selectedindexchanged);
Productslist.autopostback = true;
Item. CELLS[1]. Controls.Add (productslist); Add CheckBoxList to the second cell in the current row
}
}
E
At this point, we have finished adding CheckBoxList to the main work of the DataGrid, to see if our DataGrid has become more humane OH!!!
Gaga, if you have any questions about this article, you can qq25359952,i will VERY HAPPY to help Everyboy. Everybody progress together.