Hi,
First. Thanks a lot for this 1nderful work. Time saver. Love it.
I think i found a bug (not sure, if it was addressed earlier or in a separate thread. I could be wrong also...)
Problem:
When you specify both the DataTextField and the DataValueField the label ends up getting the contents of the value field.
(Cant seem to upload images, Admin please send me an email so that i can send an image to you)
Solution:
I think a break is needed inside the first if statement.
Can some gurus comment please.
Thanks once again
Int the .aspx page or .ascx control if you have this...
<data:EntityLabel
ID="label1"
runat="server"
DataSourceID="SomeDataSource"
DataTextField="somefieldName"
DataValueField="somefieldId"
DataTextFormatString="My text value={0}">
</data:EntityLabel>
Then the EntityLabel.cs has this...
/// <summary>
/// When overridden in a derived class, binds data from the data source to the control.
/// </summary>
/// <param name="data">The <see cref="T:System.Collections.IEnumerable"></see> list of data returned from a <see cref="M:System.Web.UI.WebControls.DataBoundControl.PerformSelect"></see> method call.</param>
protected override void PerformDataBinding(System.Collections.IEnumerable data)
{
if (data == null)
{
return;
}
// get the next data item
IEnumerator e = data.GetEnumerator();
while (e.MoveNext())
{
// get the text item if specified
if (!string.IsNullOrEmpty(DataTextField))
{
this.Text = DataBinder.GetPropertyValue(e.Current, DataTextField).ToString();
// I think we need a break; here
}
// get the value item if specified
if (!string.IsNullOrEmpty(DataValueField))
{
this.Text = DataBinder.GetPropertyValue(e.Current, DataValueField).ToString();
}
// we only do the first item
break;
}
}