using DataBinder.Eval programatically

  • Thread starter Thread starter Jeronimo Bertran
  • Start date Start date
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
 
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.
 
Back
Top