.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
" yc=""><tr>
"><td> <strong> Gender: </ strong> </ td>
Post New Web Links

How to fill a formview at page_load?

Posted By:      Posted Date: September 12, 2010    Points: 0   Category :ASP.Net
I have a formview and I want to fill it at page_load. The formview must show the data of the person that has logged in.So the question is how can I fill the formview so that is shows the data of the right person (UserId = @Param2) so that the formview is in editmode?This is the code for the Formview:<asp:FormView ID="FormView1" runat="server" DataKeyNames="UserId" DataSourceID="MySQLProfielDataSource"> <ItemTemplate> <asp:Table id="ItemTabel" runat="server"> <asp:TableRow> <asp:TableCell> UserId: </asp:TableCell> <asp:TableCell> <asp:Label ID="UserIdLabel" runat="server" Visible="false" Text='<%# Eval("UserId") %>' /> </asp:TableCell> </asp:TableRow> <asp:TableRow> <asp:TableCell> Geslacht: </asp:TableCell> <asp:TableCell> <asp:Label ID="Gesla

View Complete Post

More Related Resource Links

FormView clearing value I set in page_load.

I have a page with a FormView on it. The page is strictly for adding records to a Table. I have the FormView bound to an EntityDataSource and everything works greate except for one thing. I want to initialize a date field in the FormView to today's date. So, in my page_load event I have:               if (!Page.IsPostBack)            {                //Initialize SetupDate to today.                TextBox setupdate = (TextBox)fvJob.FindControl("txtSetupDate");                setupdate.Text = DateTime.Now.ToShortDateString();            } The first time this page loads, the txtSetupDate field is initialized. Although, and subsequent loads of the page doesn't initialize the Text Box. I step through the code in the debugger and I can see that the code is executig, but something (the FormView bind?) is "clearing" the Text Box. Any ideas? Why does it work on the first load, but not subsequent ones? Thanks for any help!  

How to fill data from a login to a Formview?

I want to fill a Formview when accessing the webpage where it's on (Page_Load). The data I have when somebody want to go to this page is his logindata.  The only code I see I can use is "User.Identity.Name". But I want his Id, so I can get to fill his UserId. I don't know how to do this. I'm using MySql as a database. My code is (a part of it):I want to fill a Formview when accessing the webpage where it's on (Page_Load).The data I have when somebody want to go to this page is his logindata. The only code I see I can use is "User.Identity.Name".But I want his Id, so I can get to fill his UserId. I don't know how to do this.I'm using MySql as a database.My code is (a part of it):<asp:FormView ID="FormView1" runat="server" DataKeyNames="UserId" DataSourceID="MySQLProfielDataSource"> <ItemTemplate> <asp:Table id="ItemTabel" runat="server"> <asp:TableRow> <asp:TableCell> UserId: </asp:TableCell> <asp:TableCell> <asp:Label ID="UserIdLabel" runat="server" Visible="false" Text='<%# Eval("UserId") %>'

Does somebody know how to fill a formview?


I have a formview and I want to do a lot with it.

First I want to go from page a to page b where page b is a formview in insert mode.

After the data is in a database a want to go to page b in select mode (readonly). With a button I want to go to update mode, so you can change your profile.

But whatever I do, I stuck with filling up the formview and get the right data.

My program exist off fist make a user with a create user wizard. This works by the way.

Then after this is done I want to go to a profile page and there you have to fill in your address etc... This also works.

But what doesn't work is that when somebody has filled in his profil and useraccount is to go back to his profile data.

I have use the following code:

            FormView1.DefaultMode = FormViewMode.ReadOnly;


FormView1.DefaultMode = FormViewMode.ReadOnly;

What are the options to change mode and what do I have to

Formview LinqData source not allowing updates


OK, I'm confused.  I've set up a formview with a Linqdata source to allow users to edit records.  When I run it, edit data and submit, it blows up and tells me "Linq datasource6  does not support the Select property when the Delete, Insert or Update operations are enabled."  I googled that warning and saw a couple of posts on this forum saying the problem is the slect statement has to be removed from the Linq data source for it to allow updates. 

But if I remove the select statement then how do I show the user specific info on pageload?   plus I thought the two way databind was an advantge of the datasource control.




FormView -- Parameters and asp:Table


I've already solved this problem to my satisfaction, I just want to know WHY it works this way.

I have a FormView control bound to an ObjectDataSource.  Let's say our data source is a hypothetical table with three columns:  id, name, age.  Why is it that when I use the <asp:Table> element inside of the FormView, the parameter values are not set, but when I use the standard <table> tag, it works fine?

This seems like a .NET problem to me.  I expect the <asp:Table> element to work in the same way as <table> because they are, for all intents and purposes, the same thing.  Am I missing something?

DropDownList within FormView Error

I have a FormView which works find and I have added a new DropDownList within the form which references another table to which I need to select a value,
I have added the dropdownlist2 and setup a new connection string to this, when I run the page I get this error:

Could not find control 'DropDownList2' in ControlParameter 'CurrencyID'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Could not find control 'DropDownList2' in ControlParameter 'CurrencyID'.
any help would be greatly

Help ~~ How to Update Binary Image on Formview

Hi All ~~ I'm confused, Can i have some help please... Thanks
Database: Books
uid dataType uniqueidentifier
Cover dataType image 
aspx :
 <asp:FormView ID="FormView1" runat="server" BackColor="LightGoldenrodYellow"   BorderColor="Tan" BorderWidth="1px" CellPadding="2" DataKeyNames="uid"     DataSourceID="SqlDataSource1" ForeColor="Black" Width="525px">
         <table class="table_width">
                 <td class="imageWidth">
                     <asp:Image ID="Image1" runat="server" Height="245px" 
                                       ImageUrl='<%# IIF(Eval("Cover") Is DbNull.Value, "~/Styles/Global/CFZ-No-Images.png", Eval("uid", "~/ImageServices.ashx?BooksID={0}")) %>' Width="180px" />

Help with displaying formview based on dropdownlist


I have a formview1 with a dropdownlist1 in the insert template. Based on the value of that dropdownlist I would like to display a second formview on the same page in insert mode so that I can write data to two different tables.

How can I accomplish this?

Is this the best way to do it?



FormView KeepInEditMode=true isn't retaining values


I have an "Edit Page" in my application. It uses a FormView bound to an EntityDataSource.

I have a handler setup for the FormView OnItemUpdated event. If an exception occurs (such as foreign key constraints or non date vales entered in a date colum, etc.), then I set the "KeepInEditMode=true". This is SUPPOSED to retain the user entered values on all of the text boxes instead of rebinding the FormView to the data again and clearing those text boxes. (Right?)

Well, it isn't working...

I have stepped through the code via the debugger and the "KeepInEditMode" does get set to true, but as soon as the page reloads, the values revert back to the original database values (the data is being rebound).

I should also mention that I am setting "ExceptionHandled" to true. I am doing this because I am handling the Exception by displaying an error in a specific area of the page and if I dont mark it as handled, IE generates an Exception popup.

Any ideas?

FormView Text Field Being Set by A Drop Down List


Hello, I have a FormView which is used to insert a record into a database.  Outside of this formview i have a drop down list, I want to grab the value from that drop down list and set one of the text fields within the formview to it's currently selected value.  I've tried the following code, but the dynamic categorytextbox line is what seems to not be working.

                    <asp:DropDownList ID="ddlCategory" runat="server" AutoPostBack="True" 
DataSourceID="SqlDataSourceCategory" DataTextField="CategoryName"
DataValueField="CategoryID" Width="200px">

                            <asp:TextBox ID="CategoryIDTextBox" runat="server" 
Text='<%# Bind("CategoryID") %>' Visible="False" />

        protected void FormView1_DataBound(object sender, EventArgs e)
dynamic varCategory = ddlCategory.SelectedValue;
dynamic categoryTextBox = FormView1.FindControl("CategoryIDText

How to fill out a form as another user , while using profiles database


I have created an InfoPath 2007 form. It works great.. I have 5 data connections to sharepoint lists and profile's database. The form displays public data (profile database) about the user, such as name, manager.. etc.

What I would like to do is have an option on the form that says " If you are not this person , click here" , manually type the persons last name , and bring up their information.

Basically , there are some people who will have someone else fill the form out for them. But I don't want them to be giving out their username and password to the system.

I want the ability to fill out a form as another user without logging off sharepoint. 

Formview PagerTemplate DropDownList Navigation


Does anyone know if its possible to use a DropDownList within the PagerTemplate to navigate to a specific record?  I have been able to place the DropDownList outside of the FormView and PagerTemplate and make it work, however, I can't get it to work inside the PagerTemplate.


RadioButtonList in FormView EditTemplate's not me behind and OldValue NewValues


Hello people,

I am using FormView component which has a field that is the sex of the person that I am using RadioButtonList with a simple way to show Male and Female, but want to retrieve the information and OldValue NewValues not anything behind me.

In the FormView Edit Template:
" yc=""><! - SEX ->

Gender: " yc="Sexo:   " yc=""><td>
   'RepeatColumns = "2">     " yc="' RepeatColumns="2">"><Asp: RadioButtonList ID = "CHR_SEXORadioButtonList" runat = "server" SelectedValue ='<%# Eval ("CHR_SEXO")%> &#

Library - Fill Columns with data from email

I have an inbound email enabled Library.  The Library has several columns created for it.  I would like to be able to send an email into the Library and have these columns filled from information in the email.  Is this possible using WSS 3.0?  What are the basic steps?  If I understand SharePoint well enough, I'm guessing is that I have to include the columns as Metadata in the body of the email and then assign this Metadata to the appropriate Library columns when new email is uploaded to the Library.

Formview + EditItemTemplate + Bind + PageLoad + Prerender = Confused


I am working with a formview edititemtemplate.  Currently in my page load, i have some stuff that would show or hide certain panels based on dropdownlist values.  These dropdown values get binded during page load.  I need to be able to change the values/dropdowns, without rebinding the old data, and updating the visibility of the panels based on predefined rules.

I have experimented with putting my formview.databind() in page load if isnotpostback, in prerender, in prerender if isnotpostback.   I have tried my rules (ex if ddlState.selectedvalue = "DE" then pnlDelaware.visible = "true") in the page load, and the page render.   I'm just not sure how to get the stars aligned here.

The closest i have come is having the databind in the pageload if notispostback, and the rules in the prerender.   However I get an error "dropdownlist has a SelectedValue which is invalid because it does not exist in the list of items.


CheckBoxList embedded in FormView InsertItemTemplate problem


I've searched hi/lo and found many similar posts but those answers aren't working for me.

I've got a FormView, in an UpdatePanel.  In the FormView's EditItemTemplate and InsertItemTemplate I'm using both a CheckBox and a CheckBoxList.  To present the data I databind in the code behind, (but then have to iterate to mark selected).  There I cast the sender as CheckBoxList in the OnPreRender event and use that object. 

The problem is retrieval.  I'm trying to access the user's entries when they submit by using the cast.  It is working fine for the CheckBox, but for the CheckBoxList the resulting checkboxlist object doesn't have any items. 

Here, both active and roles are created (they're not 'null') and active has the expected 'name' and 'selected' values, but roles has an item count = 0 and the for loop isn't entered.


            CheckBox active = ((CheckBox)Emp_Form.FindControl("cbActive"));

            CheckBoxList roles = (CheckBoxList)Emp_Form.FindControl("UsrRoles");

            foreach (ListItem role in roles.Items)
                // do stuff


Is there another way to cast a checkboxlist?  Any help would b

Page_Load Order -- Inserting a record

Is there any way to make sure an Insert Command happens before the Page_Load Events? I'm having a problem with inserting, then reading the DataSet directly after.  It seems it processes too quickly, or prior to the record being inserted. It has an impact on the DataSet that is to be displayed on screen. Summary:  Page_Loads > Finds Saved Data > If None exists (string contains 2 types of matches) > Displays the 1 of 2 types randomly. Buttons 1 & 2 Insert their respective options > Page Posts Back > Page_Loads > Read Saved Data > If my Max amount of the 1 of 2 types of Data are reached, the remaining type is shown > Displayed on page The problem I am having is that my DisplayDataSet is not getting the correct values.  It seems it's always 1 record behind on the count, because the count happens so fast, it's not getting the record that was just inserted. How can I write this, or make sure the "Find Saved Data' Routine happens after the Insert has been preformed?  Imports System.Data Imports System.Data.SqlClient Partial Public Class Assessment1 Inherits System.Web.UI.Page Protected Sub btnINS1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnINS1.Click Dim connetionString As String Dim connection As SqlConnection Dim adapter As New SqlDataAdapter Dim s
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend