473,324 Members | 2,456 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,324 software developers and data experts.

How to set databinding.eval in code?

Sue
Is there a way to take datagrid .aspx like this:

<asp:Label runat="server" Text='<%# DataBinder.Eval
(Container, "DataItem.Somefield") %>'></asp:Label>

and set it in code like this:

sub setMyLabel()
MyLabel Label = new Label
With Me.MyLabel
.ID = "SomeID"
.???
End With
End Sub

and end up with the same functionality?

tia,
Sue
Jul 19 '05 #1
2 3119
Hi Sue,

I am not very clear about what you are trying to do.

1. Do you have any special requirement to bind the label to a column
dynamically?
2. ItemDataBound fires for each record. That means your code bind the label
to a column many time.
3. Why not bind the label at design time and change its properties
dynamically?

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.Item Then
Dim lb As Label = e.Item.FindControl("Label1")
If Not lb Is Nothing Then
Dim rd As New System.Random()
Dim r As Integer = rd.Next(255)
Dim g As Integer = rd.Next(255)
Dim b As Integer = rd.Next(255)
lb.ForeColor = Color.FromArgb(r, g, b)
End If
End If
End Sub

HTH,

--
Parker Zhang
Microsoft Developer Support

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

Jul 19 '05 #2
Sue
>I am not very clear about what you are trying to do.

1. Do you have any special requirement to bind the label to a columndynamically?


Hi Parker: My intent in the end, is to keep the aspx page
from being overwhelmed by hundreds of lines of code
needed to declare an object, set attributes, bind-data,
etc. If I can set object attributes/data-binding as much
as possible programatically, then simply declare the
object in the .aspx page, it would make things much
cleaner and easier to work with. Ultimately I'd like to
have each column in it's own class. The ultimate goal is
to be able to put and pull class objects on a aspx page
as needed.

I'm open to suggestions as to how to accomplish these
goals. My shop is new to VB.NET and we're still trying to
get our arms around it and establish best practices for
the dept.

Does this help or confuse?

Sue
Jul 19 '05 #3

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

Similar topics

1
by: oafyuf | last post by:
Hi, I'm trying to learn ASP.NET by doing a pilot project: I have a DataGrid which contains a nested DataList. I want to iterate through the SQLDataReader for the DataGrid and populate each...
3
by: Peter Morris [Droopy Eyes Software] | last post by:
Hi all When I bind to multiple records I use a DataList. This allows the web-designer to add code like <%#DataBinder.Eval(Container.DataItem, "Name")%> Whenever I want to retrieve a single...
2
by: Steven | last post by:
Hi, I'm having an odd problem with late databinding (using DataBinder.Eval). I have my Business Logic and Facade assemblies in the GAC, and just about everything works fine, however, when using...
4
by: dtblankenship | last post by:
Hello everyone, I know this question has been asked many times in the forums, and after spending a few days reading, I am still confused as to the answer. I have a ListBox (lstBox),...
4
by: Nathan Sokalski | last post by:
I have two databinding expressions (the first & last names from a DB) that I want to assign to the text property of a Label so that the result is LASTNAME,FIRSTNAME. At the moment, I have the...
6
by: Nathan Sokalski | last post by:
I am using a DataSet as the DataSource of a DataList in my code. The SQL used to get the data from the database begins with: SELECT...
9
by: Nathan Sokalski | last post by:
I have a very simple UserControl which contains an Image and a Label, which I use to display an image with a caption. I am using this control inside a DataList, setting the two Public variables...
1
by: Owen Blacker | last post by:
I've spent loads of time Googling to try to work this one out and I'm sure it's something obvious. I get an InvalidOperationException reading "Databinding methods such as Eval(), XPath(), and...
1
by: Mundo | last post by:
Hi I'm pulling my hair out with a problem caused when DataBinding a DataSet to a web control. I first tried using a GridView but when that failed, I tried a Repeater. I'm getting the classic...
3
by: mesut | last post by:
Hi colleagues, I hope someone have experience with these databinding techniques in aspx... and can explain me the reason? I've got a listview and I would like to fix these #3 problems just to...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.