FormView OnDataBound - how to access select record field values in code behind

Hi,   Can someone help me out here.  Maybe this is a dumb question but why does FormView OnDataBound not have RowEventArgs the same as RowDataBound on a GridView?  Without RowEventArgs how can I access the values of the fields in the selected record when the FormView OnDataBound is fired? Indifferent

 When the GridView RowDataBound fires before each row is rendered I can use

DataBinder

.Eval(e.Row.DataItem, "MyFieldNameHere").ToString()

and then happily work with the data, but Im finding the FormView a bit limiting as I cant get at the field values easily OnDataBound.  I have had to resort to adding the fields I want into the DataKeys and getting the values back from there - but that seems like a really messy workaround.  Is FormView really just for very simple, quick and easy 'mark-up' only style Results, Details systems?

Al

0
kira1
2/16/2007 5:44:44 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
1252 Views

Similar Articles

[PageSpeed] 45

It seems like you can not access the data on the binding event.  Maybe because a form view will only display one record at a time, so you really wouldnt need to access it as it was being bound.  You could probably accomplish what you needed before binding.

I did notice, however, that the ItemInserting/Updating/Deleting events all have those special event handling parameters.


Josh Stodola ← Come check out my blog!
0
JoshStodola
2/16/2007 6:21:05 PM

You could use the DataItem property of the FormView

ex:

value = ((DataRowView)FormView1.DataItem)["fieldName"].ToString();

 Hope this helps.

 Regards,

Gasser

0
gasser
11/12/2007 6:30:14 PM
Thanks so much for the DataItem tip.  I searched a lot before finding your post.  It's exactly what I was looking for.
0
babreu
10/16/2008 11:59:18 PM
Reply:

Similar Artilces:

How to access the file field control value in code behind
Hi Guys,Please anyone help meHow to access the file field control value in code behindBelow is my HTML View  <mobile:Panel id="pnleSMSBody" Runat="server">    <mobile:DeviceSpecific id="dseSMSBody" Runat="server">     <Choice Filter="isHTML32">       <ContentTemplate>           <INPUT type="file" size="60" runat="server" id="File1">    ...

Accessing SQL datasource selected values in code behind when they're pulled from formview, listview, datagrid, etc..
Hello, In my usage of asp.net 2.0 so far I've been having a consistent lack of technique at one particular concept: In my code behind with vb, getting at the values pulled by my sql datasource that are used in my formviews, listviews, etc... What are some of the general techniques to accomplish this? What are the easiest ways? If I try to assign output parameters in my query I get errors because sql doesn't want them being used for the data consuming controls as well as assigning parameters. Lately I've been making the textboxes that are populated by the f...

accessing certain databound control value from the code behind -- in a repeater control
I have a <asp:repeater> control  and in that I have a <asp:hyperlink> within the <ItemTemplate> tag.  I have to do some calculations regarding the parameter I am using in the hyperlink.  I have to do this in the code behind.  Say I have to get the propertyID from a table.  If its in the .ascx, then its easy - I can do <%# Eval("propertyID") %>.  But how do I access this from the code behind? In your HTML you write the code like this: <%# DoStuff(Eval("ProcedureID").ToString()) %>   And in your code behi...

when loading a previously created record on to form, some controls are missing values(controls are depended on values selected in other controls)
Hello - I have created a page for Editing records.  this page will open up a chosen record and allow user to edit the data.On the form, I have 3 drop down lists.   The second dropdown list should fill values depending on value chosen in first dropdown list.  The third dropdown list should show/fill values depending on value chosen in second dropdown list.So taking this into count, i have several records with various data.  When I open-up/load a record in Edit form, only the first dropdown list has a value selected that was the pre-existing va...

Error accessing formview control in code behind.
<asp:FormView ID="FormView1" runat="server" DataKeyNames="ID"         DataSourceID="sdsListBusmanDetail" DefaultMode="Edit"><EditItemTemplate>            <asp:Label ID="ID" runat="server" Text='<%# Bind("ID") %>' Visible="false" />             <asp:Label ID="MotivationTextBox" runat="server"   &nb...

access user control value from code behind
Hello.I have the following issue and I was hoping that someone might be able to help.I have a user control that loads a dropdownlist from a database.However, I cannot find a way to get thecurrently selected value of the dropdownlist for use in a different function in my code behind file.Here is my user control:Imports SystemImports System.WebImports System.Web.UIImports System.DataImports System.Data.SqlClientImports System.Web.UI.WebControlsPublic Class locations : Inherits UserControl    Public ddlLocs As DropDownList    Sub Page_Load(ByVal Source As Object, ByVal E As ...

Not able to access the hidden field value in the code behind
Hi I have to find which button is clicked in the page Load itself. For that I have written a Java script function which sets  the value of a hidden field in the  OnClientClick method. . But when I try to access the hiddenfield value in the code behind, I am getting the old value only. I am attaching the code here   Java script function: 1 function setExportFlag() 2 { 3 var hiddenField = document.getElementById('ctl00_ContentPlaceHolder1_hfButtonClick'); 4 hiddenField.value = '1'; 5 retur...

Accessing Form Controls via code behind (VB.NET)
Hi,I hope someone can help provide some light on this problem I'm having. I have searched the forums and found another post on ASP.NET that references how to access controls on a form using for example:Dim lstResourceServers As WebControl = frmASP.FindControl("lstResourceServers")This will indeed give me access to the listbox control on the form but I can't access the properties and methods specific to the listbox control class such as Items, SelectedIndex, etc. which to me is rather pointless.If I place a listbox or any other component on my asp.net page I can directly acc...

Set Datasource to Drop Down Control in FormView InsertTemplate Field through Code Behind
Hey , How do I set Datasource to Drop Down Control in FormView InsertTemplate/EditItemTemplate Field through Code Behind. I need this as we use general connection objects and general data retrival methods in a common Data Class. Please help? Thanks, Shyam Hi, raghavashyam: You just need to bind the datasource to the FormView(Containers) and the syntax as following in the templateFiled will bind the particlar filed to your controls.  <asp:TemplateField HeaderText="Name" >               &nb...

Accessing user control in repeater from code behind in VB.net would be great
Hello i have a repeater which has a user control hard coded inside of it. I would like to be able to access the properties of the user control from code behind, but am having no luck "seeing" the usercontrol. If someone could help me out, that would be great.  Here is the repeater....<asp:Repeater ID="Repeater0" runat="server"> <HeaderTemplate> </HeaderTemplate> <ItemTemplate> <uc1:billToInfo ID="billToInfo1" billTo="<%#Container.dataItem %>" runat="server" /> </It...

Change Value of a Textbox that is inside of a FormView using Vb.Net code behind.
I am having trouble adding text to a textbox that is nested in a form. What I want to do is pre-fill out the insertview form if the user already has their info on file so they don't have to fill out the name, address, etc. each time. Any help will be greatly appreciated.Dan5150www.5150creations.com Hi, You need to define a variables as textbox and assign them to the textbox controls within the FormView by using 'FindControl'. E.g.  Dim MyText As TextBox = CType(FormView1.FindControl("txtMyTextbox"), TextBox) Then you can set the TextBox text value as follow...

Programmatically accessing field value using BLL and Tableadapter with code behind function
I need some clarity, or instruction, on how to programmatically retrieve the value from an SQL SELECT query retrieved through a TableDataAdapter and BLL function.I simply want to call, on the page, a function to retrieve a string value from the database, i.e. SomeFunction(integer) would return a String e.g. GetCustomer(ID) would return customer name.I know how to do this using both on page SQLDataSource and ObjectDataSource objects. What I am currently trying and having difficulty with is that I want to call this "GetCustomer" from within an existing Repeater which is already datab...

Selecting value in one field then causes value in another field to be selected.
I have a web form which contains a date field, the date is populated using a DatePicker which is Javascript based. The form also has a drop down box containing 3 values. What I want to do is when a date has been selected that this will cause the dropdown list value to change to dated which is one of its 3 values. i.e. when the date field is not blank then the value will be selected in the dropdown. What I also want to happen is when the date has been selected and the dropdown value is dated then the date field and the dropdown field will be set to read only.Anyone any ideas how to this usin...

Accessing FormView control from user control code?
Hi,I'm having problems accessing the FormView from the code in a user control I've made... The UC is displaying the product title, text and image and I need to manipulate the image height & width properties. For this I need to access the raw data in the Formview but how can I instantiate the Formview from my user control??<asp:FormView ID="FormView1" runat="server" DataSourceID="AccessDataSource1">   <ItemTemplate>      <MyUControls:ProductItem ID="ShowProduct1" runat="server"/>   </ItemTemplate></as...

Web resources about - FormView OnDataBound - how to access select record field values in code behind - asp.net.presentation-controls

dotnet HighCharts inside UpdatePanel
... to get functioning a dotnet.HighCharts chart inside a... Since I want to add the possibility to chose all the kind of pizza, I've added a onDatabound ...

Resources last updated: 2/5/2016 9:44:35 AM