How to refresh devexpress listbox without refreshing the page in ASP.NET using VB.NET - asp.net

I'm working on a form where I have to have an upload control and a listbox to show the uploaded files. Right now the only way to show the change is to refresh the whole page. My boss wants the upload to automatically show in the listbox. I have been unable to find anything to do this after days of searching.
VB code:
Protected Sub BootstrapUploadControl1_FileUploadComplete(sender As Object, e As DevExpress.Web.FileUploadCompleteEventArgs) Handles BootstrapUploadControl1.FileUploadComplete
Dim fileName = e.UploadedFile.FileName
Dim contentType = e.UploadedFile.ContentType
Try
Using fs As Stream = e.UploadedFile.FileContent
Using br As New BinaryReader(fs)
Dim bytes As Byte() = br.ReadBytes(CType(fs.Length, Integer))
Dim constr As String = "Data Source=mgm-sql-pub101;Initial Catalog=KidVid;Integrated Security=True;"
Dim query = "INSERT INTO Attachments(RequestID,FileName,FileBytes,Description) VALUES (#RequestID, #FileName, #FileBytes, #Description)"
Using con As SqlConnection = New SqlConnection(constr)
Dim cmd As SqlCommand = New SqlCommand(query, con)
cmd.Parameters.AddWithValue("RequestID", 1)
cmd.Parameters.AddWithValue("FileName", fileName)
cmd.Parameters.AddWithValue("FileBytes", bytes)
cmd.Parameters.AddWithValue("Description", "Binary File")
Try
con.Open()
If con.State = ConnectionState.Open Then
MsgBox("It's open! Yay!")
End If
Dim obj As Object = cmd.ExecuteNonQuery()
MsgBox("Record inserted successfully. ID = " & obj.ToString())
con.Close()
If con.State = ConnectionState.Closed Then
MsgBox("It's closed! Yay!")
End If
Catch ex As Exception
Throw ex
End Try
End Using
End Using
End Using
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Sub
HTML:
<div class="col">
<h5><i class='fas fa-paperclip' style='font-size:24px'></i>Attachments:</h5>
<div class="row mb-3">
<div class="col-5">
<dx:BootstrapUploadControl ID="BootstrapUploadControl1" runat="server" AutoPostBack="true" UploadMode="Auto" ShowProgressPanel="True" ShowUploadButton="True"></dx:BootstrapUploadControl>
<dx:ASPxButton ID="ASPxButton1" runat="server" Text="ASPxButton" AutoPostBack="true" />
</div>
</div>
<h6><i class="fas fa-file-download" style="font-size: 24px"></i> Double-click filename to download file:</h6>
<dx:BootstrapListBox ID="AttachmentsListBox" runat="server" DataSourceID="KidVidAttachmentsDataSource" AutoPostBack="true">
<Fields>
<dx:BootstrapListBoxField FieldName="FileName"></dx:BootstrapListBoxField>
</Fields>
</dx:BootstrapListBox>
<asp:SqlDataSource runat="server" ID="KidVidAttachmentsDataSource" ConnectionString="<%$ ConnectionStrings:KidVidConnectionString %>" SelectCommand="SELECT [FileName] FROM [Attachments] ORDER BY [FileName]"></asp:SqlDataSource>

So, I'm not familiar with the up-loader you are using. But, your posted code stub suggest this works "much" like the ajaxtoolkit one.
That means after "all" files been up-loaded, then no post-back occures.
As noted, you do probably want some up-loader that allows up-loading of files, and does NOT require a post-back.
However, after say 4 files are done up-loading, then it not all that bad to have a post-back trigger, and at that point in time trigger a post-back to refresh your grid of files, or listbox or whatever.
And note that one should "find" + "adopt" some up-loader for this purpose. A number "will" preview the picture file EVEN before the up-load starts. (however, I not really interested in that feature).
So, I use the ajax tool kit. It has 3 events (all do NOT post back).
Start up load stub.
One file done uploading stub. Here we save the file, add to our "file list". In my following example I use a grid view in place of a list box.
And I have some code that pulls out a first page for a image preview if this is a PDF. For images, then I just preview the image.
And a lot of the nice up-loaders also have a "hot spot" in which you can just drag + drop files.
And most are "chunked", and thus show a progress bar. And being chunked, then file size is un-limited, and you don't get a huge browser "spinner" while such large files up-load.
However, once ALL files are done, then I do fire a client side event, and I do so since I need/want to up-date my up-loaded file list. That is "why" I asked about what file up-loader you are using.
You COULD (and so could I with the aj toolkit file uploader) do a web call, get the new files, and fill out the listbox. But, I'm using a gridview, and I just do a Post-back to refresh it.
The results look like this:
So, while and after each file is up-loaded? No, I don't want a post-back.
However, once the list of files is up-loaded? Then yes, I do a post-back to update (refresh) the grid view.
So, it much depends on the file up-loader you are using.
As noted, your "code stub" suggests that your file up-loader has this ability (to trigger a client side javascript event when done).
So, what I did was drop a button on to the page, hide it (with style = display none).
And the aj fileuploader has a "all done" client side event.
this was my markup:
(not really imporant, but as a fyi:).
<div id="uploadfiles" runat="server" style="width: 550px; float: left">
<ajaxToolkit:AjaxFileUpload ID="AjaxFileUpload1" runat="server"
OnUploadComplete="AjaxFileUpload1_UploadComplete"
OnClientUploadCompleteAll="AllDone" />
</div>
<div id="myfiles" runat="server" style="float: left; width: 40%; margin-left: 30px">
<asp:GridView ID="GridFiles" runat="server"
AutoGenerateColumns="False" CssClass="table table-hover"
OnRowDataBound="GridFiles_RowDataBound">
<Columns>
<asp:BoundField DataField="FileName" HeaderText="FileName" />
<asp:BoundField DataField="UpLoadTime" HeaderText="UpLoaded" />
<asp:BoundField DataField="Size" HeaderText="Size" />
<asp:BoundField DataField="Pages" HeaderText="Pages" />
<asp:TemplateField HeaderText="Preview">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" Width="120px" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Download" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<button id="cmdDownLoad" runat="server" class="btn myshadow"
onserverclick="cmdDownLoad_Click">
<span aria-hidden="true" class="glyphicon glyphicon-cloud-download"></span>
</button>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<button id="cmdDelete" runat="server" class="btn myshadow"
onclick="if (!delok(this)) {return false};"
onserverclick="cmdDelete_ServerClick">
<span aria-hidden="true" class="glyphicon glyphicon-trash"></span>
</button>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
</div>
And I have this javascript code to refresh the grid view.
<asp:Button ID="cmdLoadGrid" runat="server" Text="Button"
style="display:none" ClientIDMode="Static" OnClick="cmdLoadGrid_Click"
/>
<script>
function AllDone() {
$('#cmdLoadGrid').click()
}
So, I in fact "click" the button after everything is done, since the aj fileupload does not do a post-back, and I in fact wanted one!
And my file save after up-load looks rather simular to what you have:
this:
Protected Sub AjaxFileUpload1_UploadComplete(sender As Object,
e As AjaxControlToolkit.AjaxFileUploadEventArgs)
Dim sPath As String = Server.MapPath("~/UpLoadFiles/")
Dim sFilePath As String = sPath & e.FileName
AjaxFileUpload1.SaveAs(sFilePath)
Dim strSQL As String =
"INSERT INTO MyUploadFiles (FileName, UpLoadTime, Size, SavePath, Pages, Preview)
Values (#FileName, #UpLoadTime, #Size, #SavePath, #Pages, #Preview)"
Dim cmdSQL As New SqlCommand(strSQL)
cmdSQL.Parameters.Add("#FileName", SqlDbType.NVarChar).Value = e.FileName
cmdSQL.Parameters.Add("#UpLoadTime", SqlDbType.NVarChar).Value = DateTime.Now
cmdSQL.Parameters.Add("#Size", SqlDbType.Int).Value = e.FileSize
cmdSQL.Parameters.Add("#SavePath", SqlDbType.NVarChar).Value = sPath
Dim iBytes() As Byte
Dim PageCount As Integer = 0
Select Case Path.GetExtension(e.FileName)
Case ".pdf"
iBytes = GetPdfThumb2(sFilePath, PageCount)
Case ".zip"
iBytes = GimageF(Server.MapPath("~/Content/Pictures/zip.png"))
Case ".bmp", ".gif", ".jpeg", ".jpg", ".png"
iBytes = GimageF(sFilePath)
Case Else
' use generatic picture
iBytes = GimageF(Server.MapPath("~/Content/Pictures/generic.png"))
End Select
cmdSQL.Parameters.Add("#Pages", SqlDbType.Int).Value = PageCount
cmdSQL.Parameters.Add("#Preview", SqlDbType.Binary).Value = iBytes
MyrstPN(cmdSQL)
End Sub

Related

How to upload Image to Web APP (Asp.net) and hold it for processing?

I am trying to create a web app using asp.net (trying to get some knowledge in order to work on more advanced stuff later on). The app I'm trying to make needs to have a picture uploaded to it and then do some processing to it. Now the question, Can I have the user upload this picture display it on the page and hold it somewhere temporarily for processing without making use of a database?
Tried looking through YouTube and web but couldn't find any specific documentation.
Gee, I don't see why a database would matter?
If you don't have a database, that should not effect that you can just drop in a file up loader, up-load files to say some folder, and then display the list of files that been up-loaded. And you are 100% free to THEN process those files later that been dropped into that folder, right?
So, lets drop in a file up-loader (you can choose/use one of a "gazillion" such up-loaders, or use a simple fileupload control.
Right below that control, then drop in say a grid view to display the files you up-loaded into that folder.
So, say this markup:
<asp:RadioButtonList ID="RadioButtonList1" runat="server" height="40px"
RepeatDirection="Horizontal" CssClass="rMyChoice" ClientIDMode="Static"
AutoPostBack="true" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
<asp:ListItem Selected="True">Upload Files</asp:ListItem>
<asp:ListItem>My Files</asp:ListItem>
</asp:RadioButtonList>
<br />
<div id="uploadfiles" runat="server" style="width:550px">
<ajaxToolkit:AjaxFileUpload ID="AjaxFileUpload1" runat="server"
OnUploadComplete="AjaxFileUpload1_UploadComplete"
OnClientUploadCompleteAll="AllDone" />
</div>
<div id="myfiles" runat="server" style="width: 700px">
<asp:GridView ID="GridFiles" runat="server"
AutoGenerateColumns="False" ShowHeaderWhenEmpty="true" CssClass="table table-hover" >
<Columns>
<asp:BoundField DataField="FileName" HeaderText="FileName" />
<asp:BoundField DataField="Created" HeaderText="UpLoaded" />
<asp:BoundField DataField="Size" HeaderText="Size" />
<asp:TemplateField HeaderText="Preview">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" Width="120px"
ImageUrl='<%# "UpLoadFiles/" + Eval("FileName") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Download" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Button ID="cmdDownLoad"
runat="server" Text="Download" CssClass="btn"
OnClick="cmdDownLoad_Click"
CommandArgument='<%# Eval("FileName") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
</div>
I am using the ajaxtoolkit up-loader, but it kind of don't really matter here at all.
Then below the up-loader, I just dropped in a grid view to display the files after up-loading.
Heck, might as well use a tab control, or a simple radio button list, so the user can view files, or up-load some more.
So, with above, I have this code behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
RBShow()
End Sub
Sub LoadGrid()
Dim rstFiles As New DataTable
rstFiles.Columns.Add("FileName")
rstFiles.Columns.Add("Created", GetType(DateTime))
rstFiles.Columns.Add("Size")
Dim sFolder As String = "~/UpLoadFiles"
Dim MyFolder As New DirectoryInfo(Server.MapPath(sFolder))
Dim MyFileList() As FileInfo = MyFolder.GetFiles("*.*")
For Each OneFile As FileInfo In MyFileList
Dim OneRow As DataRow = rstFiles.NewRow
OneRow("FileName") = OneFile.Name
OneRow("Created") = OneFile.CreationTime.ToString("G")
OneRow("Size") = OneFile.Length
rstFiles.Rows.Add(OneRow)
Next
GridFiles.DataSource = rstFiles
GridFiles.DataBind()
End Sub
Protected Sub RadioButtonList1_SelectedIndexChanged(sender As Object, e As EventArgs)
RBShow()
End Sub
Sub RBShow()
' routine to hide and show a div based on radio button (this is our fake tab control)
If RadioButtonList1.SelectedIndex = 0 Then
uploadfiles.Style.Add("Display", "normal")
myfiles.Style.Add("Display", "none")
Else
LoadGrid()
uploadfiles.Style.Add("Display", "none")
myfiles.Style.Add("Display", "normal")
End If
End Sub
The file uploader has a up-load file complete event. That code is simple this:
Protected Sub AjaxFileUpload1_UploadComplete(sender As Object, e As AjaxControlToolkit.AjaxFileUploadEventArgs)
Dim sFile As String = Server.MapPath("~/UpLoadFiles/") & e.FileName
AjaxFileUpload1.SaveAs(sFile)
End Sub
So, when we run the page, we get this:
So, since you don't have a database - don't need one!
Then just load up a grid view, or listbox or whatever with a list of files from the folder you save all the files being up-loaded.
of course in above, I do have a download button.
that code looks like this:
Protected Sub cmdDownLoad_Click(sender As Object, e As EventArgs)
Dim myBut As Button = sender
Dim strFileOnly As String = myBut.CommandArgument
Dim strFile As String = ""
strFile = Server.MapPath("~/UpLoadFiles/" + strFileOnly)
Dim sMineType As String = MimeMapping.GetMimeMapping(strFileOnly)
Response.ContentType = sMineType
Response.AppendHeader("Content-Disposition", "attachment; filename=" + strFileOnly)
Response.TransmitFile(strFile)
Response.End()
End Sub
So, the files are still in that folder for "later" processing.
And even better, if you go back to the page, you can "view" the list of files already up-loaded, or up-load a few more.
So, it not at all clear why a database is required. Those files are just sitting in a folder.
You can then process those files, say when done move to another folder called MyProcessed.
And then you are free to up-load more files for processing that will reside in that MyUpLoads folder.

Writing a WebPage in VB 4.8. A GridView has parameters, which outlet to new Data Fields in a DetailsView

The WebPage is set up for Sales and I need to reorganise the ID index i am given (In the GridView)
I have chosen a procedure that's using scripted DataTable to fill a DetailsView.
Sub SortOrder_Item(ByVal Sender As Object, ByVal e As GridViewCommandEventArgs) Handles SortOrder.RowCommand
Dim workTable As New System.Data.DataTable
Dim DTabRow As System.Data.DataRow = workTable.NewRow
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim Din As GridViewRow = SortOrder.Rows(index)
if e.CommandName = "Add" Then
Dim workCol As System.Data.DataColumn = workTable.Columns.Add("ID", Type.GetType("System.Int32"))
workCol.AllowDBNull = false
workCol.Unique = false
Dim _Item_Name As String = Server.HTMLDecode(Din.Cells(1).Text)
Dim _Curr_Price As Int32 = Server.HTMLDecode(Din.Cells(4).Text)
Dim _REFNo As String = Server.HTMLDecode(Din.Cells(5).Text)
Dim Dout As Int32 = index +1
workCol = New System.Data.DataColumn()
workCol.DataType = System.Type.GetType("System.String")
workCol.AllowDBNull = True
workCol.Caption = ""
workCol.ColumnName = "ItemName" & Dout
workCol.DefaultValue = ""
workTable.Columns.Add(workCol)
workCol = New System.Data.DataColumn()
workCol.DataType = System.Type.GetType("System.Double")
workCol.AllowDBNull = True
workCol.Caption = ""
workCol.ColumnName = "Curr_Price" & Dout
workCol.DefaultValue = 0
workTable.Columns.Add(workCol)
workCol = New System.Data.DataColumn()
workCol.DataType = System.Type.GetType("System.String")
workCol.AllowDBNull = True
workCol.Caption = ""
workCol.ColumnName = "REFNo" & Dout
workCol.DefaultValue = ""
workTable.Columns.Add(workCol)
workCol = New System.Data.DataColumn()
DTabRow("ID") = Dout
DTabRow("ItemName" & Dout) = _Item_Name
DTabRow("Curr_Price" & Dout) = _Curr_Price
DTabRow("REFNo" & Dout) = _REFNo
workTable.Rows.Add(DTabRow)
DetailInsert.DataSource = workTable
DetailInsert.DataBind()
SortOrder.Enabled = False
Go_NET.Visible = True
else
Go_NET.Visible = False
end if
End Sub
Sub CustomerDetailsView_ItemUpdating(ByVal sender As Object, ByVal e As DetailsViewUpdateEventArgs)
End Sub
Sub CustomerDetailsView_ModeChanging(ByVal sender As Object, ByVal e As DetailsViewModeEventArgs)
If e.CancelingEdit Then
' The user canceled the update operation.
' Clear the error message label.
MesX1.Text = ""
End If
End Sub
And so, the Edit Command is not working and will not show (Update/Cancel) Control.
If I tried to directly assign a DataSourceID to my DetailsView Submission form I'm sure it works but the whole Database needs its index's organized.
Gee, you filled out the GV, so why not just grab the pk ID of that row, and re-pull that one row from the database?
It certainly not going to really for all practical purposes increase the server load to re-pull that one record. But, while it not a performance issue, it MOST certainly is going to save you a BOATLOAD of hand coding.
So, I suggest you don't try and "hand code" the creating of the one row from the GV. You only going to write all that code, but then if you add, or change the columns, you right back to hand coding the one row data. Worse yet, such code really can't be re-used for other pages.
I suggest that you simple re-pull the data and get a nice working row.
Over time, I suggest you build a "helper" routine that "automatic" puts the columns from the one row into the controls on the form. That way, then you don't have to hand code the loading up of controls each time.
And then write ONE routine to do the reverse (take values from the controls back to the data row). Then one more routine to write that row out to the database.
With these 3 simple routines, then you can now use that code for all forms and all of your work (and not re-write what amounts to the same code over and over).
And you "could" use the details' view, but you still have to type in eval("some column name") anyway. So, might as well type in that code in vb - its about the same efforts.
So, I suggest this approach:
our grid view, and drop in a plane jane regular edit button (don't' bother with the GridView event model - it not all that great for editing the VERY instant you start to use custom code for this).
As noted, a details view will not help much either.
(Since we not trying to use the built-in wizards, and they are not that flexible).
So, so our grid view:
<div id="MyGridArea" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID"
CssClass="table table-hover" Width="60em" GridLines="None"
ShowHeaderWhenEmpty="true">
<Columns>
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="City" HeaderText="City" />
<asp:BoundField DataField="HotelName" HeaderText="HotelName" />
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="cmdEdit" runat="server" Text="Edit" CssClass="btn myshadow"
OnClick="cmdEdit_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
Note how we do NOT expose nor include the pk "ID" in that grid. We set/use the Datakeys setting (a VERY nice feature, since then we don't have to try and "hide" the pk row, and better yet its secure - and 100% server side managed for us).
Ok, so now our code to load the grid can be this:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
LoadGrid()
End If
End Sub
Sub LoadGrid()
Dim strSQL = "SELECT * FROM tblHotelsA ORDER BY HotelName"
GridView1.DataSource = Myrst(strSQL)
GridView1.DataBind()
End Sub
And we now have/see this:
Ok, so now our edit button.
That markup is this:
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="cmdEdit" runat="server" Text="Edit" CssClass="btn myshadow"
OnClick="cmdEdit_Click" />
</ItemTemplate>
</asp:TemplateField>
But note VERY close in above. Note the click event!!!
But, we can't just double click on that button to create a click event, since it is nested inside of the GV. So this BIG HUGE NICE tip?
You add the click event while in markup, and type in
OnClick=
The instant you hit "=", then note close, you get a popup to add the click event like this:
So, we choose to create new event. Don't seem like much occurred, and our button markup become this:
<asp:Button ID="cmdEdit" runat="server" Text="Edit" CssClass="btn myshadow"
OnClick="cmdEdit_Click" />
Now, if we flip to code behind, we have a button click for that button - but one inside of the GV.
So, our button needs to:
Get the current row id, and the row PK for the database row
We then transfer that data to our "div area", and then hide the GV,
display the "edit div".
The above is "nice" since now we again writing plane jane simple markup, and our buttons to cancel, save, or even delete are ALSO plane jane code behind.
So, only part now we need is our "edit div" area. As noted, I don't see much in the way of using details view here. You can use a details view, but I don't think it helps much at all.
Ok, so our edit div looks like this:
(just plane jane markup in that "div" with controls, check box etc. to edit the one row).
<div id="EditRecord" runat="server" style="float: left; display: none" >
<br />
<div style="float: left" class="iForm">
<label>HotelName</label>
<asp:TextBox ID="txtHotel" runat="server" Width="280">
</asp:TextBox>
<br />
<label>First Name</label>
<asp:TextBox ID="tFN" runat="server" Width="140"></asp:TextBox>
<br />
<label>Last Name</label>
<asp:TextBox ID="tLN" runat="server" Width="140"></asp:TextBox>
<br />
<label>City</label>
<asp:TextBox ID="tCity" runat="server" Width="140"></asp:TextBox>
<br />
<label>Province</label><asp:TextBox ID="tProvince" runat="server" Width="75"></asp:TextBox>
</div>
<div style="float: left; margin-left: 20px" class="iForm">
<div style="float: left">
<label>Description</label>
<br />
<asp:TextBox ID="txtNotes" runat="server" Width="260px" TextMode="MultiLine"
Height="100px" ></asp:TextBox>
</div>
<div style="float: left; margin-left: 14px">
<label>Hotel Options</label>
<br />
<asp:CheckBox ID="chkSmoking" runat="server" Text="Smoking" />
<br />
<asp:CheckBox ID="chkBalcony" runat="server" Text="Balcony" />
<br />
<asp:CheckBox ID="chkBags" runat="server" Text="Has Baggage" />
<br />
</div>
<div style="clear: both">
</div>
<asp:CheckBox ID="chkActive" Text=" Active"
runat="server" TextAlign="Right" Width="171px" />
</div>
<div style="clear: both"></div>
<hr />
<button id="cmdSave" runat="server" class="btn myshadow" type="button"
onserverclick="cmdSave_ServerClick" >
<span aria-hidden="true" class="glyphicon glyphicon-floppy-saved">Save</span>
</button>
<button id="cmdCancel" runat="server" class="btn myshadow" style="margin-left: 15px"
type="button"
onserverclick="cmdCancel_ServerClick" >
<span aria-hidden="true" class="glyphicon glyphicon-arrow-left">Back/Cancel</span>
</button>
<button id="cmdDelete" runat="server" class="btn myshadow" style="margin-left: 15px"
type="button"
onserverclick="cmdDelete_ServerClick"
onclick="if (!confirm('Delete this record?')) {return false};">
<span aria-hidden="true" class="glyphicon glyphicon-trash">Delete</span>
</button>
<br />
<br />
</div>
</div>
as a FYI:
I used html "buttons" in above. I COULD have used plane jane asp.net buttons, but I wanted the cute looking bootstrap icons. I should point out that after bootstrap 4, they dropped the including of the bootstap icons, but if you wish, use plane jane asp.net buttons for those 3 buttons if you have any trouble with using html "buttons". I did use plane jane vb code behind for those buttons, and note how I have used onserverclick - just a wee bit different syntax in the markup, but code behind is really the same as any button click code on a typical page.
Ok, so now we need our edit button code.
So, this is where we now have to type in those controls. (as noted, for future, we can write a routine that does this over and over for any markup, but for now, baby steps, just some baby steps).
So, we have this code on the edit button.
Protected Sub cmdEdit_Click(sender As Object, e As EventArgs)
Dim btn As Button = sender
Dim gRow As GridViewRow = btn.NamingContainer
Debug.Print("Row index click = " & gRow.RowIndex)
' get data base key
Dim intPK As Integer = GridView1.DataKeys(gRow.RowIndex).Item("ID")
Dim strSQL As String = "SELECT * FROM tblHotelsA WHERE ID = " & intPK
Dim rstData As DataTable = Myrst(strSQL)
' load up our edit div area
With rstData.Rows(0)
txtHotel.Text = .Item("HotelName")
tFN.Text = .Item("FirstName")
tLN.Text = .Item("LastName")
tCity.Text = .Item("City")
tProvince.Text = .Item("Province")
txtNotes.Text = .Item("Description")
chkActive.Checked = .Item("Active")
chkBalcony.Checked = .Item("Balcony")
chkSmoking.Checked = .Item("Smoking")
End With
ViewState("PK") = intPK ' same our PK for later
ShowGrid(False) ' hide GV, show edit area
End Sub
So, really, shoving a bunch of eval("column name") in markup, or typing in the text box as per above = about the same amount of effort on your part.
So, really, now all we need is a save button to write the data back to the table.
That code is really quite much the reverse of the edit button load code.
So, this code does the trick:
Protected Sub cmdSave_ServerClick(sender As Object, e As EventArgs)
Dim intPK As Integer = ViewState("PK")
Dim strSQL As String = "SELECT * FROM tblHotelsA WHERE ID = " & intPK
Using conn = New SqlConnection(My.Settings.TEST4)
Using cmdSQL = New SqlCommand(strSQL, conn)
conn.Open()
Dim da As New SqlDataAdapter(cmdSQL)
Dim daU As New SqlCommandBuilder(da)
Dim rstData As New DataTable
rstData.Load(cmdSQL.ExecuteReader)
With rstData.Rows(0)
.Item("HotelName") = txtHotel.Text
.Item("FirstName") = tFN.Text
.Item("LastName") = tLN.Text
.Item("City") = tCity.Text
.Item("Province") = tProvince.Text
.Item("Description") = txtNotes.Text
.Item("Active") = chkActive.Checked
.Item("Balcony") = chkBalcony.Checked
.Item("Smoking") = chkSmoking.Checked
End With
da.Update(rstData)
End Using
End Using
LoadGrid() ' refrsh grid to show any new edits
ShowGrid(True)
End Sub
So, that quite much gives this effect:
So, it not a lot of code, but I think more imporant is all the code is quite plane jane - nothing fancy.
The other "helper routine" I used was this one, and it simple returns a table for a given SQL query:
Public Function Myrst(strSQL As String) As DataTable
Dim rstData As New DataTable
Using mycon As New SqlConnection(My.Settings.TEST4)
Using cmdSQL As New SqlCommand(strSQL, mycon)
mycon.Open()
rstData.Load(cmdSQL.ExecuteReader)
End Using
End Using
Return rstData
End Function
Make GOOD close note of how I used the simple button click to get the current gv row index and PK. That code works for a repeater, listview, gridview etc, and it allows you to dispense with the built in grid/listview/repeater events, and use a simple button click.

ASP:Gridview checkbox column with paging is not showing which checkbox is checked

In a Asp:GridView (ASP.NET/VB), I have a column of checkbox:
<asp:TemplateField HeaderText=" " ItemStyle-BorderWidth="1" HeaderStyle-Width="3%" ItemStyle-Width="3%" HeaderStyle-CssClass="box_border table_title" ItemStyle-CssClass="box_border ">
<ItemTemplate>
<asp:CheckBox ID="chkHaktzaa" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
And I also have paging in the grid:
<table id="pager" align="center" dir="ltr" clientidmode="Static" runat="server" cellspacing="0" cellpadding="0">
<tr>
<td id="last" class="last" runat="server" clientidmode="Static"></td>
<td id="next" runat="server" tooltip="הבא" class="next" clientidmode="Static"></td>
<td>
<input id="pageNum" runat="server" class="pagedisplay" clientidmode="Static" />
</td>
<td class="prev" clientidmode="Static"></td>
<td class="first" clientidmode="Static"></td>
<td>
<select id="numOfRec" runat="server" class="pagesize" clientidmode="Static">
<option selected="selected" value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
<option value="40">40</option>
<option value="50">50</option>
</select>
</td>
</tr>
</table>
In code-behind when I iterate over these grid rows, and programmatically access the CheckBox control, and then consult its Checked property to determine whether the it's been selected, it only works with the current page of the grid. It does not consider the other pages.
The rows on the other pages always return false for checked.
This is the iteration loop:
For Each row As GridViewRow In gvBakashot.Rows
Dim cb As CheckBox = row.FindControl("chkHaktzaa")
If cb IsNot Nothing And cb.Checked Then
lst.Add(count)
End If
count = count + 1
Next
Thank you for the help.
Well of course when you re-load the page and re-load the WHOLE grid to a new page of data, a un-bound check box is not going to hold or remember its value.
What this means is that you need to get/grab/save the check box into some colleciton that persists, and then on grid display/re-load, you have to then re-set the check boxes.
In other words, if you jump to a new page, then you are doing a 100% whole new re-load of the page and the grid - and of course some old preivous grid loaded will not remember what check boxes were checked.
So, you need to manage (save) the checked boxes. So the only question then becomes do we do this DURING each check box checked, or when you page - really the ONLY question we need to answer here.
You don't mention how many rows you show - but the grid for a given page will persist (assuming you written this correctly and DO NOT re-load the grid when a page post-back occurs. In other words, your page load event ONLY loads the grid on first page load (PostBack = false). Assuming this critical design issue? (which ALL and EVERY page you write BETTER follow this rule!!!).
Ok, then, I suggest this:
Here is the markup:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID" CssClass="table" Width="50%" AllowPaging="True">
<Columns>
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="HotelName" HeaderText="HotelName" />
<asp:BoundField DataField="City" HeaderText="City" />
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="ckSel" runat="server"
Checked='<%# MyChecked(Eval("ID")) %>'
AutoPostBack="true"
OnCheckedChanged="ckSel_CheckedChanged"
/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle CssClass="GridPager" />
</asp:GridView>
And our code to fill the grid is this:
Dim MyCheckList As New List(Of Integer)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
LoadGrid()
ViewState("CheckList") = MyCheckList
Else
MyCheckList = ViewState("CheckList")
End If
End Sub
Sub LoadGrid()
Using conn As New SqlConnection(My.Settings.TEST4)
Using cmdSQL As New SqlCommand("SELECT * from tblHotels ORDER BY HotelName", conn)
Dim rstData As New DataTable
conn.Open()
rstData.Load(cmdSQL.ExecuteReader)
GridView1.DataSource = rstData
GridView1.DataBind()
End Using
End Using
End Sub
Public Function MyChecked(ID As Integer) As Boolean
Return MyCheckList.Contains(ID)
End Function
Now HOW we persist that "list" to the page.
Now, it is a simple matter to write the code for the check box above.
And that code is easy, and this:
Protected Sub ckSel_CheckedChanged(sender As Object, e As EventArgs)
' user click on check box
Dim ckSel As CheckBox = sender
Dim gRow As GridViewRow = ckSel.Parent.Parent
Dim PKID As Integer = GridView1.DataKeys(gRow.RowIndex).Item("ID")
If ckSel.Checked Then
' add to our collection
MyCheckList.Add(PKID)
Else
' remove from check list
MyCheckList.Remove(PKID)
End If
End Sub
And the results are now this:
So, now mylist will maintain, and keep a list of the choices you made.
You can then say do this:
' get selected data
Dim rstData As New DataTable
Dim strWhere As String = String.Join(",", MyCheckList.ToArray())
Dim strSQL As String
strSQL = "SELECT * from tblHotels WHERE ID IN(" & strWhere & ") ORDER BY HotelName"
Using conn As New SqlConnection(My.Settings.TEST4)
Using cmdSQL As New SqlCommand(strSQL, conn)
conn.Open()
rstData.Load(cmdSQL.ExecuteReader)
End Using
End Using
' now do whatever,
For Each OneRow As DataRow In rstData.Rows
' do whatever
Next
So you can then pass the PK id list.
Note ALSO very careful in above, we did not show, or even have to display the PK value from each row - we used DataKeys for that. This is great for MANY reasons, but significant is we DO NOT expose the PK database id's in the grid or markup. this is really nice for reasons of security, and it also meant we did not include the PK ID in the grids markup either, nor did we even have to hide the pk column - that's what DataKeys feature is for.
Edit: To be fair? I did use Eval("ID") - and did expose the ID in the GV - but I actually did not have to do this (code was shorter).

How to add new line items in a APS.net webform and submit to database

Please note: I do not necessarily need working code. I just don't know how to word what I am looking for to even find an answer on the web. I guess i'm just asking for a little guidance on what kind of control I would to use to accomplish my goal.
Basically when I go to a job site I will use different amounts and types of inventory. So one line item would consist of
Item Description
Quantity Used
UsedByTech
I'm collecting these via webform text box. I would like to have a button that says "Add" and then allows me to input another line item, and so on.
Then at some point a submit button on the form would gather those line items and input them in to a MSSQL databse.
I'm currently using ASP.Net framwork and webforms.
Can somone please tell me what kind of control would allow this a may be give me some hints about what to search for?
Ok, this is actually quite easy - but we let asp.net do most of the work for us.
So, we assume we have these two tables:
so, we have a table to list out the Job Sites
And then as per above, we have a table to list out the Job items for each site.
Ok, so we display the Job Sites.
Drop in a Gridview - build it using the wizards:
Now, blow out (delete) the data source from the page - don't need it.
Remove the DataSource setting for the Gridview
And lets drop in a plane jane button into that grid.
Thus, this markup - most of it was generated for me
<div style="padding:25px">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID" CssClass="table" Width="40%">
<Columns>
<asp:BoundField DataField="JobSite" HeaderText="JobSite" />
<asp:BoundField DataField="JobDate" HeaderText="JobDate" DataFormatString="{0:yyyy-MM-dd}" />
<asp:BoundField DataField="Foreman" HeaderText="Foreman" />
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:TemplateField HeaderText="View">
<ItemTemplate>
<asp:Button ID="cmdView" runat="server" Text="View Job" CssClass="btn"
Onclick="cmdView_Click"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
And our code to load this grid is thus this:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
LoadGrid
End If
End Sub
Sub LoadGrid()
GridView1.DataSource = MyRst("SELECT * from JobSites Order by JobDate")
GridView1.DataBind()
End Sub
Ok, we now have this:
Ok, so now we need to wire up that "view" button.
So, we grab the PK row value - jump to our edit items page;
Protected Sub cmdView_Click(sender As Object, e As EventArgs)
Dim btn As Button = sender
Dim gRow As GridViewRow = btn.Parent.Parent
' get PK database ID
Dim PK As Integer = GridView1.DataKeys(gRow.RowIndex).Item("ID")
' Now jump to our job add job items page
Session("JobID") = PK
Response.Redirect("JobAddItems.aspx")
End Sub
So, now we need to build our 2nd page.
I could use a repeater - but I used DataList - to display the ONE job.
I again used the wizards - then blow out the DataSource setting and item on that page.
We then drop in a gridview for the "many" items (the job items).
I now have this:
<br />
<div style="border:solid;border-color:black;width:20%">
<asp:DataList ID="DataList1" runat="server" DataKeyField="ID">
<ItemTemplate>
JobSite:
<asp:Label ID="JobSiteLabel" runat="server" Text='<%# Eval("JobSite") %>' Font-Size="Larger" Font-Bold="true" />
<br />
JobDate:
<asp:Label ID="JobDateLabel" runat="server" Text='<%# Eval("JobDate", "{0:yyyy-MM-dddd}") %>' />
<br />
Foreman:
<asp:Label ID="ForemanLabel" runat="server" Text='<%# Eval("Foreman") %>' />
<br />
Description:
<asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' />
<br />
<br />
</ItemTemplate>
</asp:DataList>
<br />
</div>
<br />
<div style="float:left">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID" CssClass="table borderhide" Width="30%">
<Columns>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:TextBox id="txtDesc" runat="server" Text='<%# Eval("ItemDescription") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Qty">
<ItemTemplate>
<asp:TextBox id="txtQty" runat="server" Text='<%# Eval("Qty") %>' TextMode="Number" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Used By">
<ItemTemplate>
<asp:TextBox id="txtUsedBy" runat="server" Text='<%# Eval("UsedBy") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<div style="float:right">
<asp:Button ID="cmdAdd" runat="server" Text="Add Item" CssClass="btn" style="margin-top:-20px" />
</div>
</div>
<div style="clear:both"></div>
<asp:Button ID="cmdSave" runat="server" Text="Save" CssClass="btn" />
<asp:Button ID="cmdCancel" runat="server" Text="Cancel" CssClass="btn" style="margin-left:40px"/>
</div>
Ok, and the code to load this up is this:
We load up the main record - just for display, and then the GridView of child items.
Dim rstJobItems As New DataTable
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
ViewState("JobID") = Session("JobId")
LoadData()
Else
rstJobItems = ViewState("JobItems")
End If
End Sub
Sub LoadData()
DataList1.DataSource = MyRst("SELECT * from JobSites WHERE ID = " & ViewState("JobID"))
DataList1.DataBind()
rstJobItems = MyRst("SELECT * FROM JobItems where Job_ID = " & ViewState("JobID"))
GridView1.DataSource = rstJobItems
GridView1.DataBind()
ViewState("JobItems") = rstJobItems
End Sub
Ok, so now on the first page, when we click on a row, we jump to the 2nd page, and we see/have this:
So we need to wire up the button to add a new row.
That code looks like this:
Protected Sub cmdAdd_Click(sender As Object, e As EventArgs) Handles cmdAdd.Click
' user might have done some edits
GridToTable()
' create a new row
Dim NewRow As DataRow = rstJobItems.NewRow
NewRow("Job_id") = ViewState("JobID")
NewRow("Qty") = 0
rstJobItems.Rows.Add(NewRow)
GridView1.DataSource = rstJobItems
GridView1.DataBind()
End Sub
So, say in above, I click the add row, then you will see this:
(in fact I clicked it two times).
Ok, so you are free to tab around - edit data in that grid. You can edit/change existing rows, or add a new row and simple tab around and enter data.
So, now lets wire up the Save button. That save button has to allow and deal with editing rows - and also saving edits - all in ONE shot to the database.
The code for save button is thus this:
Protected Sub cmdSave_Click(sender As Object, e As EventArgs) Handles cmdSave.Click
GridToTable()
Using conn As New SqlConnection(My.Settings.TEST4)
Using cmdSQL As New SqlCommand("SELECT * FROM JobItems WHERE ID = 0", conn)
Dim da As New SqlDataAdapter(cmdSQL)
Dim daU As New SqlCommandBuilder(da)
da.Update(rstJobItems)
End Using
End Using
' data add, and any edit now saved - return to our job site listing page
Response.Redirect("JobSites.aspx")
End Sub
So we send grid to table, and then in ONE database update, send the table back to the database.
Of course after we save, we return back to our first page with the grid now read to edit more.
So, the other routine used in above was sending the Grid (rows) back to the table.
That code is this:
Sub GridToTable()
For Each gRow As GridViewRow In GridView1.Rows
Dim OneRow As DataRow = rstJobItems.Rows(gRow.RowIndex)
OneRow("ItemDescription") = CType(gRow.FindControl("txtDesc"), TextBox).Text
OneRow("Qty") = CType(gRow.FindControl("txtQty"), TextBox).Text
OneRow("UsedBy") = CType(gRow.FindControl("txtUsedBy"), TextBox).Text
Next
End Sub
And of course the cancel button? Well, if you add some rows, or just edit the rows, and hit cancel? Well, we don't save - but just return to the previous page.
eg:
Protected Sub cmdCancel_Click(sender As Object, e As EventArgs) Handles cmdCancel.Click
Response.Redirect("JobSites.aspx")
End Sub
And last but not least, I have a "general" helper routine that simple returns a data table - and I used it several times in above. That routine kind of gives me a FoxPro or MS-Access like ability to get a data table with great ease (in place of typing that same code over and over).
That routine was this:
Public Function MyRst(strSQL As String) As DataTable
Dim rstData As New DataTable
Using conn As New SqlConnection(My.Settings.TEST4)
Using cmdSQL As New SqlCommand(strSQL, conn)
conn.Open()
rstData.Load(cmdSQL.ExecuteReader)
End Using
End Using
Return rstData
End Function
So the above is quite much start to finish. It is of course quick code, and done rather fast/quick for stack overflow. But it is full of great ideas, and as noted, I let the wizards generate most of the markup. (but then remove the data source from the GV, and also the Data source item that gets created in the page.
So in summary:
I did not write most of that markup - I let the wizards generate most of it.
Note how SMALL and relative simple the code bits were. we broke up this into bite sized parts - thus each routine is not a lot of code.
We ALSO let .net built the sql update (and insert) commands for us. this eliminated BOAT LOADS of parameters, and BOATLOADS of work to wire that up. And it also MUCH better for performance, since ado.net is smart - for rows not changed - it don't send the updates to sql server.
Note also how ONE simple update method of
da.Update(rstJobItems)
Handles BOTH edits/updates, an inserts with one command. And we probably could/should drop in a delete row button - and the update would also handle that for us too!!!
So, there is a LOT of great ideas in above, but key concepts are:
Leverage as much as you can the wizards, and built in controls.
Leverage the ability of ado.net to update a table of edits in ONE shot back to the database - and as above shows, SAME single update also works for both inserts and updates at the same time.

ModalPopup, UpdatePanel, Javascript "Object expected" Error with Internet Explorer

New information! The problem I describe below occurs only with Microsoft Internet Explorer. All others that I tested behaved as they should. Even Microsoft Edge handled it just fine. A lot of people use IE, so perhaps somebody knows a way to deal with the following problem:
A page in my asp.net web app has a modal popup which contains a listbox that must be populated on the fly. The page contains a treeview control; right clicking a node on the treeview calls up a context menu; and if the user clicks on "Add Pretask", the popup form appears, listing items which vary depending upon which node was clicked.
The listbox is contained within an UpdatePanel which was inserted so that the list could be populated without reposting the entire page. I developed this popup, tested it, and it appeared to be working properly. I was patting myself on the back for a job well done when I happened to press a key on the computer keyboard. The app crashed with the following error message:
"Unhandled exception at line 1010, column 1 in
http://localhost:55109/PPM/ScriptResource.axd?d=8GNeJYrV145FFZwe3zZTQTMdSqo5ZWiNHMcMCdX41b_dp65omt53usfcChKlDkhIbPdehfLSEKVkXbwQruOiDLDfxhVjDQZOQZDVfHxfkhrBY3rHZVHxg2I6VQGIFSKL2AhGUprc1gW7X0t1_Q79OAckMdH-JliDUkID4lzcsT8Bfkxn0&t=1e478eba
0x800a138f - JavaScript runtime error: Object expected"
This behavior is consistent. The popup will not tolerate any key strokes.
I have been wrestling with this problem for days. Thank you for any help you can offer.
Here is the relevant markup:
<a href="#" style="display:none;" onclick="javascript:return false" id="hidlinkAddPretask"
runat="server">dummy</a>
<cc1:ModalPopupExtender ID="mpePretask" runat="server" PopupControlID="pnlPretask" TargetControlID="hidlinkAddPretask"
CancelControlID="btnCancelPretask" ></cc1:ModalPopupExtender>
<asp:Panel ID="pnlPretask" runat="server" CssClass="popupPanel" Width="40%">
<asp:UpdatePanel ID="updPretask" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<ContentTemplate>
<!-- Panel within pnlPretask contains list of selected. -->
<asp:panel runat="server" ID="pnlPretaskList" Visible="false">
<asp:BulletedList ID="blPretasks" runat="server">
</asp:BulletedList>
</asp:panel>
<asp:HiddenField runat="server" ID="hidPostTaskID" Visible="true" />
Before <b>"<asp:Label ID="lblAddPretask" runat="server"></asp:Label>"</b> can be completed, I must:
<br /><br />
<asp:ListBox ID="lboxPretask" runat="server" Width="80%" Height="200px"
ToolTip="Select one or more tasks that must be completed before..." AutoPostBack="false"
SelectionMode="Multiple">
</asp:ListBox>
</ContentTemplate>
</asp:UpdatePanel>
<br /><br />
<asp:UpdateProgress ID="UpdateProgress4" runat="server" DisplayAfter="0">
<ProgressTemplate>
<img src="images/progress.gif" alt="" /> Updating...</ProgressTemplate>
</asp:UpdateProgress>
<asp:Label runat="server" ID="lblErrPretask" Font-Bold="True" ForeColor="Red" />
<br />
<asp:Button ID="btnAddAnotherPretask" runat="server" Text="Save and Add Another" />
<asp:Button ID="btnSavePretask" runat="server" Text="Save" />
<asp:Button ID="btnCancelPretask" runat="server" Text="Cancel" />
</asp:Panel>
The popup is launched from the server by this vb code:
Dim ID As String = e.NodeClicked.Attributes("TaskID").ToString
'Repopulate listbox
PretaskSelectList(ID)
updPretask.Update()
mpePretask.Show()
And this vb routine populates the listbox:
Private Sub PretaskSelectList(ByVal TaskID As Integer)
Dim strConn As String = ConfigurationManager.ConnectionStrings("PPMConnectionString").ConnectionString
Dim cnn As SqlConnection = New SqlConnection(strConn)
cnn.Open()
'Get two result sets from uspPretaskPickList
Dim sql As String = "execute dbo.uspPretaskPickList " & TaskID.ToString
Dim cmd As SqlCommand = New SqlCommand(sql, cnn)
'Result set #1 - Tasks from current Goal
Dim rdr As SqlDataReader = cmd.ExecuteReader()
Dim Itm As ListItem
With lboxPretask
.Enabled = True
.Items.Clear()
'Add a default item, #0
Itm = New ListItem("ADD NEW TASK", "0")
Itm.Attributes.Add("Style", "Font-Weight:Bold")
.Items.Add(Itm)
'Insert a separator if data reader has any records
Dim separator As New ListItem("-------------------------", "")
separator.Attributes.Add("disabled", "true")
If rdr.HasRows Then
.Items.Add(separator)
End If
'Add each member of 1st result set, using lboxPretask.Items.Add(New ListItem(TaskName, TaskID))
Do While rdr.Read
Itm = New ListItem(rdr("TaskName"), rdr("TaskID").ToString)
'Each item should be Bold.
Itm.Attributes.Add("Style", "Font-Weight:Bold")
.Items.Add(Itm)
Loop
'Add dividing line, Pretask.Items.Add("------------", "-1")
separator.Attributes.Add("disabled", "true")
.Items.Add(separator)
'Results set #2 - Tasks from other or no goal
rdr.NextResult()
'Add each member of 2nd result set, using lboxPretask.Items.Add(New ListItem(TaskName, TaskID))
Do While rdr.Read
Itm = New ListItem(rdr("TaskName"), rdr("TaskID").ToString)
.Items.Add(Itm)
Loop
End With
rdr.Close()
cnn.Close()
rdr = Nothing
cnn = Nothing
lboxPretask.ClearSelection()
End Sub
Thanks again for any insights you can provide.
Looks like your JS file is not getting referenced properly on your page.
You can fix the issue by referencing it like below.
<script type="text/javascript" src=<%# ResolveUrl("http://code.jquery.com/jquery-latest.min.js") %> ></script>
Reference:
0x800a138f - Microsoft JScript runtime error: Object expected

Resources