Hi I am using these: ASP.Net 2.0, VB.Net, Visual Studio 2005, SQL Server 2005, Formview controls
In a ASP.Net form I have 20 textboxes and 20 dropdownlists(d dl). All ddl(s) are databound and get the data from a single objectdatasourc e. All textboxes and ddl(s) support null values. Textboxes are for entering numbers and ddl(s) are for selecting the unit (mm, cm, in, m3, oz, qt like these.).
I am using the below code to achieve two things.(For each textbox and ddl have their own corresponding codes like below.)
1. Allowing the selection of ddl item also if it is not selected too, a default unit item will be inserted in the database.
2. Only if textbox has value then the default unit item will be inserted in the database.
It is working fine.
Part of form below:
Part of code behind:
But what I want to change,
* Visually the form should show the preferred ddl default item. So that the user can see and if they need to change.
* I don't want to hardcode the preferred unit item (like oz) in the code behind. Instead the ddl item itself should be refered.
How to achieve the above 2 things? (Attached image will show what I am expecting)
Please help me.
In a ASP.Net form I have 20 textboxes and 20 dropdownlists(d dl). All ddl(s) are databound and get the data from a single objectdatasourc e. All textboxes and ddl(s) support null values. Textboxes are for entering numbers and ddl(s) are for selecting the unit (mm, cm, in, m3, oz, qt like these.).
I am using the below code to achieve two things.(For each textbox and ddl have their own corresponding codes like below.)
1. Allowing the selection of ddl item also if it is not selected too, a default unit item will be inserted in the database.
2. Only if textbox has value then the default unit item will be inserted in the database.
It is working fine.
Part of form below:
Code:
<asp:FormView ID="FormView1" runat="server" DataKeyNames="ImperialMeasureID" DataSourceID="ImperialMeasureDataSource" DefaultMode="Insert">
<InsertItemTemplate>
<asp:TextBox ID="tbProductSizeValue" runat="server" Text='<%# Bind("ProductSizeValue") %>' Columns="6" MaxLength="6"></asp:TextBox>
<asp:DropDownList ID="ddlProductSizeUnit" runat="server" AppendDataBoundItems="True" DataTextField="UnitValue" DataValueField="UnitValue">
<asp:ListItem Text="---" Value="" />
</asp:DropDownList>
Code:
Dim ddl1 As DropDownList = CType(FormView1.FindControl("ddlProductSizeUnit"), DropDownList)
Dim tb1 As TextBox = CType(FormView1.FindControl("tbProductSizeValue"), TextBox)
If ddl1.SelectedValue = "" AndAlso tb1.Text.Length > 0 Then
e.Values("ProductSizeUnit") = "oz"
Else
e.Values("ProductSizeUnit") = ddl1.SelectedValue
End If
* Visually the form should show the preferred ddl default item. So that the user can see and if they need to change.
* I don't want to hardcode the preferred unit item (like oz) in the code behind. Instead the ddl item itself should be refered.
How to achieve the above 2 things? (Attached image will show what I am expecting)
Please help me.
Comment