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

DataGrid issues

3 Answers 116 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kirie
Top achievements
Rank 1
Kirie asked on 12 Sep 2011, 12:53 PM
Hi. 

I have a RadGrid with the following settings:

<telerik:RadGrid ID="genericGrid" runat="server" AutoGenerateColumns="false" AllowAutomaticDeletes="false"
    AllowSorting="true" AllowAutomaticInserts="false" AllowAutomaticUpdates="true" OnDataBound="DataBoundGenericGrid"
    AllowCustomPaging="true" PageSize="100" AllowPaging="True" AutoGenerateEditColumn="true"
    AllowFilteringByColumn="true" AllowMultiRowSelection="true" OnUpdateCommand="ItemUpdatedEvent"
    OnCancelCommand="ItemCanceledHandler" OnInsertCommand="ItemInsertedEvent" OnEditCommand="ItemEditHandler"
    OnItemDataBound="ItemDataBoundEvent" OnNeedDataSource="GridNeedDataSource" Style="height: 600;
    width: 100%">
    <ClientSettings AllowDragToGroup="true" AllowGroupExpandCollapse="true">
        <Selecting AllowRowSelect="true" EnableDragToSelectRows="false" />
        <Scrolling AllowScroll="true" UseStaticHeaders="true" />
        <ClientEvents OnRowDblClick="RowDblClick" />
    </ClientSettings>
    <MasterTableView AutoGenerateColumns="true" AllowAutomaticDeletes="false" AllowFilteringByColumn="true"
        AllowAutomaticInserts="false" AllowAutomaticUpdates="true" GridLines="Vertical"
        TableLayout="Fixed" GroupLoadMode="Client" EditMode="InPlace" />
</telerik:RadGrid>
When we autogenerate columns from a DataTable everything works as expected:

genericGrid.DataSource = table.DefaultView;

http://dl.dropbox.com/u/4552022/workinggrid.png

But when i try to add the columns in code:

foreach (var gridColumn in _gridColumns)
            {
                genericGrid.Columns.Add(gridColumn);
            }
            genericGrid.DataSource = table.DefaultView;

I get this:

http://dl.dropbox.com/u/4552022/notworkinggrid.png

And also, doubleklicking a row is supposed to give editmode:
http://dl.dropbox.com/u/4552022/edit.png

But when adding columns manually it gives this error:
http://dl.dropbox.com/u/4552022/error.png

When manually creating columns, they are created like this: 

var dropDownColumn = new GridDateTimeColumn()
                         {
                             DataField = tableDefDto.ColumnId
                         };


The reason for doing this manually, is to enable the possiblity for dropdownColumns.

Any ideas?

3 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 15 Sep 2011, 08:21 AM
Hi Eirik,

Could you please confirm that you properly create the RadGrid's columns as is shown in the following documentation article:
http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html
Additionally it will be helpful if you could post your aspx markup code with the related code behind file. Thus we will be able to gather more details about your scenario and provide you with more to-the-point answer.

Looking forward for your reply.

Best wishes,
Radoslav
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal
0
Kirie
Top achievements
Rank 1
answered on 15 Sep 2011, 09:20 AM
I am now able to doubleclick a row, and get in to edit mode, but when i try to save/go out of edit mode i get a index out of bounds error.

markup:

<html>
    <script type="text/javascript">
        function RowDblClick(sender, eventArgs) {
            sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());
        }
        </script>
    <body>
        <form id="form1" runat="server">
         <telerik:RadScriptManager ID="ScriptManager1" runat="server" />
        <div>
             <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" AllowAutomaticDeletes="false"
                        AllowSorting="false" AllowAutomaticInserts="false" AllowAutomaticUpdates="true" OnItemUpdated="ItemItemUpdatedEvent"
                        ShowStatusBar="true" OnDataBound="DataBoundGenericGrid" AllowCustomPaging="true"
                        PageSize="100" AllowPaging="True" AutoGenerateEditColumn="true" AllowFilteringByColumn="true"
                        AllowMultiRowSelection="true" OnUpdateCommand="ItemUpdatedEvent" OnInsertCommand="ItemInsertedEvent"
                        OnItemDataBound="ItemDataBoundEvent" OnNeedDataSource="GridNeedDataSource" Style="height: 600;
                        width: 100%">
                        <ClientSettings AllowDragToGroup="true" AllowGroupExpandCollapse="true">
                            <Selecting AllowRowSelect="true" EnableDragToSelectRows="false" />
                            <Scrolling AllowScroll="true" UseStaticHeaders="true" />
                            <ClientEvents OnRowDblClick="RowDblClick"  />
                        </ClientSettings>
                        <MasterTableView AutoGenerateColumns="false" AllowAutomaticDeletes="false" AllowFilteringByColumn="true"
                            AllowAutomaticInserts="false" AllowAutomaticUpdates="true" GridLines="Vertical"
                            TableLayout="Fixed" GroupLoadMode="Client" EditMode="InPlace" />
                    </telerik:RadGrid>
        </div>
        </form>
    </body>
</html>


Code behind:

using System;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
 
namespace Prj.UI.Web.Import
{
    public partial class MyForm : System.Web.UI.Page
    {
        private ImportViewModel _viewModel;
 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                _viewModel = new ImportViewModel(Session);
                GridSettings();
                var _dataColumns = _viewModel.GetColumns("slcv");
                RadGrid1.Columns.Clear();
                var gridColumns = _viewModel.GetGridColumns(_dataColumns);
                foreach (GridColumn column in gridColumns)
                {
                    RadGrid1.Columns.Add(column);
                }
                RadGrid1.DataSource = _viewModel.GetImportData("slcv", "-1");
 
            }
        }
 
        private void GridSettings()
        {
            RadGrid1.PageSize = 15;
            RadGrid1.AllowPaging = true;
            RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
            RadGrid1.AutoGenerateColumns = false;
            RadGrid1.Skin = "Web20";
            RadGrid1.MasterTableView.Width = Unit.Percentage(100);
        }
 
 
        protected void ItemUpdatedEvent(object sender, GridCommandEventArgs e)
        {
 
        }
 
        protected void ItemInsertedEvent(object sender, GridCommandEventArgs e)
        {
 
        }
 
        protected void ItemDataBoundEvent(object sender, GridItemEventArgs e)
        {
 
        }
 
        protected void GridNeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            _viewModel = new ImportViewModel(Session);
            var _dataColumns = _viewModel.GetColumns("slcv");
            RadGrid1.Columns.Clear();
            var gridColumns = _viewModel.GetGridColumns(_dataColumns);
            foreach (GridColumn column in gridColumns)
            {
                RadGrid1.Columns.Add(column);
            }
            
            RadGrid1.DataSource = _viewModel.GetImportData("slcv", "-1");
        }
 
        protected void DataBoundGenericGrid(object sender, EventArgs e)
        {
        }
 
        protected void ItemItemUpdatedEvent(object sender, GridUpdatedEventArgs e)
        {
             
        }
    }
}

0
Radoslav
Telerik team
answered on 19 Sep 2011, 07:39 AM
Hi Kirie,

Could you please try removing adding the grid'с columns into the NeedDataSource event and let me know if the described issue still persists:
protected void GridNeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
        _viewModel = new ImportViewModel(Session);
        //var _dataColumns = _viewModel.GetColumns("slcv");
       //RadGrid1.Columns.Clear();
       //var gridColumns = _viewModel.GetGridColumns(_dataColumns);
       //foreach (GridColumn column in gridColumns)
       //{
       //    RadGrid1.Columns.Add(column);
       //}         
 
          RadGrid1.DataSource = _viewModel.GetImportData("slcv", "-1");
}

Looking forward for your reply.

All the best,
Radoslav
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal
Tags
Grid
Asked by
Kirie
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Kirie
Top achievements
Rank 1
Share this question
or