Hi Ram, there is nothing built in, I created my own attribute and then is the Field template I climb the control tree until I find the Html cell then apply the css class.
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
hi steve, thanks for replying. By giving width in css will affect all the tables right? I need to fix different width for different tables. Is there any way to acheive.? It will be more helpful, if you can post or mail some sample .
/// <summary>
/// Get the Data Control containing the FiledTemplate
/// usually a DetailsView or FormView
/// </summary>
/// <param name="control">
/// Use the current field template as a starting point
/// </param>
/// <returns>
/// A FilterRepeater the control that
/// contains the current control
/// </returns>
public static T GetContainerControl<T>(this Control control) where T : Control
{
var parentControl = control.Parent;
while (parentControl != null)
{
var p = parentControl as T;
if (p != null)
return p;
parentControl = parentControl.Parent;
}
return null;
}
and
/// <summary>
/// Get the attribute of type T or null if not found
/// </summary>
/// <typeparam name="T">Attribute type</typeparam>
/// <param name="table">Column to search for the attribute on.</param>
/// <returns>Returns the attribute T or null</returns>
public static T GetAttribute<T>(this MetaColumn column) where T : Attribute
{
return column.Attributes.OfType<T>().FirstOrDefault();
}
That should do it.
I have that manu extension methods now I forget no-one else has them :(
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
Sorry one thing I did miss out :( was thactual attribute
[AttributeUsage(AttributeTargets.Property)]
public class CellCssAttribute : Attribute
{
public String Class { get; private set; }
public CellCssAttribute()
{
}
public CellCssAttribute(String css)
{
Class = css;
}
}
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
Member
7 Points
28 Posts
How to set column width for particular column in dynamic data model asp.net .?
Jun 20, 2014 01:06 AM|RRam|LINK
I have to increase the column width in the grid to accomodate the larger values.
somethign like [column(width = '100px')] .
Please advise what change needs to be done in meatadata page.
Participant
1061 Points
318 Posts
Re: How to set column width for particular column in dynamic data model asp.net .?
Jun 20, 2014 02:01 AM|Dharmesh.Kotadiya|LINK
http://msdn.microsoft.com/en-us/library/ms178296.aspx
Dharmesh M. Kotadiya,
Mark as answer if my anwers helps you
Member
7 Points
28 Posts
Re: How to set column width for particular column in dynamic data model asp.net .?
Jun 20, 2014 02:21 AM|RRam|LINK
thanks for the reply. but the link is for simple asp.net application. Mine is a Dynamic data model entity framework.
All-Star
17916 Points
5681 Posts
MVP
Re: How to set column width for particular column in dynamic data model asp.net .?
Jun 20, 2014 03:53 AM|sjnaughton|LINK
Hi Ram, there is nothing built in, I created my own attribute and then is the Field template I climb the control tree until I find the Html cell then apply the css class.
Always seeking an elegant solution.
Member
7 Points
28 Posts
Re: How to set column width for particular column in dynamic data model asp.net .?
Jun 23, 2014 07:43 AM|RRam|LINK
hi steve, thanks for replying. By giving width in css will affect all the tables right? I need to fix different width for different tables. Is there any way to acheive.? It will be more helpful, if you can post or mail some sample .
thanks again
All-Star
17916 Points
5681 Posts
MVP
Re: How to set column width for particular column in dynamic data model asp.net .?
Jun 23, 2014 07:53 AM|sjnaughton|LINK
No, I create a CSS class like:
.Narrow50
{
width: 50px;
}
Then I use code in the field template:
to walk the control tree and add the CSSClass just to that column.
Always seeking an elegant solution.
Member
7 Points
28 Posts
Re: How to set column width for particular column in dynamic data model asp.net .?
Jun 23, 2014 09:03 AM|RRam|LINK
hi steve, thanks for the demo code.
Is GetAttributes , GetContainerControl are inbuilt methods or custom methods written .?
All-Star
17916 Points
5681 Posts
MVP
Re: How to set column width for particular column in dynamic data model asp.net .?
Jun 23, 2014 10:18 AM|sjnaughton|LINK
oops
and
That should do it.
I have that manu extension methods now I forget no-one else has them :(
Always seeking an elegant solution.
Member
7 Points
28 Posts
Re: How to set column width for particular column in dynamic data model asp.net .?
Jun 24, 2014 01:38 AM|RRam|LINK
Thanks a lot Steve :)
All-Star
17916 Points
5681 Posts
MVP
Re: How to set column width for particular column in dynamic data model asp.net .?
Jun 27, 2014 05:02 AM|sjnaughton|LINK
Sorry one thing I did miss out :( was thactual attribute
Always seeking an elegant solution.