Hello
I want to generate Radgrid templates column Dynamically on button click event.
as shown in images attached below Edit ,Delete and ProductNames columns are Fixed
I just want to add Country Column dynamically on AddCountry Button click
Using the following code the new column gets added but the previous column gets deleted , I want to maintain the previous column and the values in it
as shown it attached images
Please check if I am missing any thing in the code below
thanks
waiting for reply
Kishor
Dim
objProductDataTable
As
New
tblProductDataTable
Dim
objProductTableAdapter
As
New
tblProductTableAdapter
Private
Class
MyTemplate
Implements
ITemplate
Protected
textBox
As
TextBox
Private
colname
As
String
Public
Sub
New
(
ByVal
cName
As
String
)
MyBase
.
New
()
colname = cName
End
Sub
Public
Sub
InstantiateIn(
ByVal
container
As
System.Web.UI.Control)
Implements
ITemplate.InstantiateIn
textBox =
New
TextBox
textBox.ID =
"abc"
container.Controls.Add(textBox)
End
Sub
End
Class
Protected
Sub
btnAddCountry_Click(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
btnAddCountry.Click
objProductDataTable = objProductTableAdapter.GetProducts()
RadGrid1.DataSource = objProductDataTable
Dim
templateColumnName
As
String
=
"Col1"
Dim
templateColumn
As
New
GridTemplateColumn()
templateColumn.ItemTemplate =
New
MyTemplate(templateColumnName)
templateColumn.HeaderText = txtCountry.Text
templateColumn.ItemStyle.Font.Bold =
True
templateColumn.HeaderStyle.Font.Bold =
True
RadGrid1.MasterTableView.Columns.Add(templateColumn)
RadGrid1.DataBind()
For
i = 0
To
objProductDataTable.Rows.Count - 1
Dim
lbl
As
Label =
DirectCast
(RadGrid1.Items(i).FindControl(
"lblproduct"
), Label)
lbl .Text = objProductDataTable.Rows(i).Item(
"ProductName"
)
Next
End
Sub