470,614 Members | 1,578 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,614 developers. It's quick & easy.

the DataBound event of FormView

hey

asp.net 2.0

I want to programmatically populate (with data from the database) a label
control in a FormView on a webpage.

Is it a good idea to put my logic inside the DataBound event of the
FormView?

any other suggestions?

Jeff
Aug 29 '06 #1
3 5161
The basic databinding pattern with a FormView is the same as with similar
Databound controls such a GridView. Assuming that all your controls (inluding
the label) have their databound field set,

private void BindData()
{
SqlConnection myConnection = new SqlConnection(ConnectionString);
SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM Users",
myConnection);
DataSet ds = new DataSet();
ad.Fill(ds);
fv1.DataSource = ds;
fv1.DataBind();
FormViewRow row = fv1.Row;
}

You could call the above method inside an if(!Page.IsPostBack) check in your
Page_Load handler.
--Peter
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Jeff" wrote:
hey

asp.net 2.0

I want to programmatically populate (with data from the database) a label
control in a FormView on a webpage.

Is it a good idea to put my logic inside the DataBound event of the
FormView?

any other suggestions?

Jeff
Aug 29 '06 #2
Hey Peter!

thanks for your reply!

But I want to manipulate the data returned from the database before I set
display it in the FormView!

Instead of doing this:
<asp:TextBox ID="helloworldTextBox" runat="server" Text='<%#
Bind("helloworld") %>'>
</asp:TextBox><br />

I want to do something like this (in the code behind page):
helloworldTextBox.text = <db value>;

It's an interesting code you sent me, but I have this already configured. I
want to programmatically manipulate the data returned from db before I show
in the label control

Any suggestions?
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.comwrote in message
news:4C**********************************@microsof t.com...
The basic databinding pattern with a FormView is the same as with similar
Databound controls such a GridView. Assuming that all your controls
(inluding
the label) have their databound field set,

private void BindData()
{
SqlConnection myConnection = new SqlConnection(ConnectionString);
SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM Users",
myConnection);
DataSet ds = new DataSet();
ad.Fill(ds);
fv1.DataSource = ds;
fv1.DataBind();
FormViewRow row = fv1.Row;
}

You could call the above method inside an if(!Page.IsPostBack) check in
your
Page_Load handler.
--Peter
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Jeff" wrote:
>hey

asp.net 2.0

I want to programmatically populate (with data from the database) a label
control in a FormView on a webpage.

Is it a good idea to put my logic inside the DataBound event of the
FormView?

any other suggestions?

Jeff

Aug 29 '06 #3
This is the manipulation I need done to the db data:
String str = reader.GetString(4);
lblInfo.Text = str.Replace(Environment.NewLine, "<br/>");

Maybe I instead could do this data manipulation directly in the stored
procedure (sql server 2005) which returns the datasource to the FormView??
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.comwrote in message
news:4C**********************************@microsof t.com...
The basic databinding pattern with a FormView is the same as with similar
Databound controls such a GridView. Assuming that all your controls
(inluding
the label) have their databound field set,

private void BindData()
{
SqlConnection myConnection = new SqlConnection(ConnectionString);
SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM Users",
myConnection);
DataSet ds = new DataSet();
ad.Fill(ds);
fv1.DataSource = ds;
fv1.DataBind();
FormViewRow row = fv1.Row;
}

You could call the above method inside an if(!Page.IsPostBack) check in
your
Page_Load handler.
--Peter
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Jeff" wrote:
>hey

asp.net 2.0

I want to programmatically populate (with data from the database) a label
control in a FormView on a webpage.

Is it a good idea to put my logic inside the DataBound event of the
FormView?

any other suggestions?

Jeff

Aug 29 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by MasterChief | last post: by
1 post views Thread by Dabbler | last post: by
reply views Thread by crpietschmann | last post: by
2 posts views Thread by justin | last post: by
1 post views Thread by David C | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.