hi all,
I need to bind xml data t rad grid view. Accoridng to the xml i want to set column dynamically So i need to create gridview column dynamically when click button for load xml. All columns working except command columns. For command column also i created template column with link buttons. But when i click the button command not initiating..
My staic declaration of RadGrid at initial:
My Code for Grid Generation
My Code for TemplateGeneration
I need to bind xml data t rad grid view. Accoridng to the xml i want to set column dynamically So i need to create gridview column dynamically when click button for load xml. All columns working except command columns. For command column also i created template column with link buttons. But when i click the button command not initiating..
My staic declaration of RadGrid at initial:
| <telerik:RadGrid ID="rad_grd_XmlGrid" runat="server" |
| AutoGenerateColumns="false" oncancelcommand="rad_grd_XmlGrid_CancelCommand" |
| oneditcommand="rad_grd_XmlGrid_EditCommand" |
| onitemcommand="rad_grd_XmlGrid_ItemCommand"> |
| </telerik:RadGrid> |
My Code for Grid Generation
| GridTemplateColumn tcol1 = new GridTemplateColumn(); |
| tcol1.HeaderText = "Name"; |
| tcol1.ItemTemplate = new DynamicTemplate(GridItemType.Item, "name", tcol1.DataType.ToString()); |
| tcol1.EditItemTemplate = new DynamicTemplate(GridItemType.EditItem, "name", tcol1.DataType.ToString()); |
| GridTemplateColumn tcol2 = new GridTemplateColumn(); |
| tcol2.HeaderText = "Modify"; |
| tcol2.ItemTemplate = new DynamicTemplate(GridItemType.Item, "..", "Command"); |
| tcol2.EditItemTemplate = new DynamicTemplate(GridItemType.EditItem, "..", "Command"); |
| grid.MasterTableView.Columns.Add(tcol1); |
| grid.MasterTableView.Columns.Add(tcol2); |
| DataSet ds = new DataSet(); |
| ds.ReadXml("c:\\Services.xml"); |
| grid.DataSource = ds; |
| grid.DataBind(); |
My Code for TemplateGeneration
| public class DynamicTemplate : ITemplate |
| { |
| GridItemType iType; |
| String fName; |
| String sinfo; |
| public DynamicTemplate(GridItemType itemType, String fieldName, String info) |
| { |
| iType = itemType; |
| fName = fieldName; |
| sinfo = info; |
| } |
| public void InstantiateIn(System.Web.UI.Control Container) |
| { |
| switch (iType) |
| { |
| case GridItemType.Header: |
| Literal header_ltrl = new Literal(); |
| header_ltrl.Text = "<b>" + fName + "</b>"; |
| Container.Controls.Add(header_ltrl); |
| break; |
| case GridItemType.Item: |
| switch (sinfo) |
| { |
| case "Command": |
| LinkButton edit_button = new LinkButton(); |
| edit_button.ID = "editButton"; |
| edit_button.CommandName = "Edit"; |
| //edit_button.Click +=new EventHandler(edit_button_Click); |
| edit_button.Text = "Edit"; |
| edit_button.ToolTip = "Edit"; |
| Container.Controls.Add(edit_button); |
| break; |
| default: |
| Label field_lbl = new Label(); |
| field_lbl.ID = fName; |
| field_lbl.DataBinding += new EventHandler(OnDataBinding); |
| Container.Controls.Add(field_lbl); |
| break; |
| } |
| break; |
| case GridItemType.EditItem: |
| if (sinfo == "Command") |
| { |
| LinkButton update_button = new LinkButton(); |
| update_button.ID = "updateButton"; |
| update_button.CommandName = "Update"; |
| update_button.Text = "Update"; |
| Container.Controls.Add(update_button); |
| LinkButton cancel_button = new LinkButton(); |
| cancel_button.ID = "cancelButton"; |
| cancel_button.CommandName = "Cancel"; |
| cancel_button.Text = "Cancel"; |
| cancel_button.ToolTip = "Cancel"; |
| Container.Controls.Add(cancel_button); |
| } |
| else |
| { |
| TextBox field_txtbox = new TextBox(); |
| field_txtbox.ID = fName; |
| field_txtbox.DataBinding += new EventHandler(OnDataBinding); |
| Container.Controls.Add(field_txtbox); |
| } |
| break; |
| } |
| } |
| //protected void edit_button_Click(Object sender, EventArgs e) |
| //{ |
| // new Page().Session["InsertFlag"] = 0; |
| } |
| private void OnDataBinding(object sender, EventArgs e) |
| { |
| switch (iType) |
| { |
| case GridItemType.Item: |
| Label field_ltrl = (Label)sender; |
| GridDataItem container = (GridDataItem)field_ltrl.NamingContainer; |
| field_ltrl.Text = DataBinder.Eval(container.DataItem, fName).ToString(); |
| break; |
| case GridItemType.EditItem: |
| TextBox field_txtbox = (TextBox)sender; |
| GridEditFormItem container1 = (GridEditFormItem)field_txtbox.NamingContainer; |
| field_txtbox.Text = DataBinder.Eval(container1.DataItem, fName).ToString(); |
| break; |
| } |
| } |
| } |
How can i trigger edit command?