Telerik Forums
UI for ASP.NET AJAX Forum
4 answers
355 views
Normally, if I need a client-side reference to the grid's CommandItem, I wire up the Toolbar's OnClientLoad command and save the reference when that fires. Either that or use $find(...).

However, I find myself updating a page that used multiple instances of a user control that has a grid in it and i need to access the CommandItem for a grid when a row on the grid is selected, but for the life of me I can't find anything in the API that allows me to get at the CommandItem from, say, the OnRowSelecting event.

Is this possible?

--
Stuart
Stuart Hemming
Top achievements
Rank 2
 answered on 19 Mar 2012
3 answers
187 views
So I'm using a radgrid tied to an object data source see grid code below...

<tk:RadGrid ID="rgThreshold" runat="server" AllowPaging="True" Width="100%" PageSize="10" Skin="Black"
                    OnInsertCommand="rgThreshold_InsertCommand" OnDeleteCommand="rgThreshold_DeleteCommand" OnUpdateCommand="rgThreshold_UpdateCommand"
                    AutoGenerateColumns="False" AllowSorting="True" CellSpacing="0" OnNeedDataSource="rgThreshold_NeedDataSource" >
                    <PagerStyle Mode="NextPrevAndNumeric" />
                    <ValidationSettings EnableValidation="true" EnableModelValidation="true" CommandsToValidate="Insert,Edit" />
                    <MasterTableView CommandItemDisplay="Top" EditMode="EditForms" InsertItemDisplay="Top" AutoGenerateColumns="false" DataKeyNames="ThresholdID" EditFormSettings-EditColumn-ButtonType="ImageButton">
                        <CommandItemSettings AddNewRecordText="Add New Threshold" />
                        <Columns>
                            <tk:GridEditCommandColumn UniqueName="EditCommandColumn" ButtonType="ImageButton">
                                <ItemStyle CssClass="myImageButton" />
                            </tk:GridEditCommandColumn>
                            <tk:GridBoundColumn HeaderText="Threshold ID" DataField="ThresholdID" Display="false" UniqueName="ThresholdID" ReadOnly="true" />
                            <tk:GridTemplateColumn HeaderText="Threshold Number" DataField="ThresholdNumber" UniqueName="ThresholdNumber" SortExpression="ThresholdNumber" ColumnEditorID="ThresholdNumberEditor" HeaderStyle-Width="150px" >
                                <ItemTemplate>
                                    <%# Eval("ThresholdNumber") %>
                                </ItemTemplate>
                                <InsertItemTemplate>
                                    <tk:RadNumericTextBox ID="tbThresholdNumber" runat="server" Value="5" DbValue='<%# Bind("ThresholdNumber") %>' Width="50px" ShowSpinButtons="true" NumberFormat-DecimalDigits="0" />
                                    <asp:RequiredFieldValidator ID="rfvThresholdNumber" runat="server" ControlToValidate="tbThresholdNumber" Text="Threshold Number is Required." InitialValue="" Display="Dynamic" CssClass="Validator" />
                                </InsertItemTemplate>
                                <EditItemTemplate>
                                    <tk:RadNumericTextBox ID="tbThresholdNumber" runat="server" DbValue='<%# Bind("ThresholdNumber") %>' Width="50px" ShowSpinButtons="true" NumberFormat-DecimalDigits="0" />
                                    <asp:RequiredFieldValidator ID="rfvThresholdNumber" runat="server" ControlToValidate="tbThresholdNumber" Text="Threshold Number is Required." InitialValue="" Display="Dynamic" CssClass="Validator" />
                                </EditItemTemplate>
                            </tk:GridTemplateColumn>
                            <tk:GridTemplateColumn HeaderText="Threshold Name" DataField="ThresholdName" UniqueName="ThresholdName" ColumnEditorID="ThresholdNameEditor" HeaderStyle-Width="300px">
                                <ItemTemplate>
                                    <%# Eval("ThresholdName") %>
                                </ItemTemplate>
                                <InsertItemTemplate>
                                    <tk:RadTextBox ID="tbThresholdName" runat="server" Text='<%# Bind("ThresholdName") %>' Width="500px" MaxLength="100" />
                                    <asp:RequiredFieldValidator ID="rfvThresholdName" runat="server" ControlToValidate="tbThresholdName" Text="Threshold Name is Required." InitialValue="" Display="Dynamic" CssClass="Validator" />
                                </InsertItemTemplate>
                                <EditItemTemplate>
                                    <tk:RadTextBox ID="tbThresholdName" runat="server" Text='<%# Bind("ThresholdName") %>' Width="500px" MaxLength="100" />
                                    <asp:RequiredFieldValidator ID="rfvThresholdName" runat="server" ControlToValidate="tbThresholdName" Text="Threshold Name is Required." InitialValue="" Display="Dynamic" CssClass="Validator" />
                                </EditItemTemplate>
                            </tk:GridTemplateColumn>
                            <tk:GridTemplateColumn HeaderText="Emails" DataField="Emails" UniqueName="Emails" ColumnEditorID="EmailsEditor" HeaderStyle-Width="400px">
                                <ItemTemplate>
                                    <%# Eval("Emails") %>
                                </ItemTemplate>
                                <InsertItemTemplate>
                                    <tk:RadTextBox ID="tbEmails" runat="server" Text='<%# Bind("Emails") %>' TextMode="MultiLine" Width="500px" Height="100px" MaxLength="2000" />
                                    <asp:RequiredFieldValidator ID="rfvEmails" runat="server" ControlToValidate="tbEmails" Text="Emails are Required." InitialValue="" Display="Dynamic" CssClass="Validator" />
                                </InsertItemTemplate>
                                <EditItemTemplate>
                                    <tk:RadTextBox ID="tbEmails" runat="server" Text='<%# Bind("Emails") %>' TextMode="MultiLine" Width="500px" Height="100px" MaxLength="2000" />
                                    <asp:RequiredFieldValidator ID="rfvEmails" runat="server" ControlToValidate="tbEmails" Text="Emails are Required." InitialValue="" Display="Dynamic" CssClass="Validator" />
                                </EditItemTemplate>
                            </tk:GridTemplateColumn>
                            <tk:GridTemplateColumn HeaderText="CC Emails" DataField="AdminEmails" UniqueName="AdminEmails" ColumnEditorID="AdminEmailsEditor" HeaderStyle-Width="400px">
                                <ItemTemplate>
                                    <%# Eval("AdminEmails") %>
                                </ItemTemplate>
                                <InsertItemTemplate>
                                    <tk:RadTextBox ID="tbAdminEmails" runat="server" Text='<%# Bind("AdminEmails") %>' TextMode="MultiLine" Width="500px" Height="100px" MaxLength="2000" />
                                </InsertItemTemplate>
                                <EditItemTemplate>
                                    <tk:RadTextBox ID="tbAdminEmails" runat="server" Text='<%# Bind("AdminEmails") %>' TextMode="MultiLine" Width="500px" Height="100px" MaxLength="2000" />
                                </EditItemTemplate>
                            </tk:GridTemplateColumn>
                            <tk:GridButtonColumn ConfirmText="Delete this Threshold (All Assignments will also be deleted)?" ConfirmDialogType="RadWindow" ConfirmTitle="Delete Threshold" CommandArgument="ThresholdID" CommandName="Delete" ConfirmDialogHeight="100px" ConfirmDialogWidth="220px" ButtonType="ImageButton" />
                        </Columns>
                        <EditFormSettings ColumnNumber="2" CaptionDataField="ThresholdName" CaptionFormatString="Edit: {0}">
                            <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>
                        </EditFormSettings>
                    </MasterTableView>
                </tk:RadGrid>
                <tk:RadWindowManager ID="RadWindowManager1" runat="server" Skin="Black" />
                <tk:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Black" />

The problem is it works great if at least one record exists but if I have a collection of object with count = 0 (no records) and I click the add new record button i get a:

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: DataBinding: 'Telerik.Web.UI.GridInsertionObject' does not contain a property with the name 'ThresholdName'.

What am I doing wrong?
Tsvetina
Telerik team
 answered on 19 Mar 2012
1 answer
141 views

Hi,

I am binding the radgrid using normal datasource and databind method.

the grid is getting filled with autogenerated columns. I have placed one checkbox which is in the grid, not auto generated.

Now, on post back usong any button in the page. the data in the viewstate also gets loaded. this creates addtional column. I did
radgrid.MasterTableView.Columns.Clear();

the reaction is, this will also remove the checkbox in the item template. I am not sure on how to add check box and header text box in the item template in radgrid programmatically. the example given in telerik site is not helpful.

http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html

I requrie a solution, on how to added a column which checkbox programmatically or

 

running this without touching template column or
prevent viewstate from acting on button postbacks.

thanks in advance.

Andrey
Telerik team
 answered on 19 Mar 2012
1 answer
57 views
Hi all,

in RadGrid, is it possible to add another filter option next to the existing filters? I have a column with several categories, let's say countries. Here is a good example on your demo page. Problem is: My countries are sorted in Categories, e.g.
  • Africa
    • Egypt
    • South Africa
  • Europe
    • Denmark
    • France
    • Italy
  • etc

So I could not use a simple dropdown list. I hope it's possible to use RadTreeView with checkboxes?
Problem is: I don't want to replace the existing filter. It should still be possible just to enter e.g. 'Den' and select 'Contains' as a filter. Additionally it should be possible to click on another filter icon and then RadTreeView opens showing all available options? Would that work?
I've also seen that it's possible to filter with RadFilter. This might also be an option but currently I think it's not very self-explaining for unexperienced users so I would really prefer to have an additional filter option icon in the filter row.
Many thanks in advance!

Radoslav
Telerik team
 answered on 19 Mar 2012
2 answers
136 views

I have a grid named gvTabList which in inside the usercontrol . I load this usercontrol at runtime from Default.aspx when some required condition is met.

The usercontrol is loaded as shown. I don't have to load this usercontrol on page load.As you can see I am not loading my usercontrol in Page_Load event.

if(Condition1 is met)
{
   UserControl control = (UserControl)LoadControl("~/Controls/" + Usercontrolname + ".ascx");
}
There is no problem loading the usercontrol when the condition is met. But the problem is when i click the heading of any column, the sortorder does not change. I have my funtion to handle the CustomSorting which is given below.

<telerik:RadAjaxManager ID="radAjaxManagerTab" runat="server">
                               <AjaxSettings>
                                   <telerik:AjaxSetting AjaxControlID="gvTabList">
                                       <UpdatedControls>
                                           <telerik:AjaxUpdatedControl ControlID="gvTabList" LoadingPanelID="ajaxLoadingPanel"  />
                                                                            
                                       </UpdatedControls>
                                   </telerik:AjaxSetting>
                               </AjaxSettings>
                           </telerik:RadAjaxManager>
                            <telerik:RadAjaxLoadingPanel ID="ajaxLoadingPanel" runat="server" IsSticky="true"
                       Skin="Default" Style="position: absolute; z-index: 101; top: 0; left: 0;">
                       <img alt="Loading" src="../Images/Loading.gif" />
                   </telerik:RadAjaxLoadingPanel>
                           <telerik:RadGrid ID="gvTabList" runat="server" Skin="WebBlue" AllowFilteringByColumn="True"
                               AllowPaging="True" PageSize="5" AllowSorting="True"
                                OnNeedDataSource="gvTabList_NeedDataSource"
                                OnInit="gvTabList_Init"
                                AutoGenerateColumns="False" GridLines="None" OnSortCommand="gvTabList_SortCommand" EnableAJAX="True" >                             
                               <GroupingSettings CaseSensitive="false" />
                               <MasterTableView AllowFilteringByColumn="true" AllowMultiColumnSorting="false" AllowCustomSorting="true">
                                   <RowIndicatorColumn Visible="False">
                                       <HeaderStyle Width="20px"></HeaderStyle>
                                   </RowIndicatorColumn>
                                   <ExpandCollapseColumn Visible="False">
                                       <HeaderStyle Width="19px"></HeaderStyle>
                                   </ExpandCollapseColumn>
                                   <CommandItemSettings ExportToPdfText="Export to Pdf" />
                                   <Columns>
                                       <telerik:GridBoundColumn AllowFiltering="False" DataField="ID" HeaderText="HEDIS #"
                                           UniqueName="HedisID">
                                           <HeaderStyle HorizontalAlign="Center" Width="140" />
                                           <ItemStyle HorizontalAlign="Center" />
                                       </telerik:GridBoundColumn>
                                       <telerik:GridBoundColumn AllowFiltering="False" DataField="HedisSubMeasure" HeaderText="HEDIS Domain"
                                           UniqueName="HedisDomain">
                                           <HeaderStyle HorizontalAlign="Center" Width="150" />
                                           <ItemStyle HorizontalAlign="Center" />
                                       </telerik:GridBoundColumn>
                                         
                                   </Columns>
                               </MasterTableView>
                                <PagerStyle Mode="NumericPages" />
                           </telerik:RadGrid>

I checked by debugging, but " e.OldSortOrder" always gives None.

protected void gvTabList_SortCommand(object source, GridSortCommandEventArgs e)
       {          
            GridSortExpression sortExpr = new GridSortExpression();          
           switch (e.OldSortOrder)           
           {
               case GridSortOrder.None:
                   sortExpr.FieldName = e.SortExpression;
                   sortExpr.SortOrder = GridSortOrder.Descending;
                   e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);                   
                   break;
               case GridSortOrder.Ascending:
                   sortExpr.FieldName = "ID";
                   sortExpr.SortOrder = GridSortOrder.Ascending;
                   e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);
                    
                   break;
               case GridSortOrder.Descending:
                   sortExpr.FieldName = e.SortExpression;
                   sortExpr.SortOrder = GridSortOrder.Ascending;
                   e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);
                   
                   break;
           }
           e.Canceled = true;    
           gvTabList.Rebind();
 
       }


Is this problem related with dynamically loading the usercontrol . I have found many forums saying " UserControl must be loaded during Init method". But as you can see I need this usercontrol only if a condition is met, I dont need it always. so I am not loading it in Init method.
if any one has faced this problem, please send me the solution. It will be a great help.






Antonio Stoilkov
Telerik team
 answered on 19 Mar 2012
4 answers
232 views
Hi,
I'm using RadGrid with autogenerated columns. In some column I have DateTime value ( e.g. sql - select id, startDate, price from table) . How can I set the dateformat of this columns in grid which have these values?
Amit
Top achievements
Rank 1
 answered on 19 Mar 2012
6 answers
163 views
Hi,

I have a grid with  set of GridBoundColumn, GridNumericColumn, GridDateTimeColumn etc.,  and Column reorder option enabled. i made reordering through client side by using property called ReorderColumnsOnClient="true". While reordering any column, the issue i faced is after reordered a GridNumeric column where GridBoundColumn is actually placed and vice versa., then filtering a reodered column, it throws a Type cast error.
"Message: Sys.WebForms.PageRequestManagerServerErrorException: Unable to cast object of type 'System.Web.UI.WebControls.TextBox' to type 'Telerik.Web.UI.RadNumericTextBox'. "

if i try to reorder a DatePickerColumn with numeric column it throws an exception as like follows :
"Message: Sys.WebForms.PageRequestManagerServerErrorException: Unable to cast object of type 'Telerik.Web.UI.RadDatePicker' to type 'Telerik.Web.UI.RadNumericTextBox'"


Kindly suggest a solution for this problem.

thanks and regards
Venk@t




Venkat
Top achievements
Rank 1
 answered on 19 Mar 2012
3 answers
264 views
How can I make RadDatePicker default to today's date when opens it? My RadDatePicker is one of the column the grid, when I do filter, I like to open the raddatePicker with today's date highlighted.

I am using  2011 Q1.  Is the newest version already set today's date as default when open the calendar?

Thanks
Princy
Top achievements
Rank 2
 answered on 19 Mar 2012
2 answers
62 views
Hi, i want to is the "Add" command item to pop up a rad window. I was able to get it to work by create a javascript function and setting setting;


OnCommand="Command_Clicked"

How do i prevent the insert field from appearing on the grid?

Thanks.
Kim
Top achievements
Rank 1
 answered on 19 Mar 2012
7 answers
237 views
 
Hello,

  I am working on Radgrid in one of my web pages. I have 3 questions on this.

1)  I want to change the backcolor of the edited row and for that i have given the edititemstyle and still don't see the color.Am i doing something wrong here? Here is the code.
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False"
                              OnDeleteCommand="RadGrid1_DeleteCommand" ShowStatusBar="True"
                               ShowFooter="True" Skin="Office2010Silver" Width="100%"
                              OnItemDataBound="RadGrid1_ItemDataBound" OnEditCommand="RadGrid1_EditCommand"
                              OnNeedDataSource="RadGrid1_NeedDataSource" 
                              OnUpdateCommand="RadGrid1_UpdateCommand" GridLines="None"
                              oninsertcommand="RadGrid1_InsertCommand" CellSpacing="0" Font-Bold="True"
                              ForeColor="Black">
                               <EditItemStyle  BackColor="DarkOrange"   BorderColor="#C00000" HorizontalAlign="Center" VerticalAlign="Middle" />
                              <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
                             
                              </HeaderContextMenu>                              
                               <ItemStyle Font-Bold="True" />                                 
                              <MasterTableView AllowAutomaticDeletes="True" CommandItemDisplay="Top" DataKeyNames="ClientID" EditMode="EditForms" >


2) Suppose I have 4 columns in the grid and when i edit a row, i would like to see the half of the columns on the left and the other half on the right. Something like this..

Column1       Column3
Column2       Column4

 I don't want to have all the columns straight. It will take more height.


3) I have a template column in the grid and it should bind the gender . It may be M or F or null. What i have works only  if the grid is NOT in edit mode. Is there a property which will bind the gender and should not throw a error if the value is null?
<telerik:GridTemplateColumn HeaderText="Gender" UniqueName="MemGender">
                                          <EditItemTemplate>
                                              <ASP:RadioButtonList ID="rbtnMemGender" runat="server" CssClass="radiobutton" 
                                              RepeatDirection="Horizontal"  >
                                                  <ASP:ListItem Text="M" Value="M" />
                                                  <ASP:ListItem Text="F" Value="F" />                                                 
                                              </ASP:RadioButtonList>
                                          </EditItemTemplate>
                                          <ItemTemplate>
                                              <ASP:Label ID="lblMemGender" runat="server" Text='<%# Bind("Gender") %>' ToolTip="Gender">
                                              </ASP:Label>
                                          </ItemTemplate>
                                      </telerik:GridTemplateColumn>

 



Appreciate the help.
Shinu
Top achievements
Rank 2
 answered on 19 Mar 2012
Narrow your results
Selected tags
Tags
+? more
Top users last month
Will
Top achievements
Rank 2
Iron
Motti
Top achievements
Rank 1
Iron
Hester
Top achievements
Rank 1
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Thomas
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Will
Top achievements
Rank 2
Iron
Motti
Top achievements
Rank 1
Iron
Hester
Top achievements
Rank 1
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Thomas
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?