I've created a Dynamic RadGrid on a Web User Control (ascx), and it displays correctly. However when I click on the Edit button the grid simply disappears. In order to determine what is going on I've tried to connect the OnItemCommand Event, but it does not fire? Listed below is a scaled version of the Dynamic Grid Creation, which is being executed by the PageInit Method.
My goal is to have the Edit Popup Modal show up when the User Clicks Edit, and be able to then catch the Update Click in order to manage the update back to the Data Source.
My goal is to have the Edit Popup Modal show up when the User Clicks Edit, and be able to then catch the Update Click in order to manage the update back to the Data Source.
protected void BuildGrid(DataRow curRow)
{
var curGrid = new RadGrid
{
ID = curRow.Field<
string
>("tst_desc"),
Skin = "Hay",
GridLines = GridLines.Both,
AutoGenerateColumns = false,
AllowAutomaticUpdates = true
};
curGrid.MasterTableView.Name = curRow.Field<
string
>("tst_desc");
curGrid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Bottom;
curGrid.MasterTableView.TableLayout = GridTableLayout.Fixed;
curGrid.MasterTableView.EditMode = GridEditMode.PopUp;
curGrid.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.AutoGenerated;
curGrid.MasterTableView.CommandItemSettings.ShowRefreshButton = false;
curGrid.MasterTableView.CommandItemSettings.AddNewRecordText = "Add More " + curRow.Field<
string
>("tst_desc") + " Test Results";
curGrid.NeedDataSource += new GridNeedDataSourceEventHandler(Grid_OnNeedDataSource);
curGrid.ItemCommand += new GridCommandEventHandler(Grid_OnItemCommand);
curGrid.ClientSettings.AllowKeyboardNavigation = true;
var btnCol = new GridButtonColumn
{
ButtonType = GridButtonColumnType.ImageButton,
HeaderText = "Edit",
CommandArgument = "btnEdit",
UniqueName = "btnEdit",
CommandName = "Edit"
};
curGrid.MasterTableView.Columns.Add(btnCol);
var gbcUpdBy = new GridBoundColumn
{
UniqueName = "UPDT_BY",
HeaderText = "Last Updated By",
DataField = "updt_by",
ReadOnly = true
};
curGrid.MasterTableView.Columns.Add(gbcUpdBy);
var gbcUpdDt = new GridBoundColumn
{
UniqueName = "UPDT_DT",
HeaderText = "Last Updated",
DataField = "updt_dt",
DataFormatString = "{0:MM/dd/yy}",
ReadOnly = true
};
curGrid.MasterTableView.Columns.Add(gbcUpdDt);
PlaceHolder1.Controls.Add(curGrid);
Session[curRow.Field<
string
>("tst_desc") + "ID"] = curRow.Field<
int
>("lab_tst_id").ToString(CultureInfo.InvariantCulture);
PlaceHolder1.Controls.Add(new LiteralControl("<
br
/>"));
PlaceHolder1.Controls.Add(new LiteralControl("<
br
/>"));
}
void Grid_OnItemCommand(object sender, GridCommandEventArgs e)
{
var a = 123;
}
void Grid_OnNeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
var curGrid = sender as RadGrid;
var gridName = curGrid.MasterTableView.Name;
var hidTestId = Session[gridName + "ID"];
curGrid.DataSource = ExecSQL.SQLData(_sqlStmt + " AND lt.lab_tst_id = " + hidTestId);
}