I am making an admin section that will allow access to several small SQL tables in my project.
I have repeaters set up to show my lists with a button to bring up a Modal for adding a new entry or editing an existing one. The code behind stores a value from the selected row, and then I would like to query my SQL Class to return a value to fill my text boxes. The code works back to the SQL Class and I can display a message box and get the proper results. I can't however get it to pass the value if the query back to the VB page to fill the text boxes.
Here is the Repeater
<%--Employee Repeater--%>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<HeaderTemplate>
<table class="display" id ="employeeList">
<thead>
<tr>
<th>
Name
</th>
<th>
Email
</th>
<th>
Update
</th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# Eval("name")%>
</td>
<td>
<%# Eval("email")%>
</td>
<td>
<asp:Button ID="cmdEditName" runat="server" Text="Edit/Delete" CommandArgument= '<%#Databinder.Eval(Container.DataItem, "id")%>' OnClick="EditName"/>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
My Code Behind
'Open Name Modal bound to repeater
Public Sub EditName(ByVal sender As Object, ByVal e As System.EventArgs)
Dim wLink As New Button
Edit = True
wLink = DirectCast(sender, Button)
txtEditId.Text = wLink.CommandArgument
SQL.RunReader("SELECT name from Admin_Contacts WHERE Admin_Contacts.id = '" & txtEditId.Text & "' ")
txtEditName.Text = results
SQL.RunReader("SELECT email from Admin_Contacts WHERE Admin_Contacts.id = '" & txtEditId.Text & "' ")
txtEditEmail.Text = results
ModalName.Show()
End Sub
And the code in my SQL Class
Public Function RunReader(ByVal Query As String) As String
Dim results As String = ""
Try
SQLCon.Open()
SQLCmd = New SqlCommand(Query, SQLCon)
Dim R As SqlDataReader = SQLCmd.ExecuteReader
While R.Read
results = (R(0))
'MsgBox is just to show that I am getting results
MsgBox(results)
End While
SQLCon.Close()
Catch ex As Exception
MsgBox(ex.Message)
If SQLCon.State = ConnectionState.Open Then
SQLCon.Close()
End If
End Try
Dim results = SQL.RunReader("SELECT name from Admin_Contacts WHERE Admin_Contacts.id = '" & txtEditId.Text & "' ")
txtEditName.Text = results
Complete the runreader function with return statement
Public Function RunReader(ByVal Query As String) As String
Dim results As String = ""
Try
SQLCon.Open()
SQLCmd = New SqlCommand(Query, SQLCon)
Dim R As SqlDataReader = SQLCmd.ExecuteReader
While R.Read
results = (R(0))
'MsgBox is just to show that I am getting results
MsgBox(results)
End While
SQLCon.Close()
Catch ex As Exception
MsgBox(ex.Message)
If SQLCon.State = ConnectionState.Open Then
SQLCon.Close()
End If
End Try
Return results
End Function
Then call this method as
Dim results = SQL.RunReader("SELECT name from Admin_Contacts WHERE Admin_Contacts.id = '" & txtEditId.Text & "' ")
Related
I want to get users email id in listview and whatever email generated by listview according to query. Now on send click I want all email id generated by listview to get that email.
I know how to bind listview but how can I get email to send mail?
Private Sub BindListView()
Dim constr As String = ConfigurationManager.ConnectionStrings("conio2").ConnectionString
Using con As New MySqlConnection(constr)
Using cmd As New MySqlCommand()
cmd.CommandText = "SELECT email FROM users where city = 'new york' order by ID asc"
cmd.Connection = con
Using sda As New MySqlDataAdapter(cmd)
Dim dt As New DataTable()
sda.Fill(dt)
emailList.DataSource = dt
emailList.DataBind()
End Using
End Using
End Using
End Sub
Suppose if you have ListView defined as below in the HTML part:
<asp:ListView ID="emailList" runat="server" ConvertEmptyStringToNull="False">
<ItemTemplate>
<asp:Label Text='<%# Eval("Email") %>' runat="server" ID="lblEmail"></asp:Label>
</ItemTemplate>
</asp:ListView>
You can enumerate over all the ListViewItems, get the Email IDs from the Label, and join it into a string str separated by comma (,) which can then be directly utilized for sending the email to multiple recipients.
Dim str As String = ""
For Each li As ListViewItem In emailList.Items
Dim lbl As Label = CType(li.FindControl("lblEmail"), Label)
If lbl.Text <> "" Then
str = str + lbl.Text + ","
End If
Next
str = str.Substring(0, str.Length - 1)
Use str within the message sending code as message.cc.Add(str)
where message is the object of System.Net.Mail.MailMessage
From what I understand you have some function (or sub), that sends e-mails and you just need to provide data to that function.
For simplicity let's name this:
Private Sub SendEmail(address as string, title as string, body as string)
I have also added two TextBoxes:
TextBoxTitle for holding e-mail title and
TextBoxBody for holding e-mail body
Here's the code:
Private Sub SendEmail_Click(sender As Object, e As EventArgs) Handles SendEmail.Click
For Each item As ListViewItem In emailList.Items
SendEmail(item.SubItems.Item(0).Text, TextBoxTitle.Text, TextBoxBody.Text)
Next
End Sub
I have a web form that uses a DevExpress ASPxUploadControl (v 8.3) to let our users upload documents to our server. I'm working on an enhancement that will allow them to select an upload folder for the document. These are not physical folders, but logical folders. I've added an ASP:DropDownList to the form, which I populate from the database with the names of the folders that user has set up. If the user selects the folder and then the attachment everything works fine. However, if they select the file to upload and then the folder, the file is uploaded automatically once the file has been selected, rather than waiting for them to click the Upload link. This does not allow them to change if they've selected the wrong document. Also, the old (last) value selected from the dropdownlist is used - it is not being updated to reflect the new choice I suspect there is a clash between server-side events and client-side events. Following is the relevant code. How can I prevent the page from automatically uploading the document?
Thanks!
Mike
<td class="style6" valign="middle">
<asp:Panel ID="Panel3" colspan="2" runat="server" Height="83px" Width="125px"
Style="margin-top: 0px">
<dxuc:ASPxUploadControl ID="uplImage" runat="server"
ClientInstanceName="uploader" Font-Size="Medium" Height="84px"
OnFileUploadComplete="uplImage_FileUploadComplete" ShowUploadButton="True"
Size="50" style="margin-top: 0px; margin-right: 2px;">
<ValidationSettings AllowedContentTypes="image/jpeg,image/gif,image/pjpeg,application/pdf,application/rtf,application/msword,application/vnd.ms-excel,application/csv,text/plain,text/csv,text/richtext,text/rtf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, audio/wav" MaxFileSize="4096000">
<ErrorStyle Font-Size="Smaller" />
</ValidationSettings>
<ClientSideEvents FileUploadComplete="function(s, e) {
if(e.isValid)
{
if(e.errorText != ''){
alert(e.errorText);
} else {
alert(e.callbackData);
}
}
}" />
<ValidationSettings AllowedContentTypes="image/jpeg, image/gif, image/pjpeg, application/pdf, application/rtf, application/msword, application/vnd.ms-excel, application/csv, text/plain, text/csv, text/richtext, text/rtf, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, audio/wav"
MaxFileSize="4096000">
<ErrorStyle Font-Size="Smaller" />
</ValidationSettings>
<ClientSideEvents FilesUploadComplete="function(s, e) {}" FileUploadComplete="function(s, e) {
if(e.isValid)
{
if(e.errorText != ''){
alert(e.errorText);
} else {
alert(e.callbackData);
}
}
}" FileUploadStart="function(s, e) {}" />
</dxuc:ASPxUploadControl>
</asp:Panel>
</td>
</tr>
<tr>
<td colspan="2" class="txtnote" align="center" style="height: 18px">
Allowed file types: jpeg, gif, pdf, rtf, doc, docx, txt, csv, xls, xlsx, wav
</td>
</tr>
<tr>
<td colspan="2" class="txtnote" align="center" style="height: 10px">
Maximum file size: 4Mb
</td>
</tr>
<tr>
<td></td>
<td>
<input id="chkPrivate" name="chkPrivate" value="1" type="checkbox"/>Private
(checking Private prevents Mgmt Co &Assn from viewing attachment via client
login.)</td></tr>
<tr class="aligncenter">
<th class="style5" align="center" colspan="2">
</th>
</tr>
<tr class="aligncenter">
<th class="style5" align="center" colspan="2">
<asp:Panel ID="Panel2" runat="server" Height="50px" Width="125px">
<%--<dxe:ASPxButton ID="Button1" runat="server" Font-Size="Medium" Text="Cancel">
<Paddings PaddingLeft="10px" PaddingRight="10px" />
</dxe:ASPxButton>--%>
<input type="button" id="btnReturn" class="frmBtnCommon" value="Back To Case" onclick="ReturnToCase();" />
</asp:Panel>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim DAL As New DataAccessLayer
Dim dtFolders As New DataTable
GlobalVar.LoadData(Session("UserPKey"))
Session("CurrentPage") = "CaseAttchmt.aspx"
If Session("LoggedOn") = True And GlobalVar.ConnectString <> "" Then
CSSDefaultHTML = Session("CSS_Default")
DefaultIPHTML = Application("DefaultIP")
End If
SelKey = Request.QueryString("Case")
Header1.ConnectionStr = GlobalVar.ConnectString
Header1.HDLawFirm = GlobalVar.LawFirmDir
Header1.InsertHeader("Add File to a Case", 0, 0, SelKey, "width=100% align=center")
ClientKey = Session("ClientKey")
UploadDirectory = GlobalVar.LawFirmDir & "AttachFiles/Case" & Trim(Str(SelKey)) & "/"
If System.IO.Directory.Exists(GlobalVar.LawFirmDir & "AttachFiles/") = False Then
System.IO.Directory.CreateDirectory(GlobalVar.LawFirmDir & "AttachFiles")
End If
If System.IO.Directory.Exists(GlobalVar.LawFirmDir & "AttachFiles/Case" & Trim(Str(SelKey))) = False Then
System.IO.Directory.CreateDirectory(GlobalVar.LawFirmDir & "AttachFiles/Case" & Trim(Str(SelKey)))
End If
GlobalVar.SaveData(Session("UserPKey"))
dtFolders = DAL.GetClientFolders(Session("ClientKey"))
ddlFolders.DataSource = dtFolders
Dim lstFolders As ListItem
Dim i As Integer
Dim intValue As Integer
Dim strText As String
If Not Page.IsPostBack Then
ddlFolders.Items.Clear
intValue = 0
strText = "Attachments"
lstFolders = New ListItem(strText, intValue)
ddlFolders.Items.Add(lstFolders)
For i = 0 to dtFolders.Rows.Count - 1
intValue = dtFolders.Rows(i).Item("pKey")
strText = dtFolders.Rows(i).Item("FolderName")
lstFolders = New ListItem(strText, intValue)
ddlFolders.Items.Add(lstFolders)
Next
ddlFolders.SelectedIndex = 0
Session("FolderKey") = 0
End If
End Sub
Protected Function SavePostedFile() As String
Dim filename As String = ""
Dim tempFileName As String = ""
SelKey = Session("SelKey")
If Len(Trim(Session("ClientKey"))) = 4 then
UploadDirectory = "~/DATA/AR00" & Session("ClientKey") & "/AttachFiles/Case" & Trim(Str(SelKey)) & "/"
Else
UploadDirectory = "~/DATA/" & Trim(Session("LawFirm")) & "/AttachFiles/Case" & Trim(Str(SelKey)) & "/"
End If
filename = Trim(uplImage.FileName)
If filename <> "" Then
tempFileName = MapPath(UploadDirectory) & filename
uplImage.SaveAs(tempFileName)
End If
Return tempFileName
End Function
Protected Sub uplImage_FileUploadComplete(ByVal sender As Object, ByVal e As FileUploadCompleteEventArgs)
Dim FileExists As Boolean = False
UploadDirectory = "~/DATA/" & Trim(Session("LawFirm")) & "/AttachFiles/Case" & Trim(Str(Session("SelKey"))) & "/"
Dim FilePath As String = MapPath(UploadDirectory) & Trim(uplImage.FileName)
FileExists = CheckForFile(FilePath)
'urk : Added validation for checking filename length and filesize being uploaded 06/01/2010.
If (e.IsValid) Then
If (e.UploadedFile.FileName.Length > 100) Then
e.ErrorText = "The file name cannot be more than 100 characters long. Please shorten and retry."
ElseIf (e.UploadedFile.FileName.Contains("'") Or e.UploadedFile.FileName.Contains("&")) Then
e.ErrorText = "The file name cannot contain the apostrophe or ampersand characters."
ElseIf (e.UploadedFile.FileName.EndsWith(".aspx")) Or (e.UploadedFile.FileName.EndsWith(".ASPX")) Then
e.ErrorText = ".aspx files are not allowed for upload."
ElseIf FileExists = True Then
e.ErrorText = "A file with this name has already been uploaded. Please rename and try again."
Else
e.CallbackData = SavePostedFile()
If e.CallbackData <> "" Then
s_UpdateAttachData()
End If
e.CallbackData = "File: '" + e.UploadedFile.FileName + "' uploaded successfully."
End If
End If
End Sub
Private Sub s_UpdateAttachData()
Dim i_date As DateTime = Now.Date
Dim DAL As New DataAccessLayer
ClientKey = Session("ClientKey")
Dim pPrintBy As Integer = Session("UserPKey")
Dim PrintDate As DateTime = Now
Dim s As Boolean
Dim FullAttchPath As String
If Len(trim(ClientKey)) = 1 Then
FullAttchPath = "DATA/AR00000" + ClientKey.ToString + "/AttachFiles/Case" + SelKey.ToString + "/" + Trim(uplImage.FileName)
ElseIf Len(Trim(ClientKey)) = 4 then
FullAttchPath = "DATA/AR00" + ClientKey.ToString + "/AttachFiles/Case" + SelKey.ToString + "/" + Trim(uplImage.FileName)
Else
FullAttchPath = "DATA/AR0" + ClientKey.ToString + "/AttachFiles/Case" + SelKey.ToString + "/" + Trim(uplImage.FileName)
End If
If Request.Form("chkPrivate") <> "" Then
s = 1
Else
s = 0
End If
DAL.InsertCasesAttachPKey(ClientKey, SelKey, Trim(uplImage.FileName), Trim(uplImage.FileName), pPrintBy, PrintDate, s, FullAttchPath, Session("FolderKey"))
End Sub
Protected Function CheckForFile(ByVal Filename As String) As Boolean
If File.Exists(Filename) Then
Return True
Else
Return False
End If
End Function
Protected Sub ddlFolders_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ddlFolders.SelectedIndexChanged
Session("FolderKey") = ddlFolders.SelectedValue
End Sub
Im forced to use ODBC, and i would like to bind a DataSet to a FormView. So far i have this code:
Sub lookup(data As String, city As String)
Dim query As String = "SELECT FIND_KORT_VEJ_FUL.STREET_NAME, FIND_KORT_VEJ_FUL.ZIPCODE, UXOR_CITY_DK.NAME AS cityName FROM UXOR_CITY_DK " & _
"Join(FIND_KORT_VEJ_FUL) " & _
"ON UXOR_CITY_DK.KOMMUNE_KODE=FIND_KORT_VEJ_FUL.MUNICIPALITY_CODE WHERE UXOR_CITY_DK.NAME = '" & city & "' " & _
"LIMIT 5"
Dim connectionString As String = System.Configuration.ConfigurationManager.ConnectionStrings("ODBCDataConnectionString").ConnectionString
Dim initialDataSet As New DataSet("initial")
Dim dt As DataSet = GetDataSetFromAdapter(initialDataSet, connectionString, query)
FormView1.DataSource = dt
FormView1.DataBind()
End Sub
Public Function GetDataSetFromAdapter(ByVal dataSet As DataSet, ByVal connectionString As String, ByVal queryString As String) As DataSet
Using connection As New OdbcConnection(connectionString)
Dim adapter As New OdbcDataAdapter(queryString, connection)
' Open the connection and fill the DataSet.
Try
connection.Open()
adapter.Fill(dataSet)
Catch ex As Exception
End Try
' The connection is automatically closed when the
' code exits the Using block.
End Using
Return dataSet
End Function
FormView:
<asp:FormView ID="FormView1" runat="server" EmptyDataText="Ingen data">
<ItemTemplate>
<table>
<tr>
<td>Postnummer: <%#Eval("MUNICIPALITY_CODE") %></td>
</tr>
<tr>
<td>Indbyggere: </td>
</tr>
<tr>
<td>Geografisk lokation: </td>
</tr>
<tr>
<td>Roskilde ligger i Roskilde kommune</td>
</tr>
<tr>
<td><br /><h3><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></h3></td>
</tr>
<tr>
<td>Borgmester: </td>
</tr>
<tr>
<td>Antal veje i kommunen: #</td>
</tr>
</table>
</ItemTemplate>
</asp:FormView>
I have verified the query and querystring, both work. The FormView does not get populated with the above code. Is it possible to bind a FormView to a DataSet? or is there a better method?
I've noticed a few things you probably need to change here. Here is your modified function below. The main issue is the connection not being closed. Regardless of what you may read elsewhere, SQL connections are not closed by the Using block. However, I am not sure about the OdbcConnection. I would recommend including the closing lines just in case.
Public Function GetDataSetFromAdapter(ByVal dataSet As DataSet, ByVal connectionString As String, ByVal queryString As String) As DataSet
Using connection As New OdbcConnection(connectionString)
Dim adapter As New OdbcDataAdapter(queryString, connection)
' Open the connection and fill the DataSet.
Try
connection.Open()
adapter.Fill(dataSet)
connection.Close()
Catch ex As Exception
connection.Close() 'This is necessary to avoid accidental multiple connections.
End Try
' The connection is automatically closed when the
' code exits the Using block.
End Using
Return dataSet
End Function
But the real problem I believe is that you are not referencing the table itself. Dataset only contains the tables, you must specify them when binding...
Sub lookup(data As String, city As String)
Dim query As String = "SELECT FIND_KORT_VEJ_FUL.STREET_NAME, FIND_KORT_VEJ_FUL.ZIPCODE, UXOR_CITY_DK.NAME AS cityName FROM UXOR_CITY_DK " & _
"Join(FIND_KORT_VEJ_FUL) " & _
"ON UXOR_CITY_DK.KOMMUNE_KODE=FIND_KORT_VEJ_FUL.MUNICIPALITY_CODE WHERE UXOR_CITY_DK.NAME = '" & city & "' " & _
"LIMIT 5"
Dim connectionString As String = System.Configuration.ConfigurationManager.ConnectionStrings("ODBCDataConnectionString").ConnectionString
Dim initialDataSet As New DataSet("initial")
Dim dt As DataSet = GetDataSetFromAdapter(initialDataSet, connectionString, query)
FormView1.DataSource = dt.Tables(0)
FormView1.DataBind()
End Sub
i want to send email using Persits.MailSender object. i found one solution and i include this code this solution works and Object created:
<%
posted = request.form ("submit")
if posted = "Submit" then
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' Customize the following 5 lines with your own information. ''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
vtoaddress = "_____" ' Change this to the email address you will be receiving your notices.
vmailhost = Application("ServerAddress") ' Change this to your actual Domain name.
vfromaddress = "_____" ' Change this to the email address you will use to send and authenticate with.
vfrompwd = "_______________" ' Change this to the above email addresses password.
vsubject = "ASP Contact Form" 'Change this to your own email message subject.
'''''''''''''''''''''''''''''''''''''''''''
'' DO NOT CHANGE ANYTHING PAST THIS LINE ''
'''''''''''''''''''''''''''''''''''''''''''
vfromname = request.form ("TName")
vbody = request.form ("TBody")
vrplyto = request.form ("TEmail")
vmsgbody = vfromname &"<br>"& vrplyto &"<br>"& vbody
Set objEmail = Server.CreateObject("Persits.MailSender")
objEmail.Username = vfromaddress
objEmail.Password = vfrompwd
objEmail.Host = vmailhost
objEmail.From = vfromaddress
objEmail.AddAddress vtoaddress
objEmail.Subject = vsubject
objEmail.Body = vmsgbody
objEmail.IsHTML = True
objEmail.Send
vErr = Err.Description
if vErr <> "" then
response.write vErr & "<br><br>There was an error on this page."
else
response.write "Thank you, your message has been sent."
End If
Set objEmail = Nothing
response.write "Thank you, your message has been sent."
end if
%>
<html><body>
<form name="SendEmail01" method="post">
<table border=0>
<tr>
<td>Name:</td>
<td><input type="text" name="TName" size="30"></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="TEmail" size="30"></td>
</tr>
<tr>
<td>Body:</td>
<td><textarea rows="4" name="TBody" cols="30"></textarea></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
</form>
</body></html>
after filling all fields and submitting page then error occured like:
Persits.MailSender.4 error '800a0004'
Cannot assign requested address.
/contact_form.asp, line 34
please help me..
I hope so this piece of code will help you
<%
Class HVMailer
Private mMail
Private Sub Class_Initialize()
Set mMail = Server.CreateObject("Persits.MailSender")
mMail.Host = ""
mMail.Username = ""
mMail.Password = ""
mMail.TLS = True
End Sub
Public Property Let FromAddress(sFrom)
mMail.From = trim(sFrom)
End Property
Public Property Let FromName(sFromName)
mMail.FromName = trim(sFromName)
End Property
Public Property Let ReplyTo(sReply)
mMail.AddReplyTo trim(sReply), trim(sReply)
End Property
Public Property Let Subject(sSubject)
mMail.Subject = sSubject
End Property
Public Property Let BodyText(sBodyText)
mMail.Body = sBodyText
End Property
Public Property Let HTML(bHTML)
mMail.isHTML = bHTML
End Property
Public Sub AddRecipient(sAddress, sName)
sAddress = trim(sAddress)
if mMail.ValidateAddress(sAddress)= 0 Then
mMail.AddAddress sAddress, sName
end if
End Sub
Public Sub AddCC(sAddress, sName)
sAddress = trim(sAddress)
if mMail.ValidateAddress(sAddress)= 0 Then
mMail.AddCC sAddress, sName
end if
End Sub
Public Sub AddBCC(sAddress, sName)
sAddress = trim(sAddress)
if mMail.ValidateAddress(sAddress)= 0 Then
mMail.AddBCC sAddress, sName
end if
End Sub
Public Sub AddAttachment(sFile)
mMail.AddAttachment sFile
End Sub
Public function Send()
On Error Resume Next
mReturn = True
mMail.Send
if Err<>0 Then
mReturn = false
end if
Set mMail = Nothing
send = mReturn
End Function
End Class
%>
I wrote an ASPX file in VB.NET. Originally this file ran successfully but after adding one additional parameter it now fails on "Name 'peType' is not declared".
This error does not make sense to me though because I have similar parameter, 'dType', which it does not error on. What is the cause of this error?
Here is some of my ASPX code file:
Sub Page_Load(Sender as Object, E as EventArgs)
If Not IsPostback Then
Dim TheMonthDate As Date = DateAdd(DateInterval.Month, -1, Today)
calStartDate.SelectedDate = CDate((TheMonthDate.Month) & "/1/" & Year(TheMonthDate)).ToString("MM/dd/yyyy")
calEndDate.SelectedDate = GlobalFunctions.GlobalF.MonthLastDate(CDate((TheMonthDate.Month) & "/1/" & Year(TheMonthDate)).ToString("MM/dd/yyyy"))
Dim arrType as New ArrayList()
Dim arrOrgUnit as New ArrayList()
Dim arrPEType as New ArrayList()
Dim peType As ListBox
arrType.Add("Product and Process")
arrType.Add("Product")
arrType.Add("Process")
dType.DataSource = arrType
dType.DataBind()
arrPEType.Add("-INC")
arrPEType.Add("-NC")
arrPEType.Add("-QC")
peType.DataSource = arrPEType
'peType.DataTextField = "DisplayColumnName"
'peType.DataValueField = "ValueColumnName"
peType.DataBind()
...
Dim TheType as String
Dim TheOrgUnit as String
Dim PE_Type as String
Select Case dType.SelectedValue
Case "Product and Process":
TheType = "((SMARTSOLVE.V_QXP_ALL_EXCEPTION.QXP_BASE_EXCEPTION)='PXP_PRODUCT_QXP' Or (SMARTSOLVE.V_QXP_ALL_EXCEPTION.QXP_BASE_EXCEPTION)='PXP_PROCESS_QXP')"
Case "Product":
TheType = "((SMARTSOLVE.V_QXP_ALL_EXCEPTION.QXP_BASE_EXCEPTION)='PXP_PRODUCT_QXP')"
Case "Process":
TheType = "((SMARTSOLVE.V_QXP_ALL_EXCEPTION.QXP_BASE_EXCEPTION)='PXP_PROCESS_QXP')"
End Select
Select Case peType.SelectedValue
Case "INC":
PE_Type = "substring(a.QXP_EXCEPTION_NO, charindex('-', a.QXP_EXCEPTION_NO)+1, 4)='INC'"
Case "NC":
PE_Type = "substring(a.QXP_EXCEPTION_NO, charindex('-', a.QXP_EXCEPTION_NO)+1, 4)='NC'"
Case "QC":
PE_Type = "substring(a.QXP_EXCEPTION_NO, charindex('-', a.QXP_EXCEPTION_NO)+1, 4)='QC'"
End Select
...
<td>
Product Exception Type:
</td>
<td>
<ASP:DROPDOWNLIST ID="peType" RUNAT="Server" AUTOPOSTBACK="true" />
</td>
But now my error is:
Object reference not set to an instance of an object
You missed setting the DataTextField and DataValueField property, when you tried to bind DataSource to your Dropdownlist, so set as follows:
peType.DataSource = arrPEType
peType.DataTextField = "DisplayColumnName"
peType.DataValueField = "ValueColumnName"
peType.DataBind()