Telerik Forums
UI for ASP.NET AJAX Forum
2 answers
126 views
I really like a lot of the RadGrid's functionality, and I think it's the route to go for the following problem, but i'm looking for some help on a best approach for the following problem.   Be it the rad grid or some other set of controls.

I have a Planning Year and a Planning Unit that are selectable controls, for the two controls, I want to populate some form of grid or other RadControl that allows me to repeat the following pattern.

Page 1
1. Print Planning Unit and associated year,
2. Print Planning Unit Purpose,
3. Print Planning Unit Objectives. (created by using planning unit and planning year, gives you the objective list for that planning year)

Page 2 thru end
3. Print Objective Data (created by getting planning unit and planning year, gives you the objective list for that planning year)
    a) Print Objective Statement
    b) Print Objective Tasks Detail (joined with objectives)
    c) Print Assessment Measures Detail (joined with objectives)
    d) Print Results Detail (joined with objectives)
    e) Print Use of Results Detail (joined with objectives)
    f) Status Reports Detail (joined with objectives.
Jeremy
Top achievements
Rank 2
 answered on 29 Dec 2009
2 answers
264 views
Hello,
I have a scenario where there are two grids where one is a master grid and one is a detail grid, similar to http://www.telerik.com/help/aspnet-ajax/grdrelatedgrids.html (except with two grids instead of three).  When a user selects a row from the master grid then data related to that row/item displays in the detail grid.  In my scenario, users add data to the detail grid and relate it to the master by manually entering the foreign key value (see the attached image and example below).

Example: There is a master grid that is populated with rows of "people".  A user selects a particular person then the detail grid displays the items that belong to the particular person.  The selected person ID is 3.  Users can add or update items that belong to the person by entering data into the detail grid, however currently they have to look at the master grid to tell what the ID is of the person.  ID is one of the datakeys in the detail grid.  It is a foreign key to the master grid data.  When someone needs to insert data into the detail grid related to the item they have selected in the master grid, I would like to pre-populate the textbox value when the editor for a new item is displayed.


I would like to use the datakey/primary key from the master grid to populate a value of a field when users are INSERTing new items into the detail grid.

Is this possible and how?
jgill
Top achievements
Rank 1
 answered on 29 Dec 2009
3 answers
209 views
Hi,
I have a grid with 3 detail tables on the same level. I need to disable the entire grid in such a way that the user will be able to open the lower tables to view the data but not change it (this needs to be done through code).
Would appreciate any help.
Thanks,
Lynda

<telerik:RadGrid ID="RadGridCV" runat="server" Skin="Office2007" GridLines="None" Width="98%" AllowMultiRowSelection="True" AllowMultiRowEdit="True">  
<MasterTableView AutoGenerateColumns="False" DataKeyNames="Person_Id" Width="100%" EditMode="InPlace">  
    <Columns> 
        <telerik:GridBoundColumn DataField="Person_Id" SortExpression="Person_Id" ReadOnly="True" UniqueName="Person_Id" Visible="False"></telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="Person_FirstNameEng" HeaderText="First Name" ReadOnly="True" SortExpression="Person_FirstNameEng" UniqueName="Person_FirstNameEng">  
            <ItemStyle VerticalAlign="Top" /> 
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="Person_LastNameEng" HeaderText="Last Name" ReadOnly="True" SortExpression="Person_LastNameEng" UniqueName="Person_LastNameEng">  
            <ItemStyle VerticalAlign="Top" /> 
        </telerik:GridBoundColumn> 
        <telerik:GridTemplateColumn UniqueName="ListOfPublicationsFile" HeaderText="List Of Publications File" DefaultInsertValue="">          
            <ItemTemplate>    
             <asp:Label ID="Label1" runat="server" Text='<%#Bind("ListOfPublicationsFile") %>'></asp:Label>    
            </ItemTemplate>   
            <EditItemTemplate><asp:FileUpload ID="FileUploadListOfPublications" runat="server" /></EditItemTemplate>    
            <ItemStyle VerticalAlign="Top" /> 
        </telerik:GridTemplateColumn>   
        <telerik:GridEditCommandColumn><ItemStyle ForeColor="Green" VerticalAlign="Top" /></telerik:GridEditCommandColumn> 
    </Columns> 
      
    <DetailTables> 
     <telerik:GridTableView Enabled="false" Name="AcademiclBackground" EditMode="InPlace" CommandItemDisplay="Bottom" runat="server" Caption="A. Academic Background" Width="100%" AutoGenerateColumns="False" DataKeyNames="ACBG_ItemNum">  
       <ParentTableRelation> 
         <telerik:GridRelationFields   
           DetailKeyField="ACBG_PersonId" 
           MasterKeyField="Person_Id" /> 
       </ParentTableRelation> 
       <Columns> 
           <telerik:GridBoundColumn DataField="ACBG_OrderBy" ColumnEditorID="myTextBoxEditor30px" HeaderText="Row No." SortExpression="ACBG_OrderBy" UniqueName="ACBG_OrderBy">  
               <ItemStyle Width="30px" /> 
           </telerik:GridBoundColumn> 
           <telerik:GridBoundColumn DataField="ACBG_FromTo" ColumnEditorID="myTextBoxEditor70px" HeaderText="Date From To" SortExpression="ACBG_FromTo" UniqueName="ACBG_FromTo">  
               <ItemStyle Width="80px" /> 
           </telerik:GridBoundColumn> 
           <telerik:GridBoundColumn DataField="ACBG_Institute" ColumnEditorID="myTextBoxEditor130px" HeaderText="Institute" SortExpression="ACBG_Institute" UniqueName="ACBG_Institute">  
               <ItemStyle Width="150px" /> 
           </telerik:GridBoundColumn> 
           <telerik:GridBoundColumn DataField="ACBG_Degree" ColumnEditorID="myTextBoxEditor50px" HeaderText="Degree" SortExpression="ACBG_Degree" UniqueName="ACBG_Degree">  
               <ItemStyle Width="60px" /> 
           </telerik:GridBoundColumn> 
           <telerik:GridBoundColumn DataField="ACBG_Area" ColumnEditorID="myTextBoxEditor100px" HeaderText="Area" SortExpression="ACBG_Area" UniqueName="ACBG_Area">  
               <ItemStyle Width="120px" /> 
           </telerik:GridBoundColumn>   
           <telerik:GridEditCommandColumn ButtonType="ImageButton" CancelImageUrl="~/Images/cancel.gif" 
               EditImageUrl="~/Images/edit.gif" InsertImageUrl="~/Images/update.gif" UpdateImageUrl="~/Images/update.gif"><ItemStyle  ForeColor="#007E00" /></telerik:GridEditCommandColumn> 
           <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="column" ButtonType="ImageButton" ImageUrl="~/Images/delete.gif"><ItemStyle ForeColor="#E40000" /></telerik:GridButtonColumn> 
       </Columns> 
       <CommandItemSettings AddNewRecordText="Add Academic Background Item" /> 
         <EditFormSettings><EditColumn UniqueName="EditCommandColumn1"></EditColumn></EditFormSettings>  
     </telerik:GridTableView> 
       
     <telerik:GridTableView Name="PreviousEmployment" EditMode="InPlace" CommandItemDisplay="Bottom" runat="server" Caption="B. Previous Employment&lt;br/&gt;&lt;span class=HeaderText&gt;Begin with present position (do not include tutoring, memberships in scientific associations or guest lectures)&lt;/span&gt;" Width="100%" AutoGenerateColumns="False" DataKeyNames="PE_ItemNum" AllowPaging="True">  
       <ParentTableRelation> 
         <telerik:GridRelationFields   
           DetailKeyField="PE_PersonId" 
           MasterKeyField="Person_Id" /> 
       </ParentTableRelation> 
       <Columns> 
           <telerik:GridBoundColumn DataField="PE_OrderBy" ColumnEditorID="myTextBoxEditor30px"  HeaderText="Row No." SortExpression="PE_OrderBy" UniqueName="PE_OrderBy">  
               <ItemStyle Width="30px" /> 
           </telerik:GridBoundColumn> 
           <telerik:GridBoundColumn DataField="PE_FromTo" ColumnEditorID="myTextBoxEditor70px" HeaderText="Date From To" SortExpression="PE_FromTo" UniqueName="PE_FromTo">  
               <ItemStyle Width="80px" /> 
           </telerik:GridBoundColumn> 
           <telerik:GridBoundColumn DataField="PE_Institute" ColumnEditorID="myTextBoxEditor130px" HeaderText="Institute" SortExpression="PE_Institute" UniqueName="PE_Institute">  
               <ItemStyle Width="150px" /> 
           </telerik:GridBoundColumn> 
           <telerik:GridBoundColumn DataField="PE_Title" ColumnEditorID="myTextBoxEditor50px" HeaderText="Title" SortExpression="PE_Title" UniqueName="PE_Title">  
               <ItemStyle Width="60px" /> 
           </telerik:GridBoundColumn> 
           <telerik:GridBoundColumn DataField="PE_Area" ColumnEditorID="myTextBoxEditor100px" HeaderText="Research Area" SortExpression="PE_Area" UniqueName="PE_Area">  
               <ItemStyle Width="120px" /> 
           </telerik:GridBoundColumn> 
           <telerik:GridEditCommandColumn ButtonType="ImageButton" CancelImageUrl="~/Images/cancel.gif" EditImageUrl="~/Images/edit.gif" InsertImageUrl="~/Images/update.gif" UpdateImageUrl="~/Images/update.gif"><ItemStyle ForeColor="#007E00" /></telerik:GridEditCommandColumn> 
           <telerik:GridButtonColumn CommandName="Delete" UniqueName="column" ButtonType="ImageButton" ImageUrl="~/Images/delete.gif"><ItemStyle ForeColor="#E40000" /></telerik:GridButtonColumn> 
       </Columns> 
       <CommandItemSettings AddNewRecordText="Add Previous Employment Item" /> 
         <EditFormSettings> 
             <EditColumn UniqueName="EditCommandColumn1"></EditColumn> 
         </EditFormSettings> 
     </telerik:GridTableView> 
       
     <telerik:GridTableView Name="GrantsAndAwards" CommandItemDisplay="Bottom" runat="server" Caption="C. Grants and Awards Received Within the Past Five Years&lt;br/&gt;&lt;span class=HeaderText&gt;Please indicate the date of receiving the grant/award and the funding period in the comments box.&lt;/span&gt;" Width="100%" AutoGenerateColumns="False" DataKeyNames="GAA_Id" AllowPaging="True">  
       <ParentTableRelation> 
         <telerik:GridRelationFields   
           DetailKeyField="GAA_PersonId" 
           MasterKeyField="Person_Id" /> 
       </ParentTableRelation> 
       <Columns> 
           <telerik:GridBoundColumn DataField="GAA_OrderBy"  HeaderText="Row No." SortExpression="GAA_OrderBy" UniqueName="GAA_OrderBy">  
               <ItemStyle Width="30px" /> 
           </telerik:GridBoundColumn>   
           <telerik:GridBoundColumn DataField="GAA_ResearchTopics"  HeaderText="Research Topics" SortExpression="GAA_ResearchTopics" UniqueName="GAA_ResearchTopics">  
               <ItemStyle Width="200px" /> 
           </telerik:GridBoundColumn> 
           <telerik:GridBoundColumn DataField="GAA_FundingAgency" HeaderText="Funding Organization" SortExpression="GAA_FundingAgency" UniqueName="GAA_FundingAgency">  
               <ItemStyle Width="150px" /> 
           </telerik:GridBoundColumn> 
           <telerik:GridBoundColumn DataField="GAA_TotalGrant" HeaderText="Total (in $)" SortExpression="GAA_TotalGrant" UniqueName="GAA_TotalGrant">  
               <HeaderStyle Wrap="False" /> 
               <ItemStyle Wrap="False" Width="60px" /> 
           </telerik:GridBoundColumn>    
           <telerik:GridEditCommandColumn ButtonType="ImageButton" CancelImageUrl="~/Images/cancel.gif" EditImageUrl="~/Images/edit.gif" InsertImageUrl="~/Images/update.gif" UpdateImageUrl="~/Images/update.gif"><ItemStyle ForeColor="#007E00" /></telerik:GridEditCommandColumn> 
           <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="column" ButtonType="ImageButton" ImageUrl="~/Images/delete.gif"><ItemStyle ForeColor="#E40000" /></telerik:GridButtonColumn> 
       </Columns> 
       <CommandItemSettings AddNewRecordText="Add Grant and Award Item" /> 
        <EditFormSettings UserControlName="~/Controls/ucGrantsAndAwardsDetails.ascx" EditFormType="WebUserControl"><EditColumn UniqueName="EditCommandColumn1"></EditColumn></EditFormSettings>  
     </telerik:GridTableView> 
 
</DetailTables> 
    <ExpandCollapseColumn Visible="True"></ExpandCollapseColumn> 
    <EditFormSettings> 
        <EditColumn UniqueName="EditCommandColumn1">  
        </EditColumn> 
    </EditFormSettings> 
</MasterTableView> 
</telerik:RadGrid> 
Daniel
Telerik team
 answered on 29 Dec 2009
12 answers
151 views

Hi,
I have created a grid at runtime and have set properties as follows:

 

 

MainGrid.ClientSettings.AllowKeyboardNavigation = true;   
   
MainGrid.ClientSettings.Selecting.AllowRowSelect = true;   
   
MainGrid.ClientSettings.ClientEvents.OnRowSelected = "OnRowSelected";  
 
<script type="text/javascript" language="javascript">   
   
function OnRowSelected(sender, args)   
{  
//My code  
}   
</script> 
 
 

 

 

this code works perfectly fine when i use 'SPACE' key for selecttion
I dont want 'ENTER' key to get into Edit mode instead what i want is to use 'ENTER' key for selection
What this means is,whatever currently happening using 'SPACE' bar it should happen on pressing 'ENTER' key

Regards,
Mangesh

Tsvetoslav
Telerik team
 answered on 29 Dec 2009
1 answer
116 views
I'm facing the exact same problem of the item and page count in the footer not updating after I change the data source in the

NeedDataSource event handler.

Other people have run into this issue:

http://www.telerik.com/community/forums/aspnet-ajax/grid/page-count-inaccurate-after-new-search.aspx#0

http://www.telerik.com/community/forums/aspnet-ajax/grid/rebind-not-updating-pager.aspx

However, the suggestion of setting EnableLinqExpressions to false did not work for me. Does anyone have any other suggestions to try? I'm running on .NET 3.5 and using RadControls for ASP.NET AJAX Q3 2009 NET3.5.

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SearchPersonControl.ascx.cs" Inherits="SearchPersonControl" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
<%@ Register assembly="System.Web.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" namespace="System.Web.UI.WebControls" tagprefix="asp" %>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>

<asp:Table ID="tblMainLayout" runat="server">
    <asp:TableRow>
        <asp:TableCell>
            <asp:Label ID="lblPerson" runat="server" Text="Persoon:"></asp:Label>
        </asp:TableCell>
        <asp:TableCell>
            <telerik:RadTextBox ID="txtPersonSearch" Runat="server" Width="200px"></telerik:RadTextBox>
        </asp:TableCell>
        <asp:TableCell>
            <asp:Button ID="btnSearch" runat="server" onclick="btnSearch_Click" Text="Search" />
        </asp:TableCell>
        <asp:TableCell>
            <asp:Button ID="btnAdvancedSearch" runat="server" onclick="btnAdvancedSearch_Click" Text="Show Advanced Search" />
        </asp:TableCell>
    </asp:TableRow>
    <asp:TableRow ID="tblrAdvancedSearch1" runat="server" Visible="false">
        <asp:TableCell>
            <asp:Label ID="lblID" runat="server" Text="ID nummer: "></asp:Label>
        </asp:TableCell>
        <asp:TableCell>
            <telerik:RadTextBox ID="txtID" Runat="server"></telerik:RadTextBox>
        </asp:TableCell>
    </asp:TableRow>
    <asp:TableRow ID="tblrAdvancedSearch2" runat="server" Visible="false">
        <asp:TableCell>
            <asp:Label ID="lblName" runat="server" Text="Naam:"></asp:Label>
        </asp:TableCell>
        <asp:TableCell>
            <telerik:RadTextBox ID="txtName" Runat="server" Width="200px"></telerik:RadTextBox>
        </asp:TableCell>
    </asp:TableRow>
    <asp:TableRow>
        <asp:TableCell ColumnSpan="4">
            <telerik:RadGrid ID="grdPersons" runat="server" AllowPaging="True"
                DataSourceID="HECINA_DEV_M_SearchPersonEntities" GridLines="None"
                AllowSorting="True" AllowFilteringByColumn = "true" OnNeedDataSource="grdPersons_NeedDataSource"
                EnableLinqExpressions="false">
                <MasterTableView AutoGenerateColumns="False"
                        DataSourceID="HECINA_DEV_M_SearchPersonEntities">
                    <RowIndicatorColumn>
                        <HeaderStyle Width="20px"></HeaderStyle>
                    </RowIndicatorColumn>
                    <SortExpressions>
                        <telerik:GridSortExpression FieldName="Persons_FullName" SortOrder="Ascending" />
                    </SortExpressions>
                    <ExpandCollapseColumn>
                        <HeaderStyle Width="20px"></HeaderStyle>
                    </ExpandCollapseColumn>
                    <Columns>
                        <telerik:GridBoundColumn DataField="Persons_FullName" DefaultInsertValue=""
                            HeaderText="Naam" ReadOnly="True" SortExpression="Persons_FullName"
                            UniqueName="Persons_FullName"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Persons_BirthDate"
                            DataType="System.DateTime" DefaultInsertValue="" HeaderText="Geboortedatum"
                            ReadOnly="True" SortExpression="Persons_BirthDate"
                            UniqueName="Persons_BirthDate"></telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Persons_IdentificationNumber"
                            DefaultInsertValue="" HeaderText="Identificatienummer" ReadOnly="True"
                            SortExpression="Persons_IdentificationNumber"
                            UniqueName="Persons_IdentificationNumber"></telerik:GridBoundColumn>
                    </Columns>
                </MasterTableView>
            </telerik:RadGrid>
        </asp:TableCell>
    </asp:TableRow>
</asp:Table>
<asp:EntityDataSource ID="HECINA_DEV_M_SearchPersonEntities" runat="server"
    ConnectionString="name=HECINA_DEV_M_SearchPersonEntities"
    DefaultContainerName="HECINA_DEV_M_SearchPersonEntities"
    EntitySetName="Persons" EntityTypeFilter="Persons"
    Select="it.[Persons_BirthDate], it.[Persons_FullName], it.[Persons_IdentificationNumber]">
</asp:EntityDataSource>

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CX.Hecina.DataAccessLayer;

public partial class SearchPersonControl : System.Web.UI.UserControl
{
    HECINA_DEV_M_SearchPersonEntities searchPersonEntities;

    protected void Page_Load(object sender, EventArgs e)
    {
        this.searchPersonEntities = new HECINA_DEV_M_SearchPersonEntities();
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        //Only one of these can be set. Always clear both to ensure the data grid is current.
        this.grdPersons.DataSourceID = null;
        this.grdPersons.DataSource = null;
        this.grdPersons.CurrentPageIndex = 0;
        this.grdPersons.Rebind();
    }

    protected void grdPersons_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        //Always default to the full data set. This is useful if no search terms were specified.
        IQueryable<Persons> qry = this.searchPersonEntities.Persons.OrderBy(p => p.Persons_FullName);

        if (this.txtName.Text.Length != 0)
        {
            qry = this.searchPersonEntities.Persons.Where(p => p.Persons_FullName.ToUpper().Contains(this.txtName.Text.ToUpper()));
        }

        if (this.txtID.Text.Length != 0)
        {
            qry = this.searchPersonEntities.Persons.Where(p => p.Persons_IdentificationNumber.ToUpper().Contains(this.txtID.Text.ToUpper()));
        }

        //Google-like search that matches on multiple fields simultaneously.
        if (this.txtPersonSearch.Text.Length != 0)
        {
            string searchText = this.txtPersonSearch.Text.ToUpper();
            qry = this.searchPersonEntities.Persons.Where(p => p.Persons_FullName.ToUpper().Contains(searchText) ||
                //TODO: Figure this out, at runtime an exception is thrown that LINQ does not
                //recognize ToShortDateString().
                //p.Persons_BirthDate.ToShortDateString().Contains(searchText) ||
                p.Persons_IdentificationNumber.ToUpper().Contains(searchText));
        }

        //TODO: figure out how to update record and page count.
        this.grdPersons.DataSource = qry;
    }

    protected void btnAdvancedSearch_Click(object sender, EventArgs e)
    {
        //Simply invert the visibility property value of the advanced search fields.
        this.tblrAdvancedSearch1.Visible ^= true;
        this.tblrAdvancedSearch2.Visible ^= true;

        if (this.tblrAdvancedSearch1.Visible == true)
        {
            this.btnAdvancedSearch.Text = "Hide Advanced Search";
        }
        else
        {
            this.btnAdvancedSearch.Text = "Show Advanced Search";
        }
    }
}

The only thing I could think I'm doing differently is that I'm using the grid inside a user control.

Tsvetoslav
Telerik team
 answered on 29 Dec 2009
7 answers
126 views
Hi,

In one of my user control, I've a radgrid with paging turned on. when i travel to the 3rd or 4th page or any page, then open up my ser control, my last page which i was working on is appearing as the current page. But I want the first page to alwasy come whenever I open up my user control and bind the grid.

Pls help me with code samples.

To be more clear, I do not have a "Add new record " button. It's my own button"Add" which opens up  a user control with a grid(with paging on).
When I'm in my user control, I go to the 3rd page and click cancel and exit from the user control and if I click "ADD" button from my aspx ,I open up the user control. but the grid is in page 3 and not in page 1. How do I make the grid to be in page 1 always when I open up that user control. Pls do help:
Tsvetoslav
Telerik team
 answered on 29 Dec 2009
8 answers
566 views
I am wanting to create custom Display, Insert, and Edit templates. I need to do all this through code behind, I have no access to the aspx page.

I found a few posts getting me part of the way there:

I am having trouble figuring out how to add the HTML elements below to the scheduler, through code-behind.

<AppointmentTemplate>  
    (<asp:Literal ID="AppointmentStartTime" runat="server" Text='<%# Eval("Start", "{0:t}") %>'></asp:Literal>  
    -   
    <asp:Literal ID="AppoitmentEndTime" runat="server" Text='<%# Eval("End", "{0:t}") %>'></asp:Literal>)   
    <asp:Literal ID="AppointmentSubject" runat="server" Text='<%# Eval("Subject") %>'></asp:Literal>  
</AppointmentTemplate> 

Any help is appreciated. Thanks!
Joe
Top achievements
Rank 1
 answered on 29 Dec 2009
2 answers
249 views
I am trying to set focus on a radtextbox using the following function called on the ClientEvents-OnBlur event:
The problem is that when I remove the text and tab away, focus is not set. If I continue tabbing back to that field the onblur event fires again but it does set focus.  Why is this failing on my first onBlur event being fired and successful on the second onBlur event firing?


  function ValidateTitle(oTitle, args) {
    if (oTitle.get_value()=='') {
     oTitle.focus();
      }
  }  

<telerik:RadTextBox
 ID="txtTitle"
 runat="server"
 Rows="3"
 TextMode="MultiLine"
 Width="362px"
 MaxLength="4000"
 ToolTip="Title"
 CausesValidation="True"
 ClientEvents-OnBlur="ValidateTitle">
</telerik:RadTextBox>
Robert
Top achievements
Rank 1
 answered on 29 Dec 2009
1 answer
197 views
Hi,
I have a grid with edit form (user control) for editing an item. I am insterested in disabling the entire grid in such a way that the user can still open the edit form and view the information without changing it. This needs to be done through code.
Is it possible?
Thanks,
Lynda
Daniel
Telerik team
 answered on 29 Dec 2009
3 answers
175 views
I have a RadGrid with two-level hierarchy for which the structure is defined programmatically. The datasource for the detail table is empty on page load. My idea was to query the database whenever an 'expand' event is fired and add the results to the datasource (which is held in viewstate). The event fires and the data is added to the datasource, but the Rebind() method throws the following exception:

Syntax error: Missing operand before 'Is' operator.

I tested the grid by loading some data on page load, so I know the NeedDataSource and DetailTableDataBind methods are working correctly. Some insight to why this is occurring would be appreciated. Sample code is provided below.

    protected void Page_Load(object sender, EventArgs e) 
    { 
        if (!Page.IsPostBack) 
        { 
            this.loadGrid(); 
        } 
    } 
 
protected void loadGrid() 
    { 
        // Get the null level codes and sort according to display order 
        dataset = controller.GetCode(null); 
         
        // Set the keys 
        RadGrid1.MasterTableView.DataKeyNames = new string[] { "code""value" }; 
        RadGrid1.MasterTableView.HierarchyLoadMode = GridChildLoadMode.Client; 
        RadGrid1.ClientSettings.EnablePostBackOnRowClick = true
 
        //Column to use to create the RadGrid columns 
        GridBoundColumn boundColumn; 
 
        //code column 
        boundColumn = new GridBoundColumn(); 
        RadGrid1.MasterTableView.Columns.Add(boundColumn); 
        boundColumn.DataField = "code"
        boundColumn.HeaderText = "Code"
        boundColumn.HeaderStyle.Width = 80; 
 
        //value column 
        boundColumn = new GridBoundColumn(); 
        RadGrid1.MasterTableView.Columns.Add(boundColumn); 
        boundColumn.DataField = "value"
        boundColumn.HeaderText = "Value"
        boundColumn.HeaderStyle.Width = 80; 
 
        // Create dataset for sub level codes 
        subDataset = new DataSet(); 
        GridTableView subGrid = new GridTableView(RadGrid1); 
        subTypeCodeGrid.Name = "SubCodes"
        subTypeCodeGrid.DataKeyNames = new string[] { "code""value" }; 
        subTypeCodeGrid.AutoGenerateColumns = false
        GridRelationFields relationFields = new GridRelationFields(); 
        relationFields.MasterKeyField = "value"
        relationFields.DetailKeyField = "code"
        subTypeCodeGrid.ParentTableRelation.Add(relationFields); 
        RadGrid1.MasterTableView.DetailTables.Add(subGrid); 
         
        // Add columns to sub dataset 
        //code column 
        boundColumn = new GridBoundColumn();         
        subTypeCodeGrid.Columns.Add(boundColumn); 
        boundColumn.DataField = "code"
        boundColumn.HeaderText = "Code"
        boundColumn.HeaderStyle.Width = 80;         
 
        int gridWidth = 0; 
        for (int i = 0; i < RadGrid1.MasterTableView.Columns.Count; i++) 
        { 
            gridWidth += (int)RadGrid1.MasterTableView.Columns[i].HeaderStyle.Width.Value; 
        } 
        RadGrid1.Width = gridWidth + 30; 
    }     
 
protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
    { 
        int index = e.Item.ItemIndex; 
        if ((e.CommandName == RadGrid.ExpandCollapseCommandName || e.CommandName == "RowClick")) 
        { 
            string Value = RadGrid1.MasterTableView.Items[index]["value"].Text.ToString().Trim(); 
            if (loadedValues.Contains(Value)) 
            { 
                return
            } 
            else 
            { 
                loadedValues.Add(Value); 
                DataSet tempSubCodes = controller.GetCode(Value); 
                foreach (DataSet.table1Row row in tempSubCodes.table1) 
                { 
                    subDataset.table1.Rows.Add(row.ItemArray); 
                } 
                RadGrid1.Rebind(); //<-- ERROR 
            } 
            RadGrid1.MasterTableView.Items[index].Expanded = true
        } 
    } 
 
protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
    { 
        if (!e.IsFromDetailTable) 
        { 
            RadGrid1.DataSource = dataset.table1.DefaultView; 
        } 
    } 
 
    protected void RadGrid1_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e) 
    { 
        switch (e.DetailTableView.Name) 
        { 
            case "SubCodes"
                { 
                    e.DetailTableView.DataSource = subDataset.table1.DefaultView; 
                    break
                } 
        } 
    } 

Also, when the 'expand' button is clicked, the 'RowClick' ItemCommand is fired instead of the desired ExpandCollapseCommandName. Any way to change this?
Josh
Top achievements
Rank 1
 answered on 29 Dec 2009
Narrow your results
Selected tags
Tags
+? more
Top users last month
Simon
Top achievements
Rank 2
Iron
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Marco
Top achievements
Rank 4
Iron
Iron
Iron
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Simon
Top achievements
Rank 2
Iron
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Marco
Top achievements
Rank 4
Iron
Iron
Iron
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?