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("s trConn"))
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("s trConn"))
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