I'm using a LiteralControl to catch exception errors within the RadGrid. The literal control is added to the bottom of the page, and on a long list of items cannot be seen. Please let me know a setting to add the LiteralControl someplace toward the top of the grid and highlite the line in red. The following is my c# code.
try
{
BlowDownDataLayer.InsertBlowDownEvents(this.ToString(),
Int32.Parse(RadComboboxPlant.SelectedValue.ToString()),
Int32.Parse(RadComboboxEquip.SelectedValue.ToString()),
txtEventDesc.Text.ToString(),
Int32.Parse(RadComboboxBldGasType.SelectedValue.ToString()),
Int32.Parse((insertedItem["BlowDownEmissionColumn"].Controls[0] as RadNumericTextBox).Text.ToString()),
Int32.Parse((insertedItem["NumberofBlowdownEvents"].Controls[0] as RadNumericTextBox).Text.ToString()),
DateTime.Parse(EventdtTime.SelectedDate.ToString()));
}
catch (Exception ex)
{
GridBlowDown.Controls.Add(
new LiteralControl("Unable to insert Event. If the problem persists, please contact IT Service Center (x8765)."));
e.Canceled =
true;
}
thanks,
Minh Bui
8 Answers, 1 is accepted

One suggestion is to use CommandItemTemplate and set the message error accordingly. Here is a sample code for accessing commandItemtemplate control in an external button click.
C#:
protected
void
Button1_Click(
object
sender, EventArgs e)
{
GridCommandItem item = (GridCommandItem)gvViolation.MasterTableView.GetItems(GridItemType.CommandItem)[0];
Literal lit1=(Literal) item.FindControl(
"Literal1"
);
lit1.Text =
"Executed"
;
}
Currespondng aspx is:
<
CommandItemTemplate
>
<
asp:Literal
ID
=
"Literal1"
runat
=
"server"
></
asp:Literal
>
</
CommandItemTemplate
>
Thanks,
Shinu.

I might be missing something. I've implemented the code although didn't get any response. The following is my C# code
protected void GridWellVent_DeleteCommand(object sender, GridCommandEventArgs e)
{
GridDataItem item = (GridDataItem)e.Item;
try
{
string ResultID = item.OwnerTableView.DataKeyValues[item.ItemIndex]["_ResultsID"].ToString();
WellVentDataLayer.DeleteWellVentEvents(Int32.Parse(ResultID), this.ToString());
}
catch (Exception ex)
{
GridCommandItem Msg = (GridCommandItem)GridWellVent.MasterTableView.GetItems(GridItemType.CommandItem)[0];
Literal lit1 = (Literal)Msg.FindControl("Literal1");
lit1.Text = "Delete************** failed";
}
the following is my aspx code
<telerik:RadGrid ID="GridWellVent" GridLines="None" AutoGenerateColumns="False"
runat="server" AllowPaging="True" AllowSorting="True"
OnItemDataBound="OnItemDataBoundHandler"
ShowStatusBar="True" AllowFilteringByColumn="True"
CellSpacing="0" EnableAJAX="True" onneeddatasource="GridWellVent_NeedDataSource"
oninsertcommand="GridWellVent_InsertCommand"
onupdatecommand="GridWellVent_UpdateCommand"
ondeletecommand="GridWellVent_DeleteCommand" oninit="GridWellVent_Init"
onitemcreated="GridWellVent_ItemCreated" Width="1750px">
<MasterTableView ShowFooter="false" DataKeyNames="_ResultsID" EditMode="InPlace"
CommandItemDisplay="TopAndBottom" InsertItemDisplay="Top" InsertItemPageIndexAction="ShowItemOnFirstPage">
<CommandItemTemplate>
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
</CommandItemTemplate>
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>
<Columns>
<telerik:GridEditCommandColumn FooterText="EditCommand footer" UniqueName="EditCommandColumn"
HeaderText="Edit" HeaderStyle-Width="25px" UpdateText="Update" >
<HeaderStyle Width="25px" HorizontalAlign="Center" VerticalAlign="Middle"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</telerik:GridEditCommandColumn>
<telerik:GridButtonColumn HeaderText="Delete" CommandName="Delete" HeaderStyle-Width="25px" Text="Delete"
UniqueName="DeleteColumn" ConfirmText="Are you sure that you want to delete this event?" ConfirmTitle="Delete Confirmation" >
<HeaderStyle Width="25px" HorizontalAlign="Center" VerticalAlign="Middle"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</telerik:GridButtonColumn>
Your code is generally correct and there should not be any problems with it. My best suggestion is to verify with debugger, that you are entering the catch block.
Regards,
Andrey
the Telerik team

this is correct...the CommandItemTemplate work nicely.....there is a different problem though.
Before implementing the CommandItemTemplate, I was using the RadGrid's default new record insert (see insert.jpg)....After implementing the CommandItem Template, the RadGrid's default new record insert is missing (see MissingInsert.jpg)...please advise on a way to get it back.
thanks,
Minh Bui

This is the expected behaviour. CommandItemTemplate gets or sets the template that will be instantiated in the CommandItem. If this template is set, RadGrid will not create the default CommandItem controls.
Thanks,
Princy.

I'm only trying to put warning message on top of the grid..We'd like to keep the default CommandItem controls since there's a lot codes surrounding it.
we're only looking to make warning messages appear on the top of the grid during deletion, inserting and updating of events...any simple solution is welcome...
thanks,
Minh Bui

Please check below link.
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/commanditem/defaultcs.aspx
http://www.telerik.com/help/aspnet/grid/grdcommanditemtemplate.html
Thanks,
Jayesh Goyani
You could add a button to the CommandItemTemplate and set the "InitInsert" string to its CommandName property, thus you will get back the lost functionality. This way you could add other default buttons to the CommandItemTemplate.
So after modifying the code, your CommandItemTemplate should look something similar to this:
<
CommandItemTemplate
>
<
asp:Button
ID
=
"AddNewRecords"
runat
=
"server"
CommandName
=
"InitInsert"
Text
=
"Add New Record"
/>
<
asp:Literal
ID
=
"Literal1"
runat
=
"server"
></
asp:Literal
>
</
CommandItemTemplate
>
Regards,
Andrey
the Telerik team