Link to home
Start Free TrialLog in
Avatar of xtremereality
xtremerealityFlag for United Kingdom of Great Britain and Northern Ireland

asked on

gridview and controls on the fly

Hi Experts,
how can i create a gridview by code and put inside a control created on the fly as well?

for istance i wanna have a gridview with 3 image controls inside created by code (not in design mode).

Thanks
ASKER CERTIFIED SOLUTION
Avatar of crazyman
crazyman
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of xtremereality

ASKER

Sorry can you provide me an example as i tried the links you gave me but i get some errors.
this is the class that implements ITemplate, i get some errors on the points with the arrows.
see below

public class GridViewTemplate : System.Web.UI.Page, ITemplate
{
ListItemType _templateType;
string _columnName;


public GridViewTemplate(ListItemType type, string columnName)
{
_templateType = type;
_groupName = columnName;
}


public void InstantiateIn(System.Web.UI.Control container)
{

switch (_templateType)
{

case ListItemType.Header:

break;

case ListItemType.Item:

Literal lc = new Literal();

lc.DataBinding += new EventHandler(this.lc_DataBinding);

container.Controls.Add(lc);

break;

case ListItemType.EditItem:

break;

case ListItemType.Footer:

break;

}
}


private void lc_DataBinding(Object sender, EventArgs e)
{

Literal lc = (Literal)sender;

GridViewRow row = (GridViewRow)lc.NamingContainer;

string propertyValue =  <------------------------------------------------------------ Get error here
DataBinder.Eval(row.DataItem, "PropertyName").ToString(); <--------------- And here

lc.Text = propertyValue;

}
}