DropDownList Inside FormView Problem
Hey there,
Im quite new to ASP.NET and need some help to complete this project. What I'm trying to do is disable a DropDownList within a FormView depending what level of user logs into the page. Now what I have is a DropDownList in an EditTemplate of the FormView but not in the ItemTemplate (So that lets say the Admin User comes along and wants to change a City of a user... He Goes into the Edit mode of FormView and selects the new city for the user ... if a normal user logs in then he cant change this field so the DropDownList should be disabled). Ok with that explained I have this bit of code to catch when the Edit Button is pressed:
private Sub FormView1_DataBound(ByVal sender As Object, ByVal e As FormViewCommandEventArgs) Handles FormView1.ItemCommand
If e.CommandName.Equals("Edit") Then
Response.write("Called")
Dim drop as DropDownList = DirectCast(Me.FormView1.Row.FindControl("pTextBox" ), DropDownList)
if Not drop Is Nothing then
Response.Write(":: FOUND CONTROL")
drop.Enabled = False
Else
Response.Write(":: NOT FOUND CONTROL :- NULL")
End if
End If
end sub
Now what happens is when i press the edit button .. the Sub is called and prints out NOT FOUND CONTROL:- NULL
I modified the code so that it would call the above sub anytime the event changed to see what was happening (commented out the line [ If e.CommandName.Equals("Edit") Then]) and the Sub is called and prints out NOT FOUND CONTROL:- NULL but when i hit the cancel or update button the response is FOUND CONTROL (back when the ItemTemplate is shown not the edittemplate)
Now im so confused as to why it cant find the DropDownList in the Edit Template but can find it when it goes back to the ItemTemplate. If anyone can give me any help with this then it will be much appriciated. Thanks everyone!
Stevie
|