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

RadInputManager with Auto Generated Columns

7 Answers 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Karl
Top achievements
Rank 1
Karl asked on 20 Oct 2013, 05:20 PM
Greetings!

My Radgrid uses a SqlDataSource that is a dynamically created pivot table. As such, the columns can be different whenever the Radgrid is loaded, and I am therfore letting the columns auto generate. Additionally, I am setting each of the fields to be editable using these two bits:

On the ItemCreated Event:
If TypeOf e.Item Is GridEditableItem Then
    e.Item.Edit = True
End If

On the PreRender Event:
CType(sender, RadGrid).Rebind()

And this works for my purposes. However, as more cells are rendered, performance takes a noticeable hit. And I'm not talking about thousands of records - only dozens. I've followed a few of the steps outlined in the "Client/server grid performance optimizations"  and set the ViewState to false, and I've enabled RadCompression. But I suspect that the culprit is the heavy edit boxes. Is there a way to make the MS TextBoxes load instead of Telerik NumericTextBoxes?

Thanks!

Karl

7 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 23 Oct 2013, 02:26 PM
Hi Karl,

In order to use the RadInputManager, you will need DataBound or Template Columns. As in this demo:
http://demos.telerik.com/aspnet-ajax/input/examples/radinputmanager/dynamicinputfiltersettings/defaultvb.aspx?product=grid
So you need to turn off the AutoGeneratedColumns and generate them manually. You can do this dynamically as shown in this demo:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/groupby/defaultcs.aspx

You will have to get the data from your datasource. Create the grid based on columns in this data, and then bind the grid to this data. To avoid 2 requests to your database, store the data inside a DataTable in your code behind. The correct implementation will depend on your datasource, so it will be hard to make you universal example without having your exact specifications.

Regards,
Vasil
Telerik
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 the blog feed now.
0
Karl
Top achievements
Rank 1
answered on 24 Oct 2013, 12:35 AM
Vasil,

Thanks for your reply.

I'm not sure if you missed it, but the reason I'm autogenerating colums is because I don't know what they will be at runtime. The example you provided, where columns are created "dynamically", each column is explicitly declared. This would not work in my case at all.

I don't necessarily need to use the RadInputManager. But I would like a way to make the grid lighter. If RadInputManager won't work with autogenerated columns, is there another way?

Thanks,

Karl
0
Vasil
Telerik team
answered on 24 Oct 2013, 08:59 AM
Hello Karl,

You can add the columns runtime, depending on the data in your datasource.

Do not of hard code the column names as in the demo.
Get the data, loop thought the columns in the DataTable that contains your results and add such columns to the grid. Then bind the grid to this DataTable.

Regards,
Vasil
Telerik
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 the blog feed now.
0
Karl
Top achievements
Rank 1
answered on 24 Oct 2013, 07:52 PM
Vasil,

Thanks for your reply.

Can you provide an example of what you're describing, preferably with a pivot tabe as an SqlDataSource?

Thanks,

Karl
0
Vasil
Telerik team
answered on 29 Oct 2013, 12:57 PM
Hello Karl,

You could find lots of different examples here in the forums. We could not create a custom project for each request, but if there is lots of interest, probably we could create a Code Library. You could also do such after you research, if you publish it here, you will win some telerik points.

Regards,
Vasil
Telerik
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 the blog feed now.
0
Karl
Top achievements
Rank 1
answered on 29 Oct 2013, 09:15 PM
Vasil,

I of course searched the forums prior to posting. The reason I posted the question was because I did not see the solution I was seeking. I did not request a custom project - merely an example of the solution that you yourself suggested.

I am happy to utilize a solution that has been recommended in the forums previously - the fact that it was suggested to someone else makes it likely that that person tested the solution and provided feedback. So, if the solution you suggested is so abundant, would you mind posting a link to just one such post - rather than the generic search terms "columns runtime", which returns forum posts from over 5 years ago - the first of which filled with complaints about the linked solutions themselves being unhelpful and out of date.

Again, the most helpful example would be of one with a pivot table as an Sql data source.

Thanks,

Karl
0
Vasil
Telerik team
answered on 31 Oct 2013, 08:02 AM
Hi Karl,

Here is an example how to add the columns runtime based on the columns in the provided data source.

public partial class Default : System.Web.UI.Page
{
 
    DataTable data;
 
    protected void Page_Load(object sender, EventArgs e)
    {
        data = GetDataFromDatabase();
        AddGrid(Page.Form);
    }
 
    protected void AddGrid(Control ParentControl)
    {
        RadGrid RadGrid1 = new RadGrid();
        RadGrid1.ID = "RadGrid1";
        ParentControl.Controls.Add(RadGrid1);
        RadGrid1.NeedDataSource += RadGrid1_NeedDataSource;
 
        if (!IsPostBack)
        {
            RadGrid1.AutoGenerateColumns = false;
            RadGrid1.AllowSorting = true;
            RadGrid1.AllowPaging = true;
            RadGrid1.PageSize = 7;
 
            foreach (DataColumn col in data.Columns)
            {
                GridBoundColumn boundColumn;
                boundColumn = new GridBoundColumn();
                RadGrid1.MasterTableView.Columns.Add(boundColumn);
                boundColumn.DataField = col.ColumnName;
                boundColumn.HeaderText = col.ColumnName;
            }
        }
    }
    void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        (sender as RadGrid).DataSource = data;
    }
 
    protected DataTable GetDataFromDatabase()
    {
        DataTable dataTable = new DataTable();
        dataTable.Columns.Add("Column1");
        dataTable.Columns.Add("Column2");
        for (int i = 1; i < 20; i++)
        {
            dataTable.Rows.Add("Col1_" + i, "Col2_" + i);
        }
        return dataTable;
    }
}

If you like to populate your DataTable from SqlDataSource, check this article:
http://stackoverflow.com/questions/11993211/how-to-fill-datatable-with-sql-table

Regards,
Vasil
Telerik
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 the blog feed now.
Tags
Grid
Asked by
Karl
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Karl
Top achievements
Rank 1
Share this question
or