This is a migrated thread and some comments may be shown as answers.

Place LiteralControl on top of the radgrid

8 Answers 259 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Minh
Top achievements
Rank 1
Minh asked on 19 Sep 2011, 07:46 PM
Hi,

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

Sort by
0
Shinu
Top achievements
Rank 2
answered on 20 Sep 2011, 07:09 AM
Hello Minh,

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.
0
Minh
Top achievements
Rank 1
answered on 20 Sep 2011, 04:38 PM
Hi,

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>

 

0
Andrey
Telerik team
answered on 21 Sep 2011, 01:32 PM
Hi Minh,

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
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Minh
Top achievements
Rank 1
answered on 21 Sep 2011, 02:31 PM
Hi,

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
0
Princy
Top achievements
Rank 2
answered on 21 Sep 2011, 03:08 PM
Hello Minh,

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.
0
Minh
Top achievements
Rank 1
answered on 21 Sep 2011, 03:30 PM
Hi,

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
0
Jayesh Goyani
Top achievements
Rank 2
answered on 21 Sep 2011, 07:39 PM
Hello,

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
0
Accepted
Andrey
Telerik team
answered on 21 Sep 2011, 10:01 PM
Hi Minh,

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
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Minh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Minh
Top achievements
Rank 1
Andrey
Telerik team
Princy
Top achievements
Rank 2
Jayesh Goyani
Top achievements
Rank 2
Share this question
or