ajoyprabhu
Technical User
I am trying to create a file name based upon the firs name, last name and job applied for ("JobType"- which is in a separate table)
In the VB code, "JobTypeID.SelectedItem.Text" gives me the first item of the dropdownlist, not the selected one!!
If I put Request.Form("JobTypeID") in the VB code, it gives me the correct index number, how do I convert it into the it text value?
The code is as follows:
<form enctype="multipart/form-data" runat="server" name="form1" method="POST" action="">
<table width="75%" border="0">
<tr>
<td nowrap> </td>
<td> </td>
</tr>
<tr>
<td nowrap><div align="right">Contractor:</div></td>
<td> <% ContractorTypeID.SelectedIndex = ContractorTypeID.Items.IndexOf(ContractorTypeID.Items.FindByValue(dsCandidates.FieldValue("ContractorTypeID", Nothing) )) %> <asp:dropdownlist ID="ContractorTypeID"
DataSource="<%# dsSubContractor.DefaultView %>"
DataTextField="Contractor"
DataValueField="ContractorID"
runat="server"> </asp:dropdownlist></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">JobType:</td>
<td> <% JobTypeID.SelectedIndex = JobTypeID.Items.IndexOf(JobTypeID.Items.FindByValue(dsCandidates.FieldValue("JobTypeID", Nothing) )) %> <asp:dropdownlist id="JobTypeID"
DataSource="<%# dsJobs.DefaultView %>"
DataTextField="JobType"
DataValueField="JobID"
runat="server"> </asp:dropdownlist> </td>
</tr>
<tr>
<td nowrap><div align="right">First Name: </div></td>
<td><input type="text" id="FirstName" name="FirstName"></td>
</tr>
<tr>
<td nowrap><div align="right">Last Name: </div></td>
<td><input type="text" id="LastName" name="LastName"></td>
</tr>
<tr>
<td nowrap><div align="right">Upload Resume:</div></td>
<td><input id="uploadedFile" type="file" runat="server">
<input type="hidden" name="MM_insert" value="form1"></td>
</tr><input type="hidden" name="Status" value="New">
<tr>
<td nowrap><div align="right"></div></td>
<td><p>
<input name="button" type=button id="button3"
value="Upload"
onserverclick="Upload_Click"
runat="server">
</p>
<p>
<asp:label text='<%# ContractorTypeID.SelectedItem.Text %>' runat="server"/>
<asp:label ID="message" runat="server"/>
</p>
<p></p></td>
</tr>
</table>
</form>
<script language="VB" runat="server">
Dim savePath As String = "C:\Inetpub\Sub Upload_Click(source As Object, e As EventArgs)
Page.DataBind
If Not (uploadedFile.PostedFile Is Nothing) Then
Try
Dim postedFile = uploadedFile.PostedFile
'Dim filename As String = Path.GetFileName(postedFile.FileName)
Dim filename As String = JobTypeID.SelectedItem.Text & "_" & Request.Form("FirstName") & "_" & Request.Form("LastName") & ".doc"
Dim contentType As String = postedFile.ContentType
Dim contentLength As Integer = postedFile.ContentLength
'postedFile.SaveAs(savePath & filename)
message.Text = savePath & filename & " uploaded" & _
"<br>Name: " & filename & "Type: " & contentType & _
"<br>Length: " & contentLength.ToString() & _
Catch exc As Exception
message.Text = "Failed uploading file"
End Try
End If
End Sub
</script>
In the VB code, "JobTypeID.SelectedItem.Text" gives me the first item of the dropdownlist, not the selected one!!
If I put Request.Form("JobTypeID") in the VB code, it gives me the correct index number, how do I convert it into the it text value?
The code is as follows:
<form enctype="multipart/form-data" runat="server" name="form1" method="POST" action="">
<table width="75%" border="0">
<tr>
<td nowrap> </td>
<td> </td>
</tr>
<tr>
<td nowrap><div align="right">Contractor:</div></td>
<td> <% ContractorTypeID.SelectedIndex = ContractorTypeID.Items.IndexOf(ContractorTypeID.Items.FindByValue(dsCandidates.FieldValue("ContractorTypeID", Nothing) )) %> <asp:dropdownlist ID="ContractorTypeID"
DataSource="<%# dsSubContractor.DefaultView %>"
DataTextField="Contractor"
DataValueField="ContractorID"
runat="server"> </asp:dropdownlist></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">JobType:</td>
<td> <% JobTypeID.SelectedIndex = JobTypeID.Items.IndexOf(JobTypeID.Items.FindByValue(dsCandidates.FieldValue("JobTypeID", Nothing) )) %> <asp:dropdownlist id="JobTypeID"
DataSource="<%# dsJobs.DefaultView %>"
DataTextField="JobType"
DataValueField="JobID"
runat="server"> </asp:dropdownlist> </td>
</tr>
<tr>
<td nowrap><div align="right">First Name: </div></td>
<td><input type="text" id="FirstName" name="FirstName"></td>
</tr>
<tr>
<td nowrap><div align="right">Last Name: </div></td>
<td><input type="text" id="LastName" name="LastName"></td>
</tr>
<tr>
<td nowrap><div align="right">Upload Resume:</div></td>
<td><input id="uploadedFile" type="file" runat="server">
<input type="hidden" name="MM_insert" value="form1"></td>
</tr><input type="hidden" name="Status" value="New">
<tr>
<td nowrap><div align="right"></div></td>
<td><p>
<input name="button" type=button id="button3"
value="Upload"
onserverclick="Upload_Click"
runat="server">
</p>
<p>
<asp:label text='<%# ContractorTypeID.SelectedItem.Text %>' runat="server"/>
<asp:label ID="message" runat="server"/>
</p>
<p></p></td>
</tr>
</table>
</form>
<script language="VB" runat="server">
Dim savePath As String = "C:\Inetpub\Sub Upload_Click(source As Object, e As EventArgs)
Page.DataBind
If Not (uploadedFile.PostedFile Is Nothing) Then
Try
Dim postedFile = uploadedFile.PostedFile
'Dim filename As String = Path.GetFileName(postedFile.FileName)
Dim filename As String = JobTypeID.SelectedItem.Text & "_" & Request.Form("FirstName") & "_" & Request.Form("LastName") & ".doc"
Dim contentType As String = postedFile.ContentType
Dim contentLength As Integer = postedFile.ContentLength
'postedFile.SaveAs(savePath & filename)
message.Text = savePath & filename & " uploaded" & _
"<br>Name: " & filename & "Type: " & contentType & _
"<br>Length: " & contentLength.ToString() & _
Catch exc As Exception
message.Text = "Failed uploading file"
End Try
End If
End Sub
</script>