We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Grid As UserControl

Thread ID:

Created:

Updated:

Platform:

Replies:

124313 May 31,2016 08:59 AM Jun 2,2016 11:23 AM ASP.NET Web Forms 3
loading
Tags: Grid
Hrvoje Voda
Asked On May 31, 2016 08:59 AM

I've created a user control and put a grid into it.
Now, i've seen on examples that it's needed to define columns and everything else on that grid.
That's not good for me because I'm getting data from store procedure and I have different colums and different select statement for reports.
That's why properties like Resize to fit don't work.

Is there a way to define that values in code? I'm using VB.net.

Gowthami V [Syncfusion]
Replied On June 1, 2016 08:56 AM

Hi Hrvoje, 

Thanks for using Syncfusion products. 

From your query we suspect that you are returning data from the select statement with different field and then bind it to the grid again. 

If you are doing so then for your scenario there is no need to define the columns for the grid.  

We can use the auto generated columns concept to display all the columns/fields from the assigned data source to the grid. 

Whenever you want to change the data source then assign that data source to the DataSource property of the grid and call the DataBind method in code behind itself. 

Refer to the below code example, 

//Query processing for retrieving data from data base and select command with ifferent columns 
. . . . 
. . . . 
Me.Grid1.DataSource = the data need to be bind to the grid 
Me.Grid1.DataBind() 
. . . . 
. . . . 
 
<ej:Grid ID="Grid1" runat='server' AllowPaging="true" AllowSorting="true" AllowResizeToFit="true"> 
//No need column definition 
</ej:Grid> 

Refer to the below link for more clarification about auto generation, 


If we are misunderstood your requirement please provide us below details to understand your requirement, 

1.       How would you like to change the data source whether in code behind or you want to pass data via any post? 
2.       Do you want to generate a list of columns and grid properties in code behind. 
3.       Explain your requirement clearly. 
 
The provided information will help to analyze the issue and provide you the response as early as possible. 

Regards, 

Gowthami V. 


Hrvoje Voda
Replied On June 1, 2016 09:02 AM

Thank you for your reply.

I solved problem with auto generate columns. It works fine.
My problem remain is that columns are not resized to fit text in rows.
I'.m using AllowResizeToFit="true" but it doesn't help.
How can I resize column by their row width?

Gowthami V [Syncfusion]
Replied On June 2, 2016 11:23 AM

Hi Hrvoje, 
 
By default, the grid columns width get adjusted proportionally to the grid width. So if the columns count is small then the width of the columns set width space irrespective of content width. 
 
If more columns rendered in the grid then the column width adjusted based on the content width. In that situation if the total width of the columns exceed the grid width, then horizontal scroller will be enabled. 
 
So, we suspect that the reported issue is a default behavior when limited number of columns rendered. 
 
If we misunderstood your issue, please share the below details, 
 
1.       Share the screenshot of the issue. 
2.       Grid rendering code with column definition. 
 
The provided information will help to analyze the issue and provide you the response as early as possible. 
 
Regards, 
 
Gowthami V. 
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;