F
Fao, Sean
I have a DataGrid that I'm adding CheckBox controls to at runtime (in
the code behind) and I'm not sure if I'm doing it correctly.
First of all, I noticed that the MyDataGrid.Columns.Add() method expects
a DataGridColumn so I instantiated an object of type TemplateColumn that
I had hoped I could add a CheckBox to. I soon discovered that the
ItemTemplate property of the TemplateColumn class returned an object
that had implemented the ITemplate interface and the CheckBox class did
not implement it out of the box.
From there, it meant that I would have to create a new class, which
inherited from CheckBox and implemented the ITemplate interface. I did
that and everything works (I have a CheckBox on my DataGrid), but it
seemed like the long way around and I figured there must be an easier
way. For example, how does ASP.NET add a CheckBox to a DataGrid if I
had just added it to my HTML? When I add a CheckBox in HTML, I never
have to implement the ITemplate interface --it appears that it happens
automatically. So what goes on behind the scenes that makes this possible?
As I said, I successfully added a CheckBox to my DataGrid; however, it
meant creating a new class, which I'd rather not use if it's possible.
Also, I'm having a strange issue come up that I think might be related
to my custom class.
What is the *proper* way to add a CheckBox to a DataGrid in code?
Thank you in advance,
the code behind) and I'm not sure if I'm doing it correctly.
First of all, I noticed that the MyDataGrid.Columns.Add() method expects
a DataGridColumn so I instantiated an object of type TemplateColumn that
I had hoped I could add a CheckBox to. I soon discovered that the
ItemTemplate property of the TemplateColumn class returned an object
that had implemented the ITemplate interface and the CheckBox class did
not implement it out of the box.
From there, it meant that I would have to create a new class, which
inherited from CheckBox and implemented the ITemplate interface. I did
that and everything works (I have a CheckBox on my DataGrid), but it
seemed like the long way around and I figured there must be an easier
way. For example, how does ASP.NET add a CheckBox to a DataGrid if I
had just added it to my HTML? When I add a CheckBox in HTML, I never
have to implement the ITemplate interface --it appears that it happens
automatically. So what goes on behind the scenes that makes this possible?
As I said, I successfully added a CheckBox to my DataGrid; however, it
meant creating a new class, which I'd rather not use if it's possible.
Also, I'm having a strange issue come up that I think might be related
to my custom class.
What is the *proper* way to add a CheckBox to a DataGrid in code?
Thank you in advance,