An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. |
|
I want to attach a right context menu to a RadGrid . I followed the instruction in the article:
As my data source is a collection, I have to handle the RadGrid1_InsertCommand to insert the new record into database.
But after update database, how can I turn off the grid insert mode? I put
RadGrid1.MasterTableView.IsItemInserted = false; in the RadGrid1_InsertCommand, but I received a exception:
Insert item is available only when grid is in insert mode.
protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
// get sort order
RadNumericTextBox txtSortOrder =
editedItem.FindControl("RadNumericTextBox_SortOrder") as RadNumericTextBox;
int sortOrder = -1;
Int32.TryParse(txtSortOrder.ValidationText, out sortOrder);
// InsertIntoDatabase()
…
//exception: Insert item is available only when grid is in insert mode.
RadGrid1.MasterTableView.IsItemInserted = false;
}
protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
// get category Id
Label lblId = editedItem.FindControl("lblId") as Label;
int categoryId = 0;
Int32.TryParse(lblId.Text, out categoryId);
if (0 == categoryId) return;
// update database
…
//works fine
RadGrid_Categories.EditIndexes.Clear();
}
protected void RadContectMenu1_ItemClick(object sender, Telerik.Web.UI.RadMenuEventArgs e)
{
int iClickedRowIndex;
bool convertResult = Int32.TryParse(Request.Params["ClickedRowIndex"], out iClickedRowIndex);
if (!convertResult) return;
string clickedCommand = e.Item.Text;
switch (clickedCommand)
{
case "Insert":
RadGrid1.MasterTableView.IsItemInserted = true;
RadGrid_Categories.Rebind();
break;
case "Edit":
RadGrid1.Items[iClickedRowIndex].Edit = true;
RadGrid_Categories.Rebind();
break;
}
}
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
GridColumn col = (GridColumn)RadGrid1.MasterTableView.GetColumn("EditCommandColumn");
if (RadGrid_Categories.EditIndexes.Count > 0 || RadGrid_Categories.MasterTableView.IsItemInserted )
{
col.Visible = true;
}
else
{
col.Visible = false;
}
}
| <script language="javascript"> |
| //the purpose of this script is to suppress the Exit confirmation message in IE |
| //for the sort links. problem appears in IE only. appears in footer so that it |
| //will execute again when a postback occurs in the grid |
| var links = document.getElementsByTagName("a"); |
| alert("found links"); |
| for (var i=(links.length-1); i>=0; i--) |
| { |
| if (links[i].getAttribute("title") == "Click here to sort") |
| { |
| alert("found a sort button"); |
| var cmd = links[i].getAttribute("href").replace("javascript:", ""); |
| links[i].onclick = function () { |
| suppressConfirmation(); |
| eval(cmd); |
| return false; |
| } |
| } |
| } |
| </script> |
An unhandled exception was generated during |
| Me.RadToolBar1.Items(1).Attributes.Add("onclick", "if(!confirm('Are you sure you want to delete this item?')) return false;") |