473,405 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Programmatically Bind Formview Based on Dropdownlist Selected

I have the following Formview:
Expand|Select|Wrap|Line Numbers
  1. 01.<asp:FormView runat="server" ID="fv1" PagerSettings-Visible="False"
  2. 02.                  EmptyDataText="No Image Set Found." EnableViewState="False"
  3. 03.                  AllowPaging="True">
  4. 04.                <ItemTemplate>
  5. 05.                  <asp:Button ID="btnUpdate" runat="server" CommandName="Update" Text="Edit" />
  6. 06.                </ItemTemplate>
  7. 07.                <EditItemTemplate>
  8. 08.                  <br />
  9. 09.                  <asp:Label ID="lbl0" runat="server" Visible="False" Text="Or choose one from the list:">
  10. 10.                  </asp:Label>
  11. 11.                  <asp:TextBox ID="txt0" runat="server"
  12. 12.                    Text='<%# Bind("Field0") %>'></asp:TextBox>
  13. 13.                  <asp:RequiredFieldValidator ID="rfv0" runat="server" ErrorMessage="* Required" ControlToValidate="txt0" SetFocusOnError="True" CssClass="error"></asp:RequiredFieldValidator>
  14. 14. 
  15. 15.                </EditItemTemplate>
  16. 16.                <PagerSettings Visible="False" />
  17. 17.                </asp:FormView>
I have the following dropdownlist outside of the formview:
Expand|Select|Wrap|Line Numbers
  1. 1.<asp:DropDownList ID="ddl0" runat="server" Visible="false"
  2. 2.  AutoPostBack="true" SkinID="DropDownList" AppendDataBoundItems="true" >
  3. 3.</asp:DropDownList>
What I would like to happen, is when the user chooses an item from the dropdown list, it shows all the values for that particular chosen record in the formview's controls. I would like this to work as a partial postback. Currently, I have one control in the formview, however, I plan on adding more once i know this works. The datasource for the dropdown is a table programmaticly assigned during the page's load event after, If Not Page.IsPostBack code. Then the dropdown's source is programmaticly assigned to the formview's source:

Code-Behind in VB:
Expand|Select|Wrap|Line Numbers
  1. 01.ddl0.DataSource = imgTable
  2. 02.ddl0.DataTextField = "Name"
  3. 03.ddl0.DataValueField = "tableIndex"
  4. 04.ddl0.DataBind()
  5. 05.ddl0.Visible = True
  6. 06. 
  7. 07.fv1.DataSource = ddl0.DataSource
  8. 08.fv1.DataBind()
This works during the page's first time load. However, once I change the dropdown to something different and the page refreshes, the textbox in the formview disappears. When I debug, I notice the dropdown and formview will lose their datasource values. Not sure why. I imagine, it has something to do with postbacks.

I pulled the data from a SQL database using a SELECT command. Stored it in a Dataset. Pulled out the table and assigned it to variable of type DataTable called imgTable. imgTable gets assigned to the datasource of the DropDownList. The DropDownList's datasource gets assigned to the formview's datasource. I have it this way because they pull the same data, and 2, whatever selection changes in the dropdown should be reflected in the controls of the formview.
Now my PageLoad looks like:
Expand|Select|Wrap|Line Numbers
  1. 01.Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
  2. 02. 
  3. 03.  If Not Page.IsPostBack Then
  4. 04.    lblMsg.Visible = False
  5. 05.
  6.       fetchdata() 'Function to get the data from the SQL database.
  7. 06.      BindData() 'Function to bind data to all page controls.
  8. 07.  Else
  9. 08.    If Not lblMsg.Text = "" Then
  10. 09.      lblMsg.Visible = True
  11. 10.    End If
  12. 11.    fv1.DefaultMode = FormViewMode.Edit
  13. 12.  End If
  14. 13.  fv1.DataSource = imgTable
  15. 14.  fv1.DataBind()
  16. 15.
  17. End Sub
It still doesn't work though. Instead, the textbox in the formview, displays the EmptyDataText value when I change values for my DropDownList.

Thanks,
Andy
Mar 7 '11 #1
0 4011

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: COHENMARVIN | last post by:
I'm leafing through a big book on asp.net, and I don't see any way to the following: 1. bind values and text to a dropdown 2. Also make the first line of the dropdown say something different. For...
4
by: Chris Kettenbach | last post by:
Good morning all, I am sure this has been asked but I did not see anything. I have a datalist control. In the edititemtemplate I have a dropdownlist. I know on the itemdatabound event is where I...
1
by: Patrik Zdarsa | last post by:
Hi, I'm try VS 2005 and need UPDATE database record in viewform, all working when every filed is type TextBox (html INPUT) but I need change one TextBox to Listbox or dropdownlist and read data...
0
by: Rabbit | last post by:
Hi, All, I have a FormView, in which the InsertItemTemplate has a dropdownlist that I need to set the datasource as my self created dataset. I have been trying various syntax like following at...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
0
by: Theam Kok Ming | last post by:
Hi All, I am a newbie to ASP.Net 2.0 . I would appreciate if anyone can enlighten me on my doubts I am building a simple customer registration website. I have the tables and GridView to...
1
by: rockdale | last post by:
Hi, all Is there a way to dynamically attach a regularexpressionvalidator to a textbox base on dropdownlist selected item? Let's say I have a dropdownlist list all contact type - phone, cell,...
1
by: SubashiniKumaar | last post by:
how to copy dropdownlist selected items to another dropdownlist in Asp.net using C# codings
1
by: sweatha | last post by:
Hi Friends I have designed a form with 1 DropDownList box named “ddlShow_time”& the form name is “Default4.aspx”. Just like that, I have the database(SQL SERVER 2000) as Table Name: ShowTime...
1
by: arunbojan | last post by:
Hi All, I have an editable datagrid with 10 columns, one of those is ddl column which I used for showing the status.... By default all the columns are readonly, when user clicks edit,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.