I have a need to programmatically create a RadGrid based on the number of elements from another table. So I have the following:
foreach (DataRow customerRow in dtDistinctMonitors.Rows)
{
//Get Data
DataRow[] rowData = dtMonitors.Select("tenantID = '" + tenantID + "'");
//Add Label
Label lblName = new Label();
lblName.Text = "Channel: xxxx";
lblName.Font.Size = FontUnit.Large;
PlaceHolder1.Controls.Add(lblName);
//Add RadGrid
RadGrid RadGrid1 = new RadGrid();
RadGrid1.ID = customerRow["channelID"].ToString();
//Add RadGrid to the Controls collection of the placeholder
PlaceHolder1.Controls.Add(RadGrid1);
RadGrid1.DataSource = rowData;
RadGrid1.MasterTableView.DataKeyNames = new string[] { "monitorID" };
RadGrid1.AllowPaging = false;
RadGrid1.MasterTableView.AutoGenerateColumns = false;
RadGrid1.Skin = "Silk";
RadGrid1.RenderMode = RenderMode.Lightweight;
RadGrid1.Width = Unit.Percentage(100);
GridBoundColumn boundColumn;
boundColumn = new GridBoundColumn();
RadGrid1.MasterTableView.Columns.Add(boundColumn);
boundColumn.DataField = "monitorName";
boundColumn.HeaderText = "Monitor Name";
GridButtonColumn buttonColumn;
buttonColumn = new GridButtonColumn();
buttonColumn.Text = "Delete";
buttonColumn.ButtonType = GridButtonColumnType.LinkButton;
buttonColumn.HeaderStyle.Width = Unit.Pixel(100);
buttonColumn.CommandArgument = "monitorID";
buttonColumn.CommandName = "lnkDelete_Command";
RadGrid1.MasterTableView.Columns.Add(buttonColumn);
}
And below I have lnkDelete_Command as:
public void lnkDelete_Command(object sender, CommandEventArgs e)
{
using (SqlConnection sqlConn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["stringvalue"].ConnectionString))
{
string ID = e.CommandArgument.ToString();
//DELETE FROM WHERE ID = ID
}
}
Yet, when I click on the LinkButton created it doesn't fire. It doesn't really do anything at all but creates a second instance of the button. Am I missing something simple here?