Why not seen OnDataBound event?

Posted on 2013-02-01
Last Modified: 2013-02-02
Can you please advise why I can't find out OnDataBound event below for Formview?
Question by:HuaMinChen
  • 2

Accepted Solution

esolve earned 100 total points
ID: 38846171
LVL 10

Author Comment

ID: 38846186
Many thanks. Is there any event similar to OnDataBound for a formview?

Expert Comment

ID: 38846234
I suppose you could use the Databound and Databinding event.

The Databound event fires after the control binds to a source. So you could use this event to retrieve the datarowview like this.

 protected void FormView1_DataBinding(object sender, EventArgs e)
            FormView frm = (FormView)sender;

            DataRowView drv = (DataRowView)frm.DataItem;
            for (int i = 0; i < drv.DataView.Table.Columns.Count; i++)
                if (!string.IsNullOrEmpty(drv[i].ToString()))

Open in new window

You can access a control like this:
Label Label4 = (Label)FormView1.FindControl("Label4");
Label4.Text = price.ToString("c");
LVL 10

Assisted Solution

by:Monica P
Monica P earned 50 total points
ID: 38846534
protected void ItemsFormView_DataBound(object sender, EventArgs e)
       DataRowView dataRow = ((DataRowView)FormView1.DataItem);
        if (Convert.ToInt16(dataRow["ClStk"]) <= 0)
            Label lbl = (Label)FormView1.FindControl("lblStock");
                 lbl.CssClass = "changefont";

Link with sample of bound event

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now