Tuesday, January 25, 2011

ASP.Net: Bind data into a template column

Suppost that we have a Grid View, with the property "AutoGenerateColumns" sat to false, when we declare a set of bound columns, it is easy to fill the data into the right column by giving each column the matching field name using the property "DataField". and just bind the data like this:

gridview1.DataSource = OurCollection
gridview1.DataBind()




But what if we needed to give a template column contains a check box or maybe a DropDownList a value from the database. in the same way. well no it is not so right to loop on each row and set the value manually.


the correct way is so simple just give the checked value a binded value like this:




Checked='< % # Bind("property or database field name") % > '

1 comment: