Hello,
I am creating a dynamic RadGrid completely in the code. I am adding the buttons for ItemTemplates and EditItemTemplates for the Editing the controls. I am creating this in the Page_Init function.
The controls binds fine and displays the data and "Edit Button". But the problem is that when I click on the "Edit" button, the "ItemCommand" event does not fires for the grid and The grid is not displayed in edit mode. The Page only postback to the server and binds the grid again. But if i click on the "Delete" button, which is "BoundColumn", it does fire the "ItemCommand" event for the grid. What point I may be missing here ?
Following is the code for it :
I am creating a dynamic RadGrid completely in the code. I am adding the buttons for ItemTemplates and EditItemTemplates for the Editing the controls. I am creating this in the Page_Init function.
The controls binds fine and displays the data and "Edit Button". But the problem is that when I click on the "Edit" button, the "ItemCommand" event does not fires for the grid and The grid is not displayed in edit mode. The Page only postback to the server and binds the grid again. But if i click on the "Delete" button, which is "BoundColumn", it does fire the "ItemCommand" event for the grid. What point I may be missing here ?
Following is the code for it :
public class ItemTemplateLinks : ITemplate
{
protected RadButton rBtn;
string colname = string.Empty;
string colValue = string.Empty;
public ItemTemplateLinks(string cName)
{
colname = cName;
}
public void InstantiateIn(System.Web.UI.Control container)
{
rBtn = new RadButton();
rBtn.Text = "Edit";
rBtn.ButtonType = RadButtonType.StandardButton;
rBtn.Command += new CommandEventHandler(rBtn_Command);
rBtn.CommandName = "Edit";
Random rnd = new Random();
rBtn.ID = "test";
container.Controls.Add(rBtn);
}
void rBtn_Command(object sender, CommandEventArgs e)
{
string a = (sender as RadButton).CommandName;
}
}
public class EditItemTemplateLinks : IBindableTemplate
{
ListItemType lstItemType;
protected RadButton rBtn;
string colname = string.Empty;
string btnText = string.Empty;
string cmdName = string.Empty;
string colValue = string.Empty;
public EditItemTemplateLinks(string cName, string bText, string bCmdName)
{
btnText = bText;
bCmdName = cmdName;
colname = cName;
}
public void InstantiateIn(System.Web.UI.Control container)
{
rBtn = new RadButton();
rBtn.Text = "Update fire";
rBtn.ButtonType = RadButtonType.StandardButton;
rBtn.CommandName = "Update";
rBtn.Command += new CommandEventHandler(rBtn_Command);
Random rnd = new Random();
rBtn.ID = "ssss";
container.Controls.Add(rBtn);
}
void rBtn_Command(object sender, CommandEventArgs e)
{
string a = (sender as RadButton).CommandName;
}
public IOrderedDictionary ExtractValues(Control container)
{
OrderedDictionary od = new OrderedDictionary();
return od;
}
}
RadGrid RadGrid1 = new RadGrid();
RadGrid1.NeedDataSource += new GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource); RadGrid1.ItemCommand += new GridCommandEventHandler(RadGrid1_ItemCommand); RadGrid1.ItemCreated += new GridItemEventHandler(RadGrid1_ItemCreated); RadGrid1.ID = "rgDemo"; RadGrid1.Width = Unit.Percentage(100); RadGrid1.PageSize = 5; RadGrid1.AllowPaging = true; RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric; RadGrid1.AutoGenerateColumns = false; RadGrid1.GroupingEnabled = true; RadGrid1.ShowGroupPanel = true; RadGrid1.ShowStatusBar = true; RadGrid1.ClientSettings.AllowDragToGroup = true; RadGrid1.MasterTableView.PageSize = 15; RadGrid1.MasterTableView.DataKeyNames = new string[] { "ID" }; RadGrid1.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.Template; RadGrid1.MasterTableView.EditMode = GridEditMode.InPlace; GridTemplateColumn gtc = new GridTemplateColumn(); gtc.ItemTemplate = new ItemTemplateLabels("Description"); gtc.HeaderText = "Description"; gtc.EditItemTemplate = new EditItemTemplateTextBoxes("Description"); RadGrid1.MasterTableView.Columns.Add(gtc); GridTemplateColumn gt2 = new GridTemplateColumn(); gt2.ItemTemplate = new ItemTemplateLabels("Name"); gt2.HeaderText = "Name"; gt2.EditItemTemplate = new EditItemTemplateTextBoxes("Name"); RadGrid1.MasterTableView.Columns.Add(gt2); GridTemplateColumn gt3 = new GridTemplateColumn(); gt3.ItemTemplate = new ItemTemplateLinks("Links"); gt3.UniqueName = "EditCommandColumn"; gt3.HeaderText = "Links"; gt3.EditItemTemplate = new EditItemTemplateLinks("Links", "Update", "Update"); RadGrid1.MasterTableView.Columns.Add(gt3); GridButtonColumn gBtnColumn = new GridButtonColumn(); gBtnColumn.CommandName = "Delete"; gBtnColumn.Text = "Delete"; gBtnColumn.ButtonType = GridButtonColumnType.LinkButton; RadGrid1.MasterTableView.Columns.Add(gBtnColumn);