473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

GridView, ODS, Entity and DataObjectFieldAttribute

Does the DataObjectFieldAttribute have any affect on the GridView by way of
an ODS?

In partuculare, I was hoping that the max length of a text box within a
gridview would be set to the length property of the attribute but it seems
to have no affect. Any info would be helpful. Thanks,

public class CustomerEntity {

[DataObjectField(false, false, false, 25)]
public String FirstName {
get { return firstName; }
set { firstName = value; }
}

Jan 27 '07 #1
5 2275
Hi Andrew,

It seems the DataObjectFieldAttribute currently is only used by designers
such as ObjectDataSourceDesigner. It's not used at run-time by GridView to
configure the default edit template's TextBox's MaxLength.

I'll see if there's a better workaround other than creating a TemplateField
and set the MaxLength manually.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 29 '07 #2
You answer is what I thought to be the case. Its addition would be a nice
feature for Orcas.

Guessing I will attempt to write a little "Helper" method that reads a
GridView and sets the templated field maxLength properties but guessing that
might not be possible with non-templated bound columns.

-Andy

"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:%2******************@TK2MSFTNGHUB02.phx.gbl.. .
Hi Andrew,

It seems the DataObjectFieldAttribute currently is only used by designers
such as ObjectDataSourceDesigner. It's not used at run-time by GridView to
configure the default edit template's TextBox's MaxLength.

I'll see if there's a better workaround other than creating a
TemplateField
and set the MaxLength manually.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your
reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Jan 29 '07 #3
Hi Andrew,

For non-templated bound columns, we could use the RowDataBound event to
manually set the TextBox's MaxLength according to the bound object's
DataObjectFieldAttribute:

protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (Gridview1.EditIndex != -1 && e.Row.RowIndex == Gridview1.EditIndex
&& e.Row.DataItem != null)
{
Type t = e.Row.DataItem.GetType();
Dictionary<string, intml = new Dictionary<string,int>();

foreach (PropertyInfo pi in t.GetProperties())
{
DataObjectFieldAttribute dofa =
Attribute.GetCustomAttribute(pi, typeof(DataObjectFieldAttribute)) as
DataObjectFieldAttribute;
if (dofa != null && dofa.Length >= 0)
{
ml.Add(pi.Name, dofa.Length);
}
}

if (ml.Count 0)
{
foreach (DataControlFieldCell dcfc in e.Row.Cells)
{
BoundField bf = dcfc.ContainingField as BoundField;
if (bf != null && dcfc.Controls.Count 0)
{
TextBox txt = dcfc.Controls[0] as TextBox;
if (txt != null)
{
if (ml.ContainsKey(bf.DataField))
{
txt.MaxLength = ml[bf.DataField];
}
}
}
}
}
}
}
Hope this helps.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 30 '07 #4
Thanks. Will give it a try.

-Andy
"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:mx**************@TK2MSFTNGHUB02.phx.gbl...
Hi Andrew,

For non-templated bound columns, we could use the RowDataBound event to
manually set the TextBox's MaxLength according to the bound object's
DataObjectFieldAttribute:

protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (Gridview1.EditIndex != -1 && e.Row.RowIndex == Gridview1.EditIndex
&& e.Row.DataItem != null)
{
Type t = e.Row.DataItem.GetType();
Dictionary<string, intml = new Dictionary<string,int>();

foreach (PropertyInfo pi in t.GetProperties())
{
DataObjectFieldAttribute dofa =
Attribute.GetCustomAttribute(pi, typeof(DataObjectFieldAttribute)) as
DataObjectFieldAttribute;
if (dofa != null && dofa.Length >= 0)
{
ml.Add(pi.Name, dofa.Length);
}
}

if (ml.Count 0)
{
foreach (DataControlFieldCell dcfc in e.Row.Cells)
{
BoundField bf = dcfc.ContainingField as BoundField;
if (bf != null && dcfc.Controls.Count 0)
{
TextBox txt = dcfc.Controls[0] as TextBox;
if (txt != null)
{
if (ml.ContainsKey(bf.DataField))
{
txt.MaxLength = ml[bf.DataField];
}
}
}
}
}
}
}
Hope this helps.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.
Jan 31 '07 #5
Hi Andy,

Have you tried the workaround? Does that work for you? Please feel free to
let me know if there's anything else I can help.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 2 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ed Dennison | last post by:
I'm starting to look at DocBook-XML (not SGML) for producing a large documentation set. The hierarchy of DocBook elements for organizing the content is (more or less); set book part chapter...
11
by: Douglas Reith | last post by:
Hi There, Can someone please tell me why the XML spec states that an attribute value with an external entity is forbidden? Or point me to the appropriate document? Or better still, perhaps you...
4
by: terry | last post by:
could someone tell me how to add or remove entity to a xml file when i dim xmlentity as new xmlentity it's say it's sube new is private thks
4
by: GregG | last post by:
Greetings, I have been working with the new GridView control, and while figuring out most of it's idiosyncrasies on my own, have stumbled upon a problem I cannot seem to resolve. We have...
5
by: BenG | last post by:
Hi. I have a gridview control on a web form (asp.net 2.0) that's bound to a objectDataSource. The objectdatasource which is bound to a class I've written in the DAL to read and update the database....
12
by: dixonjm | last post by:
Hi, I am new to gridviews, so any help would be most appreciated. Here is my problem:- I have a form with a GridView and a button. My gridview is bound to a collection (12000 items) (PageSize...
1
by: Dev147 | last post by:
I need to dynamically create a GridView that contains a variable number of columns that must be bound to an underlying collection in an entity class. These columns represent days from a specified...
17
by: ata | last post by:
Hi folks, Consider a gridview that's being bound to a ObjectDataSource that uses an adapter to handle data access logic. 1. How am I supposed to have a RowIndex column *without* modifying the...
7
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
I'm adding subheadings to a gridview. Each sub head has a few link buttons. I'm adding the controls in the rowdatabound event code follows: sorry about the length here. I have to be missing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.