Data Binding techniques for data binding controls

Source: Internet
Author: User
For example, the Image of the DataList control must be bound to the specified Image path.

ImageUrl = '<% # Eval ("database field", "admin/uploading/{0}") %>'

Format the specified date field

<Asp: TextBox Id = "TextBox1" Text = '<% # Eval ("database field", "{0: g }") %> 'runat = "server"> </asp: TextBox>

You can use DataFormatString in the binding column of the Gridview. HtmlEncode = "false" should be added to make the DataFormatString settings take effect.

For example: <asp: BoundField DataField = "SignedDate" HeaderText = "signing date" DataFormatString = "{0: d}" HtmlEncode = "false"/>

The key is the letter next to it, which is commonly used below.

D (6/26/2004) D (Saturday, June 26,2004)

T (8:11 PM) T (8:11:04 PM)

G (6/26/2004 8: 11 PM)

G (6/26/2004 8:11:04)

You can bind a value to the CommandArgument attribute of all server buttons in asp.net. For example:

<Asp: Button id = "Button1" CommandArgument = '<% # Eval ("database field name")' runat = "server"> </asp: Button>

If you want to bind multiple values to the trigger button, you can use "~ "Separated, such:

CommandArgument = '<% # Eval ("database field name") + "~ "+ Eval (" database field name ") %>'

On the. cs page, set the value to e. CommandArgument. ToString.

Special usage of data binding expressions

<Asp: Label id = "Label1" Text = '<% # drop-down box ID. SelectedItem. Text %> 'runat = "server">

You can also bind it with a 3-element operation.

For example, <asp: Label id = "Label1" Text = '<% # Eval ("field name"). Tostring () = "False "? "None": Eval ("field name") %>'

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.