Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
425
Webdatagrid ItemTemplate error
posted

hi , 

iam adding an itemtemplate in the grid the contain the edit and delete buttons with 

TemplateDataField field1 = new TemplateDataField();
field1.Key = "TemplateColumn1";
field1.Header.Text = "Edition ";
this.WebDataGrid1.Columns.Add(field1);
//get reference to the template column
TemplateDataField templateColumn1 = (TemplateDataField)this.WebDataGrid1.Columns["TemplateColumn1"];
templateColumn1.ItemTemplate = new CustomItemTemplate();

and 

private class CustomItemTemplate : ITemplate
{
#region ITemplate Members

public void InstantiateIn(Control container)
{

Button edit = new Button();
edit.CssClass = "Button";
edit.Text = "Modifier";
edit.OnClientClick = "return editRow()";

Button delete = new Button();
delete.CssClass = "Button";
delete.Text = "Supprimer";
delete.OnClientClick = "return deleteRow()";

container.Controls.Add(edit);
container.Controls.Add(delete);
}

#endregion
}

but i get in this.WebDataGrid1.Columns.Add(field1); line when i clique any button

Key:TemplateColumn1 must be unique. The field objects in the grid must have non-empty unique keys assigned to the Key property.

to put this another way how to do this in codebehind

 

<Columns>
                        <ig:TemplateDataField  Key="TemplateColumn0">
                            <Header Text="Edition HTML"></Header>
                            <ItemTemplate>

                                <asp:Button ID="Buttonedit" runat="server" Text="Edit HTML" onclientclick="eturn editRow();" />

                                <asp:Button ID="Buttondelete" runat="server" Text="Delete HTML" onclientclick="return deleteRow();" />

                            </ItemTemplate>
                        </ig:TemplateDataField>
                    </Columns>

Top Replies