using DataBinder.Eval programatically

J

Jeronimo Bertran

Hi,

I currently have the following HTML code for a button:

<asp:Button id=SelectButton runat="server" Text='<%# DataBinder.Eval
(Container.DataItem, "PageName") %>' CommandName='<%# DataBinder.Eval
(Container.DataItem, "PageName") %>'> </asp:Button>

The text for the button is evaluated at runtime. I am now trying to do
the same but for a button that I create programatically:

Button btn = new Button();
btn.ID = "SelectButton";
btn.Text = "<%# DataBinder.Eval(Container.DataItem, \"PageName\") %>";
btn.CommandName = "<%# DataBinder.Eval(Container.DataItem, \"PageName\")
%>";
container.Controls.Add(btn);

However, the text is literally the string.

Thanks,

Jeronimo
 
J

Jacob Yang [MSFT]

Hi Jeronimo,

As I understand, you want to know "How to use DataBinder.Eval
programatically in the C# code".

Based on my research and experience, the following Knowledge Base article
is useful to you. Please refer to it carefully.

HOW TO: Use the ItemDataBound Event of Web Forms List Controls in Visual C#
.NET
http://support.microsoft.com/default.aspx?scid=kb;en-us;317582
"...
protected void FormatRepeaterRow(Object sender, RepeaterItemEventArgs e)
{
if( (e.Item.ItemType == ListItemType.Item) || ( e.Item.ItemType ==
ListItemType.AlternatingItem))
{
DbDataRecord dbr = (DbDataRecord)e.Item.DataItem;
if( Convert.ToString(DataBinder.Eval(dbr, "Country")) == "USA" )
((Label)e.Item.FindControl("lblContactName")).ForeColor =
System.Drawing.Color.Red;
}
}
..."

Does it answer your question? If I have misunderstood your concern, please
feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top