View Single Post
  #9 (permalink)  
Old February 22nd, 2006, 05:04 PM
rit01 rit01 is offline
Friend of Wrox
 
Join Date: Oct 2005
Location: , , United Kingdom.
Posts: 173
Thanks: 0
Thanked 2 Times in 1 Post
Default

Voila.. thanks Jim!!

In the HTML - Formview, as I have 3 Textboxes that I needed to control the Enabled property of what I did was set each textbox Enabled Property to False as so

Code:
<asp:FormView DefaultMode="Edit" ID="FormView1" runat="server" 
OnDataBound="FormView1_DataBound" … other bits…

<asp:DropDownList ID="MyDropdownList" runat="server" ..other bits..
        SelectedValue='<%# Bind("DatafromDB") %>'>
    </asp:DropDownList>

<asp:TextBox ID="txtbox1" Enabled="false"
runat="server" ></asp:TextBox>

<asp:TextBox ID="txtbox2" Enabled="false"
runat="server" ></asp:TextBox>

<asp:TextBox ID="txtbox3" Enabled="false"
runat="server" ></asp:TextBox>
An then the code-behind stuff for referencing/manipulating the controls within the FormView went like this..

Code:
Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As
 System.EventArgs)
        Dim DDList As DropDownList = 
CType(FormView1.FindControl("MyDropdownList"), DropDownList)
        Dim s As String
        s = DDList.SelectedItem.Value

        Select Case s
            Case 1
                Dim box1 As TextBox = 
CType(FormView1.FindControl("txtbox1"), TextBox)
                box1.Enabled = True
            Case 2
                Dim box2 As TextBox = 
CType(FormView1.FindControl("txtbox2"), TextBox)
                Box2.Enabled = True
            Case 3
                Dim box3 As TextBox = 
CType(FormView1.FindControl("txtbox3"), TextBox)
                Box3.Enabled = True
        End Select
    End Sub
If the above can be improved in anyway, please feel free to tweak.. always time for educating.

Ta

Rit
Reply With Quote