narmi2
asked on
setting dropdownlist1.SelectedIndex help
i have a webform with a dropdown
the dropdownlist1 is populated from a database e.g.
dropdownlist1.DataTextFiel d = objDataSet.Tables(0).Colum ns("Name") .ColumnNam e.ToString ()
dropdownlist1.DataValueFie ld = objDataSet.Tables(0).Colum ns("Code") .ColumnNam e.ToString ()
that bit works fine
next bit I cant seem to do
it should set the selectedindex of the dropdownlist1 to the correct selectedindex e.g.
dropdownlist1.SelectedInde x = objDataSet.Tables(0).Rows( 0).Item("C ode").ToSt ring()
But the "Code" is not an integer, its a string
can anyone help?
Kind of urgent 500 points
the dropdownlist1 is populated from a database e.g.
dropdownlist1.DataTextFiel
dropdownlist1.DataValueFie
that bit works fine
next bit I cant seem to do
it should set the selectedindex of the dropdownlist1 to the correct selectedindex e.g.
dropdownlist1.SelectedInde
But the "Code" is not an integer, its a string
can anyone help?
Kind of urgent 500 points
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
that doesnt seem to work
however the following code might be what im looking for!!!!
textbox1.Text = dropdownlist1.Items.IndexO f(dropdown list1.Item s.FindByVa lue(objDat aSet.Table s(0).Rows( 0).Item("C ode").ToSt ring()))
this gives me the correct number for the index which is should select in the dropdownlist1 but if i do this
dropdownlist1.SelectedInde x = dropdownlist1.Items.IndexO f(dropdown list1.Item s.FindByVa lue(objDat aSet.Table s(0).Rows( 0).Item("C ode").ToSt ring()))
it does not work????????
however the following code might be what im looking for!!!!
textbox1.Text = dropdownlist1.Items.IndexO
this gives me the correct number for the index which is should select in the dropdownlist1 but if i do this
dropdownlist1.SelectedInde
it does not work????????
what's the error then?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
laotzi2000 - no errors, it just always have the index 0 selected?
b1xml2 - that does not work either. i get the feeling that i have contradicting code somewhere.
im gonna post up the code so someone can tell me what im doing wrong. :)
thanks
b1xml2 - that does not work either. i get the feeling that i have contradicting code somewhere.
im gonna post up the code so someone can tell me what im doing wrong. :)
thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
yeah, probably that is the case...
Here's a thought, do you have your dropdownlist binding on a post back? Is the dropdownlist's autopostback set to true? One of those could be the problem
For example:
Page loads - Dataset Binds
DropDownList selectedindex is changed
DropDownList hits the Autopostback
Page Loads - Dataset Binds
etc...
For example:
Page loads - Dataset Binds
DropDownList selectedindex is changed
DropDownList hits the Autopostback
Page Loads - Dataset Binds
etc...
Dim item As ListItem
If Not IsDBNull(objDataSet.Tables (0).Column s("Code"). ColumnName .ToString( )) Then
For Each item In dropdownlist1.Items
If item.Value.IndexOf(objData Set.Tables (0).Column s("Code"). ColumnName .ToString( )) <> -1 Then
dropdownlist1.ClearSelecti on()
dropdownlist1.Items.FindBy Value(item .Value).Se lected = True
End If
Next
End If
If Not IsDBNull(objDataSet.Tables
For Each item In dropdownlist1.Items
If item.Value.IndexOf(objData
dropdownlist1.ClearSelecti
dropdownlist1.Items.FindBy
End If
Next
End If
ASKER
here's the code so far!
<%@ Page Language="VB" runat="server" debug="true" explicit="true" aspcompat=true smartnavigation=true validateRequest=false%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sql Client" %>
<%@ Register TagPrefix="aspx" TagName="CM1" src="../components/CM1.asc x" %>
<%@ Register TagPrefix="aspx" TagName="CM2" src="../components/CM2.asc x" %>
<%@ Register TagPrefix="aspx" TagName="CM3" src="../components/CM3.asc x" %>
<script language="VB" runat="server">
Dim strEntryPerson as string
Dim datEntryDate as date
'## DB CONNECTION VARIABLES ##
Dim objConnection1 As SqlConnection
Dim objConnection2 As SqlConnection
Dim objSelectDataAdapter As SqlDataAdapter
Dim objDataSet As DataSet
Dim strAddEditSQL As String
Dim objAddEditCommand As SqlCommand
sub Page_Prerender(sender as Object, e as EventArgs)
SelectedDDL()
end sub
sub Page_Load(sender as Object, e as EventArgs)
objConnection1 = New SqlConnection("MyConnectio n1")
objConnection2 = New SqlConnection("MyConnectio n2")
if not page.ispostback
GetFunction1()
GetFunction2()
GetFunction3()
end if
end sub
sub SelectedDDL()
if ddlCM2.SelectedItem.Text = "_New Employee" then
Response.Redirect("../defa ult.aspx")
else
objSelectDataAdapter = New SqlDataAdapter("SELECT job_title, start_date, contract_full_part_time, contract_type, " & _
"contract_signed, salary, salary_effective_date, hours_of_work, " & _
"location_office, department " & _
"FROM MyTable1 " & _
"WHERE (employee_id = '" & ddlCM2.SelectedItem.Value & "') " & _
"AND (inactive = 0)", objConnection1)
objDataSet = new DataSet()
objSelectDataAdapter.Fill( objDataSet , "EmergencyDetails")
if objDataSet.Tables(0).Rows. Count = 0 then
txtJobTitle.Text = ""
txtStartDate.Text = ""
txtFullPartTime.SelectedIn dex = 0
txtContractType.SelectedIn dex = 0
txtSigned.Checked = false
txtSalary.Text = ""
txtEffectiveDate.Text = ""
txtHoursOfWork.Text = ""
txtLocationOffice.Selected Index = 0
txtDepartment.SelectedInde x = 0
btnSaveUpdate.text = "Save"
else
txtJobTitle.Text = objDataSet.Tables(0).Rows( 0).Item("j ob_title") .ToString( )
txtStartDate.Text = objDataSet.Tables(0).Rows( 0).Item("s tart_date" ).ToString ()
txtFullPartTime.SelectedVa lue = objDataSet.Tables(0).Rows( 0).Item("c ontract_fu ll_part_ti me").ToStr ing()
txtContractType.SelectedVa lue = objDataSet.Tables(0).Rows( 0).Item("c ontract_ty pe").ToStr ing()
txtSigned.Checked = objDataSet.Tables(0).Rows( 0).Item("c ontract_si gned").ToS tring()
txtSalary.Text = objDataSet.Tables(0).Rows( 0).Item("s alary").To String()
txtEffectiveDate.Text = objDataSet.Tables(0).Rows( 0).Item("s alary_effe ctive_date ").ToStrin g()
txtHoursOfWork.Text = objDataSet.Tables(0).Rows( 0).Item("h ours_of_wo rk").ToStr ing()
txtLocationOffice.Selected Value = objDataSet.Tables(0).Rows( 0).Item("l ocation_of fice").ToS tring()
txtDepartment.SelectedValu e = objDataSet.Tables(0).Rows( 0).Item("d epartment" ).ToString ()
btnSaveUpdate.text = "Update"
end if
page.databind()
end if
ddlCM2.SelectedIndex = session("sesRememberILoop" )
ddlCM1.selectedindex = session("sesRememberMainTa sk")
End Sub
Sub GetFunction1()
objSelectDataAdapter = New SqlDataAdapter("SELECT PERSNL_TYP_DESC, PERSNL_TYP_CODE " & _
"FROM MyTable2 " & _
"WHERE INACTIVE = 'N'", objConnection2)
objDataSet = New DataSet()
objSelectDataAdapter.Fill( objDataSet , "ContractType")
txtContractType.DataSource = objDataSet.Tables(0)
txtContractType.DataTextFi eld = objDataSet.Tables(0).Colum ns("PERSNL _TYP_DESC" ).ColumnNa me.ToStrin g()
txtContractType.DataValueF ield = objDataSet.Tables(0).Colum ns("PERSNL _TYP_CODE" ).ColumnNa me.ToStrin g()
txtContractType.DataBind()
End Sub
Sub GetFunction3()
objSelectDataAdapter = New SqlDataAdapter("SELECT OFFC_DESC, OFFC_CODE " & _
"FROM hbl_office", objConnection2)
objDataSet = New DataSet()
objSelectDataAdapter.Fill( objDataSet , "OfficeLocation")
txtLocationOffice.DataSour ce = objDataSet.Tables(0)
txtLocationOffice.DataText Field = objDataSet.Tables(0).Colum ns("OFFC_D ESC").Colu mnName.ToS tring()
txtLocationOffice.DataValu eField = objDataSet.Tables(0).Colum ns("OFFC_C ODE").Colu mnName.ToS tring()
txtLocationOffice.DataBind ()
End Sub
Sub GetFunction2()
'## POPULATE DEPARTMENT
objSelectDataAdapter = New SqlDataAdapter("SELECT DEPT_NAME,DEPT_CODE,INACTI VE FROM MyTable3 WHERE ((DEPT_CODE IN (SELECT DISTINCT DEPT FROM HBA_OFFC_DEPT WHERE OFFC = 'GX') AND INACTIVE != 'Y')) ORDER BY DEPT_CODE", objConnection2)
objDataSet = New DataSet()
objSelectDataAdapter.Fill( objDataSet 1, "Departments")
txtDepartment.DataSource = objDataSet.Tables(0)
txtDepartment.DataTextFiel d = objDataSet.Tables(0).Colum ns("DEPT_N AME").Colu mnName.ToS tring()
txtDepartment.DataValueFie ld = objDataSet.Tables(0).Colum ns("DEPT_C ODE").Colu mnName.ToS tring()
txtDepartment.DataBind()
End Sub
Sub SaveUpdateRecord(Source as Object, E as EventArgs)
'## USER ##
Dim emp_code As String = "xxx"
if btnSaveUpdate.text = "Save" then
strAddEditSQL = "SET DATEFORMAT dmy " & _
"INSERT INTO MyTable1 " & _
"(employee_id, job_title, start_date, contract_full_part_time, contract_type, " & _
"contract_signed, salary, salary_effective_date, hours_of_work, location_office, " & _
"department, entry_date, entry_person) " & _
"VALUES (@employee_id, @job_title, @start_date, @contract_full_part_time, @contract_type, " & _
"@contract_signed, @salary, @salary_effective_date, @hours_of_work, " & _
"@location_office, @department, @entry_date, @entry_person) " & _
"SET DATEFORMAT mdy"
objAddEditCommand = new SqlCommand(strAddEditSQL, objConnection1)
objAddEditCommand.Paramete rs.Add(New SqlParameter("@employee_id ", SqlDbType.Int, 4))
objAddEditCommand.Paramete rs("@emplo yee_id").V alue = ddlCM2.selecteditem.value
objAddEditCommand.Paramete rs.Add(New SqlParameter("@job_title", SqlDbType.NVarChar, 1000))
objAddEditCommand.Paramete rs("@job_t itle").Val ue = txtJobTitle.text
objAddEditCommand.Paramete rs.Add(New SqlParameter("@start_date" , SqlDbType.DateTime, 8))
objAddEditCommand.Paramete rs("@start _date").Va lue = txtStartDate.text
objAddEditCommand.Paramete rs.Add(New SqlParameter("@contract_fu ll_part_ti me", SqlDbType.NVarChar, 1000))
objAddEditCommand.Paramete rs("@contr act_full_p art_time") .Value = txtFullPartTime.SelectedIt em.Value
objAddEditCommand.Paramete rs.Add(New SqlParameter("@contract_ty pe", SqlDbType.NVarChar, 1000))
objAddEditCommand.Paramete rs("@contr act_type") .Value = txtContractType.SelectedIt em.Value
objAddEditCommand.Paramete rs.Add(New SqlParameter("@contract_si gned", SqlDbType.Int, 8))
objAddEditCommand.Paramete rs("@contr act_signed ").Value = txtSigned.Checked
objAddEditCommand.Paramete rs.Add(New SqlParameter("@salary", SqlDbType.NVarChar, 50))
objAddEditCommand.Paramete rs("@salar y").Value = txtSalary.text
objAddEditCommand.Paramete rs.Add(New SqlParameter("@salary_effe ctive_date ", SqlDbType.DateTime, 8))
objAddEditCommand.Paramete rs("@salar y_effectiv e_date").V alue = txtEffectiveDate.text
objAddEditCommand.Paramete rs.Add(New SqlParameter("@hours_of_wo rk", SqlDbType.NVarChar, 50))
objAddEditCommand.Paramete rs("@hours _of_work") .Value = txtHoursOfWork.text
objAddEditCommand.Paramete rs.Add(New SqlParameter("@location_of fice", SqlDbType.NVarChar, 1000))
objAddEditCommand.Paramete rs("@locat ion_office ").Value = txtLocationOffice.Selected Item.Value
objAddEditCommand.Paramete rs.Add(New SqlParameter("@department" , SqlDbType.NVarChar, 1000))
objAddEditCommand.Paramete rs("@depar tment").Va lue = txtDepartment.SelectedItem .Value
objAddEditCommand.Paramete rs.Add(New SqlParameter("@entry_date" , SqlDbType.DateTime, 8))
objAddEditCommand.Paramete rs("@entry _date").Va lue = datetime.now
objAddEditCommand.Paramete rs.Add(New SqlParameter("@entry_perso n", SqlDbType.NVarChar, 50))
objAddEditCommand.Paramete rs("@entry _person"). Value = trim(lcase(emp_code))
objAddEditCommand.Connecti on.Open()
objAddEditCommand.ExecuteN onQuery
objAddEditCommand.Connecti on.Close()
else
strAddEditSQL = "SET DATEFORMAT dmy " & _
"UPDATE MyTable1 " & _
"SET employee_id = @employee_id, " & _
"job_title = @job_title, " & _
"start_date = @start_date, " & _
"contract_full_part_time = @contract_full_part_time, " & _
"contract_type = @contract_type, " & _
"contract_signed = @contract_signed, " & _
"salary = @salary, " & _
"salary_effective_date = @salary_effective_date, " & _
"hours_of_work = @hours_of_work, " & _
"location_office = @location_office, " & _
"department = @department, " & _
"entry_change_date = @entry_change_date, " & _
"entry_change_person = @entry_change_person " & _
"WHERE (employee_id = @employee_id) " & _
"SET DATEFORMAT mdy"
objAddEditCommand = new SqlCommand(strAddEditSQL, objConnection1)
objAddEditCommand.Paramete rs.Add(New SqlParameter("@employee_id ", SqlDbType.Int, 4))
objAddEditCommand.Paramete rs("@emplo yee_id").V alue = ddlCM2.selecteditem.value
objAddEditCommand.Paramete rs.Add(New SqlParameter("@job_title", SqlDbType.NVarChar, 1000))
objAddEditCommand.Paramete rs("@job_t itle").Val ue = txtJobTitle.text
objAddEditCommand.Paramete rs.Add(New SqlParameter("@start_date" , SqlDbType.DateTime, 8))
objAddEditCommand.Paramete rs("@start _date").Va lue = txtStartDate.text
objAddEditCommand.Paramete rs.Add(New SqlParameter("@contract_fu ll_part_ti me", SqlDbType.NVarChar, 1000))
objAddEditCommand.Paramete rs("@contr act_full_p art_time") .Value = txtFullPartTime.SelectedIt em.Value
objAddEditCommand.Paramete rs.Add(New SqlParameter("@contract_ty pe", SqlDbType.NVarChar, 1000))
objAddEditCommand.Paramete rs("@contr act_type") .Value = txtContractType.SelectedIt em.Value
objAddEditCommand.Paramete rs.Add(New SqlParameter("@contract_si gned", SqlDbType.Int, 8))
objAddEditCommand.Paramete rs("@contr act_signed ").Value = txtSigned.Checked
objAddEditCommand.Paramete rs.Add(New SqlParameter("@salary", SqlDbType.NVarChar, 50))
objAddEditCommand.Paramete rs("@salar y").Value = txtSalary.text
objAddEditCommand.Paramete rs.Add(New SqlParameter("@salary_effe ctive_date ", SqlDbType.DateTime, 8))
objAddEditCommand.Paramete rs("@salar y_effectiv e_date").V alue = txtEffectiveDate.text
objAddEditCommand.Paramete rs.Add(New SqlParameter("@hours_of_wo rk", SqlDbType.NVarChar, 50))
objAddEditCommand.Paramete rs("@hours _of_work") .Value = txtHoursOfWork.text
objAddEditCommand.Paramete rs.Add(New SqlParameter("@location_of fice", SqlDbType.NVarChar, 1000))
objAddEditCommand.Paramete rs("@locat ion_office ").Value = txtLocationOffice.Selected Item.Value
objAddEditCommand.Paramete rs.Add(New SqlParameter("@department" , SqlDbType.NVarChar, 1000))
objAddEditCommand.Paramete rs("@depar tment").Va lue = txtDepartment.SelectedItem .Value
objAddEditCommand.Paramete rs.Add(New SqlParameter("@entry_chang e_date", SqlDbType.DateTime, 8))
objAddEditCommand.Paramete rs("@entry _change_da te").Value = datetime.now
objAddEditCommand.Paramete rs.Add(New SqlParameter("@entry_chang e_person", SqlDbType.NVarChar, 50))
objAddEditCommand.Paramete rs("@entry _change_pe rson").Val ue = trim(lcase(emp_code))
objAddEditCommand.Connecti on.Open()
objAddEditCommand.ExecuteN onQuery()
objAddEditCommand.Connecti on.Close()
page.databind()
end if
ddlCM2.PopulateCM2
End Sub
</script>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="../stylesheets/style .css" />
</head>
<body>
<form id="form1" runat="server">
<table class="BorderColor" border="1" bordercolor="#203A76" cellspacing="3" cellpadding="0">
<tr class="RowColor" valign="top">
<td width="150">
<table class="ColumnHeadings" border="0" cellpadding="3" cellspacing="0">
<tr valign="top">
<td class="PersonnelHeadings">
<h4>Title 1
</td>
</tr>
<tr valign="top">
<td class="PersonnelSubHeading ">
<p>Title 2
</td>
</tr>
<tr valign="top">
<td>
<aspx:CM1 id="ddlCM1" runat="server" />
</td>
</tr>
<tr valign="top">
<td class="PersonnelSubHeading ">
<p>Title 3
</td>
</tr>
<tr valign="top">
<td>
<aspx:CM2 id="ddlCM2" onselectedindexchanged="Wh enSelectio nIsChanged " runat="server" />
</td>
</tr>
<tr valign="top">
<td class="PersonnelSubHeading ">
<p>Title 4
</td>
</tr>
<tr valign="top">
<td height="100%">
<aspx:CM3 id="CM3" runat="server" />
</td>
</tr>
</table>
</td>
<td>
<table class="ColumnHeadings" border="0" cellpadding="3" cellspacing="0" bgcolor="#DFE6F1">
<tr valign="top">
<td class="PersonnelHeadings">
<h4>Title 5
</td>
</tr>
<tr valign="top">
<td class="PersonnelSubHeading ">
<p>
</td>
</tr>
<tr valign="top">
<td height="100%">
<table border="0">
<tr>
<td colspan="2" class="SubCatFadeBlue">
<b>Job Details</b>
</td>
<td>
</td>
</tr>
<tr>
<td>
Job Title:
</td>
<td>
<asp:textbox id="txtJobTitle" font-size="8" runat="server" width="250" />
</td>
</tr>
<tr>
<td>
Start Date:
</td>
<td>
<asp:textbox id="txtStartDate" font-size="8" runat="server" width="250" />
</td>
</tr>
<tr>
<td colspan="2" class="SubCatFadeBlue">
<b>Contract</b>
</td>
<td>
</td>
</tr>
<tr>
<td>
Full/Part Time:
</td>
<td>
<asp:dropdownlist id="txtFullPartTime" font-size="8" runat="server" width="250">
<asp:listItem Value="0">Full Time</asp:listitem>
<asp:listItem Value="1">Part Time</asp:listitem>
</asp:dropdownlist>
</td>
</tr>
<tr>
<td>
Contract Type:
</td>
<td>
<asp:dropdownlist id="txtContractType" font-size="8" runat="server" width="250" />
</td>
</tr>
<tr>
<td>
Signed:
</td>
<td>
<asp:checkbox id="txtSigned" font-size="8" runat="server" />
</td>
</tr>
<tr>
<td colspan="2" class="SubCatFadeBlue">
<b>Salary</b>
</td>
<td>
</td>
</tr>
<tr>
<td>
Salary:
</td>
<td>
<asp:textbox id="txtSalary" font-size="8" runat="server" width="250" />
</td>
</tr>
<tr>
<td>
Effective Date:
</td>
<td>
<asp:textbox id="txtEffectiveDate" font-size="8" runat="server" width="250" />
</td>
</tr>
<tr>
<td colspan="2" class="SubCatFadeBlue">
<b>Other</b>
</td>
<td>
</td>
</tr>
<tr>
<td>
Hours Of Work:
</td>
<td>
<asp:textbox id="txtHoursOfWork" font-size="8" runat="server" width="250" />
</td>
</tr>
<tr>
<td>
Location Office:
</td>
<td>
<asp:dropdownlist id="txtLocationOffice" font-size="8" runat="server" width="250" />
</td>
</tr>
<tr>
<td>
Department:
</td>
<td>
<asp:dropdownlist id="txtDepartment" font-size="8" runat="server" width="250" />
</td>
</tr>
</table>
</td>
</tr>
<tr valign="top">
<td class="PersonnelFooter">
<asp:button id="btnSaveUpdate" text="Save" font-size="8" OnClick="SaveUpdateRecord" runat="server" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body
</html>
<%@ Page Language="VB" runat="server" debug="true" explicit="true" aspcompat=true smartnavigation=true validateRequest=false%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sql
<%@ Register TagPrefix="aspx" TagName="CM1" src="../components/CM1.asc
<%@ Register TagPrefix="aspx" TagName="CM2" src="../components/CM2.asc
<%@ Register TagPrefix="aspx" TagName="CM3" src="../components/CM3.asc
<script language="VB" runat="server">
Dim strEntryPerson as string
Dim datEntryDate as date
'## DB CONNECTION VARIABLES ##
Dim objConnection1 As SqlConnection
Dim objConnection2 As SqlConnection
Dim objSelectDataAdapter As SqlDataAdapter
Dim objDataSet As DataSet
Dim strAddEditSQL As String
Dim objAddEditCommand As SqlCommand
sub Page_Prerender(sender as Object, e as EventArgs)
SelectedDDL()
end sub
sub Page_Load(sender as Object, e as EventArgs)
objConnection1 = New SqlConnection("MyConnectio
objConnection2 = New SqlConnection("MyConnectio
if not page.ispostback
GetFunction1()
GetFunction2()
GetFunction3()
end if
end sub
sub SelectedDDL()
if ddlCM2.SelectedItem.Text = "_New Employee" then
Response.Redirect("../defa
else
objSelectDataAdapter = New SqlDataAdapter("SELECT job_title, start_date, contract_full_part_time, contract_type, " & _
"contract_signed, salary, salary_effective_date, hours_of_work, " & _
"location_office, department " & _
"FROM MyTable1 " & _
"WHERE (employee_id = '" & ddlCM2.SelectedItem.Value & "') " & _
"AND (inactive = 0)", objConnection1)
objDataSet = new DataSet()
objSelectDataAdapter.Fill(
if objDataSet.Tables(0).Rows.
txtJobTitle.Text = ""
txtStartDate.Text = ""
txtFullPartTime.SelectedIn
txtContractType.SelectedIn
txtSigned.Checked = false
txtSalary.Text = ""
txtEffectiveDate.Text = ""
txtHoursOfWork.Text = ""
txtLocationOffice.Selected
txtDepartment.SelectedInde
btnSaveUpdate.text = "Save"
else
txtJobTitle.Text = objDataSet.Tables(0).Rows(
txtStartDate.Text = objDataSet.Tables(0).Rows(
txtFullPartTime.SelectedVa
txtContractType.SelectedVa
txtSigned.Checked = objDataSet.Tables(0).Rows(
txtSalary.Text = objDataSet.Tables(0).Rows(
txtEffectiveDate.Text = objDataSet.Tables(0).Rows(
txtHoursOfWork.Text = objDataSet.Tables(0).Rows(
txtLocationOffice.Selected
txtDepartment.SelectedValu
btnSaveUpdate.text = "Update"
end if
page.databind()
end if
ddlCM2.SelectedIndex = session("sesRememberILoop"
ddlCM1.selectedindex = session("sesRememberMainTa
End Sub
Sub GetFunction1()
objSelectDataAdapter = New SqlDataAdapter("SELECT PERSNL_TYP_DESC, PERSNL_TYP_CODE " & _
"FROM MyTable2 " & _
"WHERE INACTIVE = 'N'", objConnection2)
objDataSet = New DataSet()
objSelectDataAdapter.Fill(
txtContractType.DataSource
txtContractType.DataTextFi
txtContractType.DataValueF
txtContractType.DataBind()
End Sub
Sub GetFunction3()
objSelectDataAdapter = New SqlDataAdapter("SELECT OFFC_DESC, OFFC_CODE " & _
"FROM hbl_office", objConnection2)
objDataSet = New DataSet()
objSelectDataAdapter.Fill(
txtLocationOffice.DataSour
txtLocationOffice.DataText
txtLocationOffice.DataValu
txtLocationOffice.DataBind
End Sub
Sub GetFunction2()
'## POPULATE DEPARTMENT
objSelectDataAdapter = New SqlDataAdapter("SELECT DEPT_NAME,DEPT_CODE,INACTI
objDataSet = New DataSet()
objSelectDataAdapter.Fill(
txtDepartment.DataSource = objDataSet.Tables(0)
txtDepartment.DataTextFiel
txtDepartment.DataValueFie
txtDepartment.DataBind()
End Sub
Sub SaveUpdateRecord(Source as Object, E as EventArgs)
'## USER ##
Dim emp_code As String = "xxx"
if btnSaveUpdate.text = "Save" then
strAddEditSQL = "SET DATEFORMAT dmy " & _
"INSERT INTO MyTable1 " & _
"(employee_id, job_title, start_date, contract_full_part_time, contract_type, " & _
"contract_signed, salary, salary_effective_date, hours_of_work, location_office, " & _
"department, entry_date, entry_person) " & _
"VALUES (@employee_id, @job_title, @start_date, @contract_full_part_time, @contract_type, " & _
"@contract_signed, @salary, @salary_effective_date, @hours_of_work, " & _
"@location_office, @department, @entry_date, @entry_person) " & _
"SET DATEFORMAT mdy"
objAddEditCommand = new SqlCommand(strAddEditSQL, objConnection1)
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Connecti
objAddEditCommand.ExecuteN
objAddEditCommand.Connecti
else
strAddEditSQL = "SET DATEFORMAT dmy " & _
"UPDATE MyTable1 " & _
"SET employee_id = @employee_id, " & _
"job_title = @job_title, " & _
"start_date = @start_date, " & _
"contract_full_part_time = @contract_full_part_time, " & _
"contract_type = @contract_type, " & _
"contract_signed = @contract_signed, " & _
"salary = @salary, " & _
"salary_effective_date = @salary_effective_date, " & _
"hours_of_work = @hours_of_work, " & _
"location_office = @location_office, " & _
"department = @department, " & _
"entry_change_date = @entry_change_date, " & _
"entry_change_person = @entry_change_person " & _
"WHERE (employee_id = @employee_id) " & _
"SET DATEFORMAT mdy"
objAddEditCommand = new SqlCommand(strAddEditSQL, objConnection1)
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Paramete
objAddEditCommand.Connecti
objAddEditCommand.ExecuteN
objAddEditCommand.Connecti
page.databind()
end if
ddlCM2.PopulateCM2
End Sub
</script>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="../stylesheets/style
</head>
<body>
<form id="form1" runat="server">
<table class="BorderColor" border="1" bordercolor="#203A76" cellspacing="3" cellpadding="0">
<tr class="RowColor" valign="top">
<td width="150">
<table class="ColumnHeadings" border="0" cellpadding="3" cellspacing="0">
<tr valign="top">
<td class="PersonnelHeadings">
<h4>Title 1
</td>
</tr>
<tr valign="top">
<td class="PersonnelSubHeading
<p>Title 2
</td>
</tr>
<tr valign="top">
<td>
<aspx:CM1 id="ddlCM1" runat="server" />
</td>
</tr>
<tr valign="top">
<td class="PersonnelSubHeading
<p>Title 3
</td>
</tr>
<tr valign="top">
<td>
<aspx:CM2 id="ddlCM2" onselectedindexchanged="Wh
</td>
</tr>
<tr valign="top">
<td class="PersonnelSubHeading
<p>Title 4
</td>
</tr>
<tr valign="top">
<td height="100%">
<aspx:CM3 id="CM3" runat="server" />
</td>
</tr>
</table>
</td>
<td>
<table class="ColumnHeadings" border="0" cellpadding="3" cellspacing="0" bgcolor="#DFE6F1">
<tr valign="top">
<td class="PersonnelHeadings">
<h4>Title 5
</td>
</tr>
<tr valign="top">
<td class="PersonnelSubHeading
<p>
</td>
</tr>
<tr valign="top">
<td height="100%">
<table border="0">
<tr>
<td colspan="2" class="SubCatFadeBlue">
<b>Job Details</b>
</td>
<td>
</td>
</tr>
<tr>
<td>
Job Title:
</td>
<td>
<asp:textbox id="txtJobTitle" font-size="8" runat="server" width="250" />
</td>
</tr>
<tr>
<td>
Start Date:
</td>
<td>
<asp:textbox id="txtStartDate" font-size="8" runat="server" width="250" />
</td>
</tr>
<tr>
<td colspan="2" class="SubCatFadeBlue">
<b>Contract</b>
</td>
<td>
</td>
</tr>
<tr>
<td>
Full/Part Time:
</td>
<td>
<asp:dropdownlist id="txtFullPartTime" font-size="8" runat="server" width="250">
<asp:listItem Value="0">Full Time</asp:listitem>
<asp:listItem Value="1">Part Time</asp:listitem>
</asp:dropdownlist>
</td>
</tr>
<tr>
<td>
Contract Type:
</td>
<td>
<asp:dropdownlist id="txtContractType" font-size="8" runat="server" width="250" />
</td>
</tr>
<tr>
<td>
Signed:
</td>
<td>
<asp:checkbox id="txtSigned" font-size="8" runat="server" />
</td>
</tr>
<tr>
<td colspan="2" class="SubCatFadeBlue">
<b>Salary</b>
</td>
<td>
</td>
</tr>
<tr>
<td>
Salary:
</td>
<td>
<asp:textbox id="txtSalary" font-size="8" runat="server" width="250" />
</td>
</tr>
<tr>
<td>
Effective Date:
</td>
<td>
<asp:textbox id="txtEffectiveDate" font-size="8" runat="server" width="250" />
</td>
</tr>
<tr>
<td colspan="2" class="SubCatFadeBlue">
<b>Other</b>
</td>
<td>
</td>
</tr>
<tr>
<td>
Hours Of Work:
</td>
<td>
<asp:textbox id="txtHoursOfWork" font-size="8" runat="server" width="250" />
</td>
</tr>
<tr>
<td>
Location Office:
</td>
<td>
<asp:dropdownlist id="txtLocationOffice" font-size="8" runat="server" width="250" />
</td>
</tr>
<tr>
<td>
Department:
</td>
<td>
<asp:dropdownlist id="txtDepartment" font-size="8" runat="server" width="250" />
</td>
</tr>
</table>
</td>
</tr>
<tr valign="top">
<td class="PersonnelFooter">
<asp:button id="btnSaveUpdate" text="Save" font-size="8" OnClick="SaveUpdateRecord"
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body
</html>
ASKER
making progress here!
it now works when i click the update or save button. it adds the correct entries into the database and even remembers the correct item in the dropdown
however, if i click on another page and then go back the this page, it does not remember the correct dropdownitem???
it now works when i click the update or save button. it adds the correct entries into the database and even remembers the correct item in the dropdown
however, if i click on another page and then go back the this page, it does not remember the correct dropdownitem???
That's normal, when you go back from another page, it is not postback,
so the dropdownlist will be rebind, the selected item is lost.
To remember this, you can consider using a session variable.
so the dropdownlist will be rebind, the selected item is lost.
To remember this, you can consider using a session variable.
ASKER
I got it working!!!!!!!!!!
I simply removed the following from each of the Functions
txtLocationOffice.DataBind ()
so the only time it binds is in the SelectedDLL sub!!!!!
it was binding too many times, once in the SelectedDLL sub and once in each of the functions!!!!
cant believe i didnt see that!!!
I simply removed the following from each of the Functions
txtLocationOffice.DataBind
so the only time it binds is in the SelectedDLL sub!!!!!
it was binding too many times, once in the SelectedDLL sub and once in each of the functions!!!!
cant believe i didnt see that!!!
dropdownlist1.SelectedInde