a problem on dynamic datagrid
-
Hi all, I have added linkbutton to the datagrid in the template column.i have to display particular field of datasource to the lnkbutton text.My code is like this this is a class file public class DataGridTempla :System.Web.UI.Page,ITemplate { ListItemType templateType; string columnName; public DataGridTempla( ListItemType type,string colname) { templateType = type; columnName = colname; } public void InstantiateIn(System.Web.UI.Control container) { Literal lc = new Literal(); LinkButton lb = new LinkButton(); lb.Click+=new EventHandler(lb_Click); case ListItemType.Item: lc.Text=columnName; lc.Text = "Select " + columnName; lb.CommandName = "EditButton"; lb.Text= "" + columnName + ""; //container.Controls.Add(chkb); container.Controls.Add(lb); container.Controls.Add(lc); } this is my webform coding TemplateColumn tc=new TemplateColumn(); tc.ItemTemplate=new DataGridTempla(ListItemType.Item,"BrandId" ); BoundColumn bc=new BoundColumn(); bc.DataField="Brand_Name"; DataGrid1.Columns.AddAt(0,tc); DataGrid1.Columns.AddAt(1,bc); DataGrid1.DataBind(); please try this.
sivamyneni
-
Hi all, I have added linkbutton to the datagrid in the template column.i have to display particular field of datasource to the lnkbutton text.My code is like this this is a class file public class DataGridTempla :System.Web.UI.Page,ITemplate { ListItemType templateType; string columnName; public DataGridTempla( ListItemType type,string colname) { templateType = type; columnName = colname; } public void InstantiateIn(System.Web.UI.Control container) { Literal lc = new Literal(); LinkButton lb = new LinkButton(); lb.Click+=new EventHandler(lb_Click); case ListItemType.Item: lc.Text=columnName; lc.Text = "Select " + columnName; lb.CommandName = "EditButton"; lb.Text= "" + columnName + ""; //container.Controls.Add(chkb); container.Controls.Add(lb); container.Controls.Add(lc); } this is my webform coding TemplateColumn tc=new TemplateColumn(); tc.ItemTemplate=new DataGridTempla(ListItemType.Item,"BrandId" ); BoundColumn bc=new BoundColumn(); bc.DataField="Brand_Name"; DataGrid1.Columns.AddAt(0,tc); DataGrid1.Columns.AddAt(1,bc); DataGrid1.DataBind(); please try this.
sivamyneni
Siva Myneni wrote:
please try this.
Ok, I tried it, now what? First, as this is related to ASP.NET you might get a better response by posting it to that forum. Second, try using a template in the the aspx rather creating it in the code-behind
only two letters away from being an asset