DropDownList Selection Menu

G

Guest

Hi...

Can someone please tell me what I'm doing wrong here...

I have a dropdownmenu populated from a database! The idea is that a user
selects an option from the dropdownlist which then loads the selected data
into a datagrid...

For some reason I can't get the data in the datagrid to load! Not really
shaw how to do it.... I presume it would work on SelectedIndexChanged but the
data doesn't load... Do I have to re bind the data??

I don't get any errors when I load the page or choose an item from the
dropdown... ????

And when I try to rebind the data usindg selectedindexchanged page doesn't
fire the Databind again???

Thanks for any help...

Sub BindData()

Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("strConn"))
Dim cmd As New SqlCommand("PageDetails", Myconn)
cmd.CommandType = CommandType.StoredProcedure

Myconn.Open()

Dim objType, objItemID As SqlParameter
objType = cmd.Parameters.Add("@Type", SqlDbType.Char)

objType.Direction = ParameterDirection.Input

'Shows requested data in datagrid!
Dim ShowEvent As String
ShowEvent = DDLShowType.SelectedValue

objType.Value = ShowEvent 'UserLogged.GetOfficeName()

Dim myReader As SqlDataReader = cmd.ExecuteReader()
DGPages.DataSource = myReader
DGPages.DataBind()

myReader.Close()

Myconn.Close()

End Sub 'Loads Data into Datagrid

Private Sub DDLShowType_ItemDataBound(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles DDLShowType.Load

'Construct the Database Connection
Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("strConn"))
Dim cmd As New SqlCommand("SelectType", Myconn)

cmd.CommandType = CommandType.StoredProcedure

Myconn.Open()

'Populates Office DropDownList with office names
DDLShowType = CType(FindControl("DDLShowType"), DropDownList)
DDLShowType.DataSource =
cmd.ExecuteReader(CommandBehavior.CloseConnection)
DDLShowType.DataTextField = "Type"
DDLShowType.DataValueField = "TypeID"
DDLShowType.DataBind()
DDLShowType.Items.Insert(0, "Select One")
DDLShowType.Items.FindByText("Select One").Value = 0 'insert don't
create a value, but we need a value during defaults
DDLShowType.SelectedIndex = 0
Myconn.Close()

End Sub
 
G

Grant Merwitz

Ok, so what you need to do, is set the DropDownList's AutoPostBack property
to true.
And create a method to handle the SelectedIndexChanged event (as you
suspected)

From that event, you can now call the BindData method you have created.

If you don't set the AutoPostBack to true, it will not fire the
SelectedIndexChanged event when the DataGrid has changed.
OfCourse, you'll have to specificy the OnSelectedIndexChanged to call the
method you've set up as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top