473,320 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

DropDownList Selection Menu

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
Nov 19 '05 #1
3 1260
Do you have the AutoPostBack property set to true on the DataGrid?

"Tim::.." <myatix_at_hotmail.com> wrote in message
news:37**********************************@microsof t.com...
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

Nov 19 '05 #2
No...

"Grant Merwitz" wrote:
Do you have the AutoPostBack property set to true on the DataGrid?

"Tim::.." <myatix_at_hotmail.com> wrote in message
news:37**********************************@microsof t.com...
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


Nov 19 '05 #3
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.

"Tim::.." <myatix_at_hotmail.com> wrote in message
news:FD**********************************@microsof t.com...
No...

"Grant Merwitz" wrote:
Do you have the AutoPostBack property set to true on the DataGrid?

"Tim::.." <myatix_at_hotmail.com> wrote in message
news:37**********************************@microsof t.com...
> 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


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brennon Arnold | last post by:
I have a problem that I figured would be relatively common, but have been unable to find any information on it as of yet. I have a page that contains two DropDownList controls, with the second...
4
by: theo | last post by:
Program flow...load file,then extract the xml text tags from the file,then the number of Xml tags retrieved from the file determines the number of dropdownlist controls instanciated in the...
4
by: sklett | last post by:
I have 2 dropdownlist on a page. They have ViewState = true. After I submit to the page, the selection in the DropDownList is lost. I set a break in the Page_Load event to make sure that I...
3
by: Tim::.. | last post by:
Can someone please tell me how I go about preselecting an item in a drop drown list when I click the Edit Command in a datagrid? I have tried the following but it doesn't work for me! I would...
1
by: I am Sam | last post by:
I have two DropDownList controls in a web form and I need to test which control has changed without wrapping it in a SelectedIndexChange Event. How do I go about this issue? I have tried the...
4
by: Chris Kettenbach | last post by:
Good morning all, I am sure this has been asked but I did not see anything. I have a datalist control. In the edititemtemplate I have a dropdownlist. I know on the itemdatabound event is where I...
1
by: Trevor Bezotte | last post by:
Hi, I'm new to asp.net. I am having trouble updating and displaying a profile property through a dropdownlist. I believe the problem has something to do with autoeventwireup but I'm not sure. If...
10
by: ads | last post by:
hi, after binding the dropdownlist to a datasource, ive experience this error "Cannot have multiple items selected in a dropdownlist" after using the code:...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.