HI,
I have a DataTable with Customer Data. I'm binding rad grid dynamically, because upton 3rd column, datatable has static columns after that from 4th columns all columns are Dynamic, so for that I've designed rad grid in dynamic binding and also binded column with Edit and Delete buttons. But the rad grid control item command event is not firing. Below is my code
and ITemplate Class
Help me in this regards with making my rad grid fire item command.
Regards
Phaneendra
I have a DataTable with Customer Data. I'm binding rad grid dynamically, because upton 3rd column, datatable has static columns after that from 4th columns all columns are Dynamic, so for that I've designed rad grid in dynamic binding and also binded column with Edit and Delete buttons. But the rad grid control item command event is not firing. Below is my code
void
BindsGrid(
int
pageIndex = 0)
{
SetupTableService pgs =
new
SetupTableService();
DataTable dt = pgs.ExportFuelGrade(SupplierId);
int
i = 0;
if
(gvFuelsGrades.MasterTableView.Columns.Count > 0)
{
gvFuelsGrades.MasterTableView.Columns.Clear();
gvFuelsGrades.DataSource =
null
;
gvFuelsGrades.DataBind();
}
foreach
(DataColumn col
in
dt.Columns)
{
GridBoundColumn boundCol =
new
GridBoundColumn();
string
column =
string
.Format(
"{0}"
, dt.Columns[i].ColumnName);
boundCol.DataField = column;
boundCol.HeaderText = column;
// templateCol.UniqueName = column.Replace(" ", string.Empty);
gvFuelsGrades.MasterTableView.DataKeyNames =
new
string
[] {
"FuelId"
};
boundCol.ItemStyle.Width = Unit.Pixel(500);
boundCol.ItemStyle.Wrap =
true
;
if
(boundCol.HeaderText ==
"FuelId"
|| boundCol.HeaderText ==
"OilGrade"
|| boundCol.HeaderText ==
"FuelGradeId"
|| boundCol.HeaderText ==
"ProductGroupId"
)
boundCol.Visible =
false
;
gvFuelsGrades.MasterTableView.Columns.Add(boundCol);
i++;
}
gvFuelsGrades.ClientIDMode = System.Web.UI.ClientIDMode.Static;
gvFuelsGrades.CurrentPageIndex = pageIndex;
gvFuelsGrades.AllowPaging =
true
;
gvFuelsGrades.Width = Unit.Pixel(1000);
gvFuelsGrades.DataSource = dt;
gvFuelsGrades.DataBind();
//(gvFuelsGrades.MasterTableView.GetColumn("Actions") as GridTemplateColumn).OrderIndex = gvFuelsGrades.Columns.Count+1;
GridTemplateColumn templateCol =
new
GridTemplateColumn();
templateCol.ItemTemplate =
new
GridActionTemplate(
"Actions"
);
templateCol.HeaderText =
"Actions"
;
templateCol.OrderIndex = gvFuelsGrades.Columns.Count + 2;
gvFuelsGrades.MasterTableView.Columns.Add(templateCol);
gvFuelsGrades.Rebind();
//(gvFuelsGrades.MasterTableView.GetColumn("Actions") as GridTemplateColumn).Visible = CanEdit() | CanDelete();
}
and ITemplate Class
class
GridActionTemplate : ITemplate
{
public
event
CommandEventHandler Command;
private
void
OnCommand(CommandEventArgs e)
{
if
(Command !=
null
)
{
Command(
this
, e);
}
}
private
void
imgEdit_Command(
object
sender, GridCommandEventArgs e)
{
OnCommand(e);
}
public
void
InstantiateIn(System.Web.UI.Control container)
{
lControl =
new
LiteralControl();
lControl.ID =
"lControl"
;
imgEdit =
new
ImageButton();
imgEdit.CommandName =
"edit"
;
imgEdit.ID =
"btnEdit"
;
imgEdit.ImageUrl =
"~/Static/Images/Actions/edit.png"
;
imgDelete =
new
ImageButton();
imgDelete.CommandName =
"delete"
;
imgDelete.ImageUrl =
"~/Static/Images/Actions/delete.gif"
;
Table tbl =
new
Table();
TableRow tr =
new
TableRow();
TableCell td =
new
TableCell();
td.Controls.Add(imgEdit);
tr.Cells.Add(td);
td =
new
TableCell();
td.Controls.Add(imgDelete);
tr.Cells.Add(td);
tbl.Rows.Add(tr);
container.Controls.Add(imgEdit);
container.Controls.Add(imgDelete);
}
protected
LiteralControl lControl;
protected
ImageButton imgEdit;
protected
ImageButton imgDelete;
protected
ImageButton imgView;
private
string
colname;
public
GridActionTemplate(
string
cName)
{
colname = cName;
}
}
Help me in this regards with making my rad grid fire item command.
Regards
Phaneendra