473,396 Members | 2,113 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,396 software developers and data experts.

Datalist SelectedIndexChange

18
Actually we're in a datalist. It sorta in the edit mode. Let me see if I can explain this. To bind the causetype and causedetail dropdownlist to the table in the edit mode I use the top code (1.) which is in the dlIncident_itemDataBound sub and actually works fine. But If the user decides to change the causetype ddl, (the details must change along with it.) the second code (which is html) (2.) the "onselectedindexchange" executes and sends it to the dlIncident_SelectedIndexChanges sub.(3.) Which I was hoping would bind the causedetails (4.) depending on what causetype will be selected. Am I making any sense? I'm sorry if i confused you;}


1.) Public Sub dlIncident_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlIncident.ItemDataBound

If e.Item.ItemType = ListItemType.EditItem Then 'if datalist is in edit mode

'Load Causes dropdownlist
connFF = New SqlConnection(Application("connFF"))
Dim cmdCauses As SqlCommand = New SqlCommand("Select vchcauses from luFFCauses", connFF)
Dim dtrCauses As SqlDataReader
Dim ddlCausetype As DropDownList = CType(e.Item.FindControl("ddlCausetype"), DropDownList)

Try
connFF.Open()
dtrCauses = cmdCauses.ExecuteReader
ddlCausetype.DataSource = dtrCauses
ddlCausetype.DataTextField = "vchcauses"
ddlCausetype.DataValueField = "vchcauses"
ddlCausetype.DataBind()
dtrCauses.Close()
connFF.Close()

Catch er As Exception
LogError(er.ToString, "Edit.aspx-Load Causes dropdownlist")
Exit Try
Finally
connFF.Close()
End Try


'Load Cause Details dropdownlist
connFF = New SqlConnection(Application("connFF"))


Dim intCounter As Integer
Dim ddlCauseDetails As DropDownList = CType(e.Item.FindControl("ddlCauseDetails"), DropDownList)
Dim cmdCauseDetails As New SqlCommand("spFFGetCauseDetails", connFF)
cmdCauseDetails.CommandType = CommandType.StoredProcedure

Dim prmCauseDetail As New SqlParameter("@CauseType", SqlDbType.VarChar)
prmCauseDetail.Value = ddlCausetype.SelectedValue
cmdCauseDetails.Parameters.Add(prmCauseDetail)

Dim dtrDetails As SqlDataReader

Try
connFF.Open()
dtrDetails = cmdCauseDetails.ExecuteReader
ddlCauseDetails.DataSource = dtrDetails
ddlCauseDetails.DataTextField = "Details"
ddlCauseDetails.DataValueField = "Details"
ddlCauseDetails.DataBind()

'While dtrDetails.Read
' Dim newListItem As New ListItem
' newListItem.Value = dtrDetails.GetString(0)
' ddlCauseDetails.Items.Add(newListItem)
' intCounter += 1
'End While
'Loop
dtrDetails.Close()
connFF.Close()


Catch er As Exception
LogError(er.ToString, "Load CauseDetails Dropdownlist-Edit.aspx")
Exit Try
Finally
connFF.Close()
End Try

2.)<asp:DropDownList id="ddlcausetype" runat="server" OnSelectedIndexChanged="dlIncident_SelectedIndexCh anged"
Width="272px" ForeColor="Gray" AutoPostBack="True"></asp:DropDownList></TD>


(3.) Sub dlIncident_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dlIncident.SelectedIndexChanged
Dim ddlCausedetails As DropDownList
BindCauseDetails(ddlCausedetails)
End Sub


(4.)Private Sub BindCauseDetails(ByVal ddl As DropDownList)

connFF = New SqlConnection(Application("connFF"))
Dim ddlcausetype As DropDownList
Dim intCounter As Integer
Dim ddlCauseDetails As DropDownList
Dim cmdCauseDetails As New SqlCommand("spFFGetCauseDetails", connFF)
cmdCauseDetails.CommandType = CommandType.StoredProcedure

Dim prmCauseDetail As New SqlParameter("@CauseType", SqlDbType.VarChar)
prmCauseDetail.Value = ddlcausetype.SelectedItem.Value
cmdCauseDetails.Parameters.Add(prmCauseDetail)

Dim dtrDetails As SqlDataReader

Try
connFF.Open()
dtrDetails = cmdCauseDetails.ExecuteReader
ddlCauseDetails.DataSource = dtrDetails
ddlCauseDetails.DataTextField = "Details"
ddlCauseDetails.DataValueField = "Details"
ddlCauseDetails.DataBind()

dtrDetails.Close()
connFF.Close()

Catch er As Exception
LogError(er.ToString, "CauseDetails-Incident.aspx")
Exit Try
Finally
connFF.Close()
End Try
End Sub
Aug 29 '08 #1
0 2512

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Thorben | last post by:
Hello, how can I undo/cancel the SelectedIndexChange event of an Listview control? Thanks in advance Thorben
1
by: Paul C | last post by:
Can anyone tell me why I am getting 2 calls to my SelectedIndexChange event. public class Browse : System.Web.UI.Page { protected System.Web.UI.WebControls.DataGrid DataGrid1; protected...
1
by: Jay | last post by:
I have dropdownlist in a usercontrol and selectedindexchange event captured. But Iam seeing fire twice. Thanks.
2
by: MBhat | last post by:
Hello, I have a dropdownlist server control.On selectedIndexChange I do some functionality. In addtion to this I need to check for something else. To do this I have to use javascript function to...
1
by: ProSAAP | last post by:
I need help. I am attaching both the html stuff as well as the code snippet that is not firing. Can someone please help me Thank Sub InputPub_SelectedIndexChanged(ByVal sender As Object, ByVal e...
6
by: Paul | last post by:
I am trying to use a DataList and the ItemTemplate. I am binding the Datalist to a SQL query that gives me a list of Items with a Parent Category. I want to loop through all the items, but...
0
by: Leonardo Santos-Macias | last post by:
I have a dropdown list that I bind at runtime. It does postback to the server. If I select any item, it will trigger the SelectedIndexChange event. My problem is that it doesn't trigger the...
2
by: Kevin | last post by:
Hi I need to get the "ItemId" from the selected value of the DropDownList in a DataList, but i don't known where tu put the <%# DataBinder.Eval(Container.DataItem, "ItemId"), because if I try to...
3
by: Mirek Endys | last post by:
I have DataList as part of DataList item. DataList in DataList. The parent DataList working well including Edit command, that shows Edit template and correctly bind the data into edit template...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.