c# - Radgrid 自定义插入模板

标签 c# asp.net telerik radgrid

我有一个简单的 radgrid。当我单击“添加记录”时,它会弹出一个插入模板,它会以垂直格式显示表单,我想更改它以使其以水平格式显示?我该怎么做?

protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["GridData"] == null)
            {
                DataTable table = GetTable();
                Session.Add("GridData", table);
            }
            DefineGridStructure();
        }


        private void DefineGridStructure()
        {
            RadGrid grid = new RadGrid();
            grid.ID = "RadGrid1";
            grid.NeedDataSource += new GridNeedDataSourceEventHandler(grid_NeedDataSource);
            grid.AutoGenerateEditColumn = true;
            grid.AutoGenerateDeleteColumn = true;
            grid.AllowAutomaticInserts = false;
            grid.Width = Unit.Percentage(100);
            grid.PageSize = 15;
            grid.AllowPaging = true;
            grid.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
            grid.AutoGenerateColumns = false;
            grid.MasterTableView.Width = Unit.Percentage(100);
            grid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.TopAndBottom;
            grid.AllowAutomaticDeletes = false;
            grid.AllowAutomaticUpdates = false;
            grid.InsertCommand +=grid_InsertCommand;
            grid.MasterTableView.DataKeyNames = new string[] { "RowNumber" };
            GridBoundColumn boundColumn = new GridBoundColumn();
            boundColumn.DataField = "RowNumber";
            boundColumn.HeaderText = "RowNumber";
            boundColumn.ReadOnly = true;
            grid.MasterTableView.Columns.Add(boundColumn);
            boundColumn = new GridBoundColumn();
            boundColumn.DataField = "Size";
            boundColumn.HeaderText = "Size";
            grid.MasterTableView.Columns.Add(boundColumn);
            boundColumn = new GridBoundColumn();
            boundColumn.DataField = "Description";
            boundColumn.HeaderText = "Description";
            grid.MasterTableView.Columns.Add(boundColumn);
            boundColumn = new GridBoundColumn();
            boundColumn.DataField = "Quantity";
            boundColumn.HeaderText = "Quantity";
            grid.MasterTableView.Columns.Add(boundColumn);
            boundColumn = new GridBoundColumn();
            boundColumn.DataField = "Duration";
            boundColumn.HeaderText = "Duration";
            grid.MasterTableView.Columns.Add(boundColumn);
            boundColumn = new GridBoundColumn();
            boundColumn.DataField = "DurationType";
            boundColumn.HeaderText = "DurationType";
            grid.MasterTableView.Columns.Add(boundColumn);
            boundColumn = new GridBoundColumn();
            boundColumn.DataField = "Amount";
            boundColumn.HeaderText = "Amount";
            grid.MasterTableView.Columns.Add(boundColumn);
            PlaceHolder1.Controls.Add(grid);
        }

        private void grid_InsertCommand(object sender, GridCommandEventArgs e)
        {
            // Looking to loop through the form so i can insert the values into the datatable
        }





        void grid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            DataTable current = (DataTable)Session["GridData"];
            RadGrid grid = (RadGrid)sender;
            grid.DataSource = current;

        }



        static DataTable GetTable()
        {
            //
            // Here we create a DataTable with a few columns.
            //
            // Create Datatable to store all colums
            DataTable dt = new DataTable();
            DataRow dr = null;
            dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
            dt.Columns.Add(new DataColumn("Size", typeof(string)));
            dt.Columns.Add(new DataColumn("Description", typeof(string)));
            dt.Columns.Add(new DataColumn("Quantity", typeof(string)));
            dt.Columns.Add(new DataColumn("Unit", typeof(string)));
            dt.Columns.Add(new DataColumn("Duration", typeof(string)));
            dt.Columns.Add(new DataColumn("DurationType", typeof(string)));
            dt.Columns.Add(new DataColumn("Amount", typeof(string)));
            dr = dt.NewRow();
            dr["RowNumber"] = 1;
            dr["Size"] = string.Empty;
            dr["Description"] = string.Empty;
            dr["Quantity"] = string.Empty;
            dr["Unit"] = string.Empty;
            dr["Duration"] = string.Empty;
            dr["DurationType"] = string.Empty;
            dr["Amount"] = string.Empty;
            dt.Rows.Add(dr);
            return dt;
        }

最佳答案

请尝试使用以下代码片段。

grid.MasterTableView.Columns.Add(boundColumn);
grid.MasterTableView.EditMode = GridEditMode.InPlace; // I have Added this line
PlaceHolder1.Controls.Add(grid);

如果有任何疑问,请告诉我。

关于c# - Radgrid 自定义插入模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18862485/

相关文章:

c# - C#.Net 中的应用程序关闭时可以中止前台线程吗?

c# - 如何使用wpf xaml绘制均匀间隔的对角线文本

jquery - 如何从客户端通过该时间段的时间或日期获取Telerik调度程序的时间段

c# - 使用 MVVM 在 XAML 中禁用 TelerikGrid 中的行

c# - Lucene Hightlighter 有时会莫名其妙地返回空白片段

c# - 无法在 Vista x64 中的 C# 应用程序中加载 C++ DLL

c# - 随机无法连接到本地MySQL?

html - 将 CSS 样式应用于 asp 内容

c# - 使用 ABCpdf 将 HTML 转换为 PDF

c# - 如何在运行时根据现有数据模型中的数据构建自定义的动态 ViewModel?