PDA

View Full Version : Coding an event in ASP.NET 2.0


Vishal90216
05-24-2009, 12:05 PM
Hello everyone!

I've got a problem in ASP.NET 2.0. I am trying to code an event which will add a user to a defined role in Sql Database. The event is raised when a button is clicked. Actually there are two dropdownlists, dropdownlist1 and dropdownlist2. The user first selects a UserName from dropdownlist1 and then selects a role from dropdownlist2. When a button is clicked, the UserName selected from dropdownlist1 will be added to the role selected from dropdownlist2.
In the .aspx.vb file, I have declared the UserName, RoleName As string as follows:
Dim UserName, RoleName As String
and then I have written the following block of codes in the button_click event section:

Roles.AddUsersToRole(DropDownList1.SelectedValue, DropDownList2.SelectedValue)
SqlDataSource1.DataBind()
SqlDataSource2.DataBind()
DropDownList1.DataBind()
DropDownList2.DataBind()

where SqlDataSource1 is the datasource used for dropdownlist1 and SqlDataSource2 is the datasource used for dropdownlist2.
Now when debugging I'm getting the following error:
Value of type string cannot be converted to "1-dimensional array of string.

Could anyone please help me and tell me if my code is correct or explain to me how to code this event correctly?

Thank you

bermanbp
06-10-2009, 11:14 PM
You should databind your lists on pageload first. Then OnPostBack, get the selected values and do your thing.