PC Review


Reply
Thread Tools Rate Thread

the DataBound event of FormView

 
 
Jeff
Guest
Posts: n/a
 
      29th Aug 2006
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      29th Aug 2006
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
>
>
>

 
Reply With Quote
 
Jeff
Guest
Posts: n/a
 
      29th Aug 2006
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]" <(E-Mail Removed)> wrote in message
news:4C96A67E-E381-4F1C-B90B-(E-Mail Removed)...
> 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
>>
>>
>>



 
Reply With Quote
 
Jeff
Guest
Posts: n/a
 
      29th Aug 2006
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]" <(E-Mail Removed)> wrote in message
news:4C96A67E-E381-4F1C-B90B-(E-Mail Removed)...
> 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
>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FormView Null databound value David C Microsoft ASP .NET 1 8th Dec 2007 09:49 PM
Validating event in databound controls =?Utf-8?B?TWFydGluIFN0ZXR0bmVy?= Microsoft Dot NET Framework Forms 1 13th Nov 2006 07:46 PM
GV Databound Event vs DG ItemDataBound Event GaryDean Microsoft ASP .NET 1 18th Aug 2006 04:47 AM
DropDownList missing Databound Event ? Olivier Matrot Microsoft ASP .NET 1 10th Feb 2005 12:11 PM
Parse event for databound controls in CF Minh Kama Yie Microsoft Dot NET Compact Framework 0 9th Jul 2004 05:04 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:09 PM.