repeater control with ajax update panel for Paging - updatepanel

I have change my code. I add the updatepanel and the link buttons
Markup
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:LinkButton ID="btnPrev" runat="server" OnClick="btnPrev_Click">PrevButton</asp:LinkButton>
<asp:TextBox id="txtHidden" style="width: 28px" value="1" runat="server" />
<asp:LinkButton ID="btnNext" runat="server" OnClick="btnNext_Click">NextButton</asp:LinkButton>
<asp:Repeater ID="Repeater1" runat="server" >
<ItemTemplate>
<div class="latnewstitle">
Date:</div>
<%#DataBinder.Eval(Container.DataItem, "date")%><br />
<div class="latnewstitle">
title:</div>
<div class="latnewscontent">
<%#DataBinder.Eval(Container.DataItem, "title")%></div>
<asp:HyperLink ID="lnkDetails" runat="server" NavigateUrl='<%# Eval("item_ID", "~/Details.aspx?ID={0}") %>'>See Details</asp:HyperLink>
<br />
<br />
<hr width="100px" />
<br />
</ItemTemplate>
</asp:Repeater>
</div>
</ContentTemplate>
</asp:UpdatePanel>
my code behind
Public Property PgNum() As Integer
Get
If ViewState("PgNum") IsNot Nothing Then
Return Convert.ToInt32(ViewState("PgNum"))
Else
Return 0
End If
End Get
Set(value As Integer)
ViewState("PgNum") = value
End Set
End Property
Protected Sub Page_Load(sender As Object, e As EventArgs)
If Not Page.IsPostBack Then
bindrepeater()
End If
End Sub
I add the bindrepeater sub so bind datato the repeater
Protected Sub bindrepeater()
Dim strsql As String = "SELECT * FROM news ORDER BY news.item_ID DESC"
Dim sqlconn As New SqlConnection
sqlconn.ConnectionString = ConfigurationManager.ConnectionStrings("mycon").ToString
sqlconn.Open()
Dim cmd As New SqlCommand(strsql, sqlconn)
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds)
cnt = ds.Tables(0).Rows.Count
'Dim table As New DataTable()
'da.Fill(table)
Dim pds As New PagedDataSource()
pds.DataSource = ds.Tables(0).DefaultView
pds.AllowPaging = True
pds.PageSize = 5
pds.CurrentPageIndex = PgNum
txtHidden.Text = PgNum
Dim vcnt As Integer = cnt / pds.PageSize
If PgNum < 1 Then
btnPrev.Visible = False
ElseIf PgNum > 0 Then
btnPrev.Visible = True
End If
If PgNum = vcnt Then
btnNext.Visible = False
ElseIf PgNum < vcnt Then
btnNext.Visible = True
End If
Repeater1.DataSource = pds
Repeater1.DataBind()
sqlconn.Close()
End Sub
'My paging buttons
Protected Sub btnNext_Click(sender As Object, e As System.EventArgs) Handles btnNext.Click
PgNum += 1
bindrepeater()
End Sub
Protected Sub btnPrev_Click(sender As Object, e As System.EventArgs) Handles btnPrev.Click
PgNum -= 1
bindrepeater()
End Sub
Protected Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
bindrepeater()
End Sub
My problem is that my next button goes always +2 and the previous button -2.
Thank you

Related

vb.net add html to aspx page dynamically

I have an aspx page with a sidebar on the left.
The sidebar shows from one to many tasks grouped by date.
I want to show a modal popup passing an ID when user clicks a task.
The sidebar is something like this:
01/09/2016
Go to the dentist
Meet with Anna
02/09/2016
blabla
03/09/2016
bla1
bla2
bla3
etc.
On page load I declare variables and query my database with this:
Dim elementoLi As String = "<li><h2><i class=""fa fa-cog fa-fw""></i>XXX</h2>YYY</li>"
Dim htmlTitle As String = "<div class=""title"">
<h1>XXX</h1>
</div><div class=""content""><ul>YYY</ul></div><br/>"
Dim htmlContent As String = ""
Dim htmlChiamateaperte As String = ""
Dim htmlfinale As String = ""
Dim chiamateAperte = From statoRic In
dbVulcano.StatoRic.Where(Function(s) s.RFStato >= 11 And s.RFStato <= 13 And s.Attuale = 1 And s.RFTecnico = rfTecnico)
From richiesta In
dbVulcano.Richieste.Where(Function(r) r.IDRic = statoRic.RFRic).DefaultIfEmpty()
From cliente In
dbVulcano.Clienti.Where(Function(c) c.IDCliente = richiesta.RFCliente).DefaultIfEmpty()
Select statoRic.RFRic, statoRic.RFStato, statoRic.Attuale, richiesta.Descr, cliente.RagSociale, statoRic.DataAss, statoRic.Data, dataf = If(statoRic.DataAss.HasValue, statoRic.DataAss, statoRic.Data)
Order By dataf Descending
Then I cycle to create the sidebar structure:
For Each item In chiamateAperte
Dim data1 = Format(item.dataf, "dd/MM/yyyy")
If htmlChiamateaperte.Contains(data1) = False Then
htmlChiamateaperte = htmlChiamateaperte & Replace(htmlTitle, "XXX", data1)
htmlContent = ""
End If
For Each item2 In chiamateAperte
Dim data2 = Format(item2.dataf, "dd/MM/yyyy")
If data2 = data1 Then
Dim rags, desc As String
desc = UppercaseFirstLetter(item2.Descr)
rags = item2.RagSociale
htmlContent = htmlContent & Replace(Replace(elementoLi, "XXX", rags), "YYY", desc)
End If
Next
htmlChiamateaperte = Replace(htmlChiamateaperte, "YYY", htmlContent)
Next
divChiamateAperte.InnerHtml = "<h1>CHIAMATE APERTE</h1><br /><br />" & htmlChiamateaperte
Basically I dinamically create a string that at the end is passed as html code. What I need is to add links in the "elementoLi" var so that, once the user click on the link, it opens a modal popup (and passes along an ID). How can I do that? Doesn't matter if I have to change all the code to create the structure. Thanks
EDIT 1:
This is the structure I need:
<div class="panel" runat="server" id="divChiamateAperte" autopostback="true">
<h1>CHIAMATE APERTE</h1><br /><br />
<div class="title"><h1>dd/mm/yyyy</h1>
</div>
<div class="content">
<ul>
<li><h2><i class="fa fa-cog fa-fw"></i> RAGIONE SOCIALE 1</h2> Descrizione 1</li>
<li><h2><i class="fa fa-cog fa-fw"></i> RAGIONE SOCIALE 2</h2> Descrizione 2</li>
</ul>
</div>
<br />
<div class="title"><h1>dd/mm/yyyy</h1>
</div>
<div class="content">
<ul>
<li><h2><i class="fa fa-cog fa-fw"></i> RAGIONE SOCIALE 1</h2> Descrizione 1</li>
<li><h2><i class="fa fa-cog fa-fw"></i> RAGIONE SOCIALE 2</h2> Descrizione 2</li>
</ul>
</div>
</div>
EDIT 2:
I made this example using the structure above and the repeater, but the problem I see to obtain the above (where the block made by div title to div content can be 1 to infinite) is that I need to repeat the repeater result from 1 to X (where x is the data read from db).
<%# Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Repeater Example</title>
<script runat="server">
Sub Page_Load(Sender As Object, e As EventArgs)
If Not IsPostBack Then
Dim values As New ArrayList()
values.Add("Apple")
values.Add("Orange")
values.Add("Pear")
values.Add("Banana")
values.Add("Grape")
' Set the DataSource of the Repeater.
Repeater1.DataSource = values
Repeater1.DataBind()
End If
End Sub
</script>
</head>
<body>
<h3>Repeater Example</h3>
<form id="form1" runat="server">
<b>Repeater1:</b>
<br />
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<div class="title">
<h1>dd/mm/yyyy</h1>
</div>
<div class="content">
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<h2><i class="fa fa-cog fa-fw"></i><%# Container.DataItem %></h2>
Descrizione 1</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</div>
</FooterTemplate>
</asp:Repeater>
<br />
</form>
</body>
</html>
First of all, it is not recommended to use
Dim html as String = ""
html += .....
html += .....
this consume a lot of RAM on the server
Second, you may want to use the Repeater control if you are using .NET webform. Read more on the why on: http://blog.zay-dev.com/net-web-form-implementation-strategy-3-the-controls/
Example (.ASPX):
<asp:Repeater runat="server" ID="RepeaterCode">
<ItemTemplate>
<div>
<h1><asp:Literal runat="server" ID="LiteralHeader"/></h1>
<span class="<asp:Literal runat='server' ID='LiteralSpanClass'/>">
<asp:Literal runat="server" ID="LiteralSpanContent"/>
</span>
</div>
</ItemTemplate>
</asp:Repeater>
.ASPX.VB:
Protected Sub Page_Load(sender as Object, e as EventArgs) Handles Me.Load
RepeaterCode.DataSource = Source
RepeaterCode.DataBind()
End Sub
Protected Sub RepeaterCode_ItemDataBound(sender as Object, e as RepeaterItemEventArgs) Handles RepeaterCode.ItemDataBound
If (TypeOf e.Item Is RepeaterItem) Then
Dim LiteralHeader as Literal = e.Item.FindControl("LiteralHeader")
If (LiteralHeader IsNot Nothing) Then LiteralHeader.Text = "Header"
End If
End Sub
Edit 1 -
ASPX:
<div class="panel" id="divChiamateAperte">
<h1>CHIAMATE APERTE</h1>
<br /><br />
<asp:Repeater runat="server" ID="RepeaterGroups" OnItemDataBound="RepeaterGroups_ItemDataBound">
<ItemTemplate>
<div class="title">
<h1>
<asp:Literal runat="server" ID="LiteralHeader"/>
</h1>
</div>
<div class="content">
<ul>
<asp:Repeater runat="server" ID="RepeaterItems" OnItemDataBound="RepeaterItems_ItemDataBound">
<ItemTemplate>
<li>
<h2>
<i class="fa fa-cog fa-fw"><i>
<asp:Literal runat="server ID="LiteralItemText"/>
</h2>
<a href="#" onclick="ShowModal($(this).attr("data-id"))" data-id="<asp:Literal runat='server' ID='LiteralID'/>">
<asp:Literal runat="server" ID="LiteralAnchorText"/>
</a>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
.ASPX.VB:
Protected Sub Page_Load(sender as Object, e as EventArgs) Handles Me.Load
If (Not Me.IsPostBack) Then
Dim dt as DataTable = Model.GetSideBarGroups()
RepeaterGroups.DataSource = dt
RepeaterGroups.DataBind()
End If
End Sub
Protected Sub RepeaterGroups_ItemDataBound(Sender As Object, e As RepeaterItemEventArgs)
If (TypeOf e.Item Is RepeaterItem AndAlso e.Item.DataItem IsNot Nothing) Then
Dim dr as DataRow = e.Item.DataItem
Dim GroupID as Integer = If(IsDBNull(dr("GroupID")), -1, Integer.Parse(dr("GroupID").ToString()))
Dim GroupDate as DateTime = If(IsDBNull(dr("GroupDate")), DateTime.Today, DateTime.Parse(dr("GroupDate").ToString()))
Dim dt as DataTable = Model.GetSideBarItems(GroupID)
Dim LiteralHeader as Literal = e.Item.FindControl("LiteralHeader")
Dim RepeaterItems as Repeater = e.Item.FindControl("RepeaterItems")
If (LiteralHeader IsNot Nothing) Then LiteralHeader.Text = GroupDate.ToString("dd/mm/yyyy")
If (RepeaterItems IsNot Nothing) Then
RepeaterItems.DataSource = dt
RepeaterItems.DataBind()
End If
End If
End Sub
Protected Sub RepeaterItems_ItemDataBound(Sender As Object, e As RepeaterItemEventArgs)
' To-Do
End Sub

How to Create Hyperlink to Uploaded files to open the file

Hi Below is the code for Uploading Multiple files I cant display all the file names at a time it shows only one file name and how to create hyperlink to Uploaded documents to view the files.
Protected Sub Button1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs)
If FileUpload1.HasFile Then
Try
FileUpload1.SaveAs("Destinationpath\testing\\" & _
FileUpload1.FileName)
Label1.Text = "File name: " & _
FileUpload1.FileName & "<br>"
ListBox1.Items.Add(System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName))
Catch ex As Exception
Label1.Text = "ERROR: " & ex.Message.ToString()
End Try
Else
Label1.Text = "You have not specified a file."
End If
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs)
'Files.RemoveAt(ListBox1.SelectedIndex)
ListBox1.Items.Remove(ListBox1.SelectedItem.Text)
Label1.Text = "File removed"
End Sub
and below is the aspx code
<div>
<asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true"/><br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Upload Document" /><br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label></div>
<asp:listbox ID="ListBox1" runat="server" Width="175px"></asp:listbox>
<asp:Button ID="Button2" runat="server" Text="Remove" Width="98px" OnClick="Button2_Click" />
can anyone help me to do this. Thanks..
Use ListBox for this. It will be something like:
protected void UploadButton_Click(object sender, EventArgs e){
foreach (HttpPostedFile fl in fu.PostedFiles)
{
fl.SaveAs(DestinationPath + fl.FileName);
ListItem li = new ListItem();
li.Text = fl.FileName;
ListBox1.Items.Add(li);
}
}
In your design page:
<asp:Panel ID="pnlFiles" runat="server" />
Your code behind:
Protected Sub Button1_Click(ByVal sender As Object, _ByVal e As System.EventArgs)
For Each fl as HttpPostedFile in fu.PostedFiles
Dim fileLink as String = DestinationPath + fl.FileName
fl.SaveAs(fileLink)
Dim hpr as New HyperLink
hpr.Text = "Download file"
hpr.NavigateUrl = fileLink
pnlFiles.Controls.Add(hpr)
Next
End Sub

how to add Button Click Event in asp.net with vb

I have problem with onclick event. Here is an example which is similar to my project
HTML
<%# Page Language="VB" AutoEventWireup="true" CodeFile="Example.aspx.vb" Inherits="Example" %>
<html>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
<br />
<asp:Label ID="label1" runat="server" Text="Label"></asp:Label>
</form>
</body>
</html>
VB
Partial Class Example
Inherits System.Web.UI.Page
Dim No_of_Animals As Integer = 6 ' Number of Animals
Dim Cage(No_of_Animals) As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
label1.Text = " Animal released: " & Session.Item("AnimalReleased")
Cage(0) = "Cow"
Cage(1) = "Bat"
Cage(2) = "Dog"
Cage(3) = "Cat"
Cage(4) = "Snake"
Cage(5) = "Pig"
Dim html As New StringBuilder()
html.Append("<table>")
For Animal = 1 To No_of_Animals
html.Append("<tr><td>Cage " & Animal & " : </td>")
html.Append("<td> " & Cage(Animal - 1) & "</td>")
html.Append("<td><button runat=""server"" OnServerClick=""DisplayAnimal(" & Animal - 1 & ")"">Release</button></td></tr>")
Next
html.Append("</table>")
PlaceHolder1.Controls.Add(New Literal() With {.Text = html.ToString()})
End Sub
Public Sub DisplayAnimal(ByVal CageNo As Integer)
Session.Item("AnimalReleased") = Cage(CageNo)
End Sub
End Class
After I click a button the page will just refresh but session.item("AnimalRelease") was never given a value.
I'm suspecting onclick is not functioning well.
According to MSDN, the OnServerClick should be all lower case: "onserverclick".

VBA HTML Coding , Trying To copy Table

I'm trying to pull Table Data from a website after VBA has already opened and clicked Run on the website. But now having trouble trying to copy all the data over to a sheet. I've tried several different codes to try this posted below. Any help would be great.
Here is the code that I have so far .
Sub AHT()
Application.ScreenUpdating = False
Application.ScreenUpdating = True
Set appIE = CreateObject("InternetExplorer.Application")
sURL = "http://cctools/reporting/main.php?p=centeraht"
' Instructes the macro to open IE and navigate to sURL.
With appIE
.Navigate sURL
.Visible = True
Application.Wait Now + TimeValue("00:00:02")
Set HTMLDOC = .Document
End With
Application.Wait Now + TimeValue("00:00:02")
For Each Btninput In appIE.Document.getElementsByTagName("INPUT")
If Btninput.Value = "Run" Then
Btninput.Click
Exit For
End If
Next
End Sub
I have Tried difference Variations of
Set TDelements = appIE.Docuemnt.getElementsByTagName("TD").innerText
Sheet1.Cells.ClearContents
r = 0
For Each TDelement In TDelements
'Look for required TD elements - this check is specific to VBA Express forum - modify as required
If TDelement.className = "<>" Then
Sheet13.Range("A1").Offset(r, 0).Value = TDelement.innerText
r = r + 1
End If
Next
And this :
Sub Extract_TD_text()
Dim URL As String
Dim IE As InternetExplorer
Dim HTMLDOC As HTMLDocument
Dim TDelements As IHTMLElementCollection
Dim TDelement As HTMLTableCell
Dim r As Long
'Saved from www vbaexpress com/forum/forumdisplay.php?f=17
URL = "http://cctools/reporting/main.php?p=centeraht"
Set IE = New InternetExplorer
With IE
.Navigate URL
.Visible = True
'Wait for page to load
While .Busy Or .ReadyState <> READYSTATE_COMPLETE: DoEvents: Wend
Set HTMLDOC = .Document
End With
Application.Wait Now + TimeValue("00:00:02")
For Each Btninput In IE.Document.getElementsByTagName("INPUT")
If Btninput.Value = "Run" Then
Btninput.Click
Exit For
End If
Next
Set TDelements = appIE.Docuemnt.getElementsByTagName("TD").innerText
Sheet1.Cells.ClearContents
r = 0
For Each TDelement In TDelements
'Look for required TD elements - this check is specific to VBA Express forum - modify as required
If TDelement.className = "data xsmall" Then
Sheet13.Range("A1").Offset(r, 0).Value = TDelement.innerText
r = r + 1
End If
Next
But All with no luck. Here is the Source Code of the website after the vba code has already clicked RUn and Generated the Table
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Reporting</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<link rel="stylesheet" href="/inc/framework_style.css" type="text/css" />
<link rel="stylesheet" href="/inc/jquery-ui-1.8.16.custom.css" type="text/css" />
<script type="text/javascript" src="/inc/ajax.js"></script>
<script type="text/javascript" src="/inc/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="/inc/jquery-ui-1.8.16.custom.min.js"></script>
<link rel="stylesheet" href="inc/style.css" type="text/css" />
</head>
<body>
<div id="wrapper">
<div id="menu"><span class='menuheader'>Menu</span>:<br />
<a href='main.php?p=main'>Home</a><br />
<a href='main.php?p=lobscorecard'>LOB Scorecard</a><br />
<a href='main.php?p=vdn'>VDN Report</a><br />
<a href='main.php?p=centeraht'>UV T1 Center AHT Interval</a><br />
<a href='main.php?p=centerahtd'>UV T1 Center AHT Daily</a><br />
<a href='main.php?p=centert2aht'>UV T2 Center AHT Interval</a><br />
<a href='main.php?p=centerT2ahtd'>UV T2 Center AHT Daily</a><br />
<br />
</div>
<div id='fakeheader'></div>
<div id="main"> <script type='text/javascript'>
//<![CDATA[
document.title = 'Reporting - U-Verse T1 AHT Interval - Center Split';
$(document).ready(function(){
document.getElementById('subpagetitle').innerHTML='U-Verse T1 AHT Interval - Center Split';
});
//]]>
</script>
<form method='post' action=''><table class='data'><tr><th>Date</th><th>SubLOB</th><th class='t_custom' title='Comma separated list of agent skills' style='cursor:help; display: none;'>Skills</th></tr><tr><td><input type='text' size='8' id='date' name='date' value='2014-07-13' /></td><td><select name='sublob' onchange="if (this.value == 4) { $('.t_custom').show(); } else { $('.t_custom').hide(); }"><option value=''>All</option><option value='1'>IPDSLAM/CSI</option><option value='2'>Non IPDSLAM/CSI</option><option value='3'>New Blue</option><option value='4'>Custom</option></select></td><td class='t_custom' style='display: none;'><input type='text' name='skills' value='' /></td></tr><tr><th class='center' colspan='3'><input type='submit' value='Run' /></th></tr></table></form> <script type='text/javascript'>
//<![CDATA[
$('#date').datepicker({dateFormat: 'yy-mm-dd',minDate:'2010-05-26',maxDate:'2014-07-13',showOn:'button',buttonImageOnly: true, buttonImage: '/img/icon_pickdate.gif'});
//]]>
</script>
Running for 2014-07-12 22:00:00 to 2014-07-13 15:32:49<br/>
Skills Used: 330,325,334,329,331,332,327,328,336,323,361,351,352,353,354,355,357,358,359,356,348,371,375,368,379,347,385,337,338,339,341,343,344,177,176<br/>
<table class='data xsmall'>
<tr><th rowspan='2'>Int</th>
<th colspan='3' class='center'>ACD Calls</th>
<th colspan='3' class='center'>Avg ACD</th>
<th colspan='3' class='center'>Avg ACW</th>
<th colspan='3' class='center'>Avg Hold</th>
<th colspan='3' class='center'>AIHT</th>
<th colspan='3' class='center'>AOHT</th><th rowspan='2' class='center'>Forecast<br/>AHT</th><th colspan='3' class='center'>AIHT+AOHT</th></tr>
<tr><th>SAT</th><th>PHX</th><th>Combined</th><th>SAT</th><th>PHX</th><th>Combined</th>
<th>SAT</th><th>PHX</th><th>Combined</th><th>SAT</th><th>PHX</th><th>Combined</th>
<th>SAT</th><th>PHX</th><th>Combined</th><th>SAT</th><th>PHX</th><th>Combined</th>
<th>SAT</th><th>PHX</th><th>Combined</th></tr><tr><td>0000</td><td>5</td><td>13</td>
<td>18</td><td>7.993</td><td>5.533</td><td>6.217</td><td>1.013</td><td>0.536</td>
<td>0.669</td><td>1.360</td><td>0.460</td><td>0.710</td><td>10.367</td><td>6.529</td>
<td>7.595</td><td>0.000</td><td>0.117</td><td>0.084</td><td>0.000</td><td>10.367</td>
<td>6.646</td><td>7.680</td></tr><tr class='altrow'><td>0530</td><td>0</td><td>0</td>
<td>0</td><td>0.000</td><td>0.000</td><td>0.000</td><td>0.000</td><td>0.000</td>
<td>0.000</td><td>0.000</td><td>0.000</td><td>0.000</td><td>0.000</td><td>0.000</td>
<td>0.000</td><td>0.000</td><td>0.000</td><td>0.000</td><td>0.000</td><td>0.000</td>
<td>0.000</td><td>0.000</td></tr><tr><td>0600</td><td>11</td><td>0</td><td>11</td>
<td>22.050</td><td>0.000</td><td>22.050</td><td>2.126</td><td>0.000</td><td>2.126</td>
<td>0.956</td><td>0.000</td><td>0.956</td><td>25.132</td><td>0.000</td><td>25.132</td>
<td>0.000</td><td>0.000</td><td>0.000</td><td>13.825</td><td>25.132</td><td>0.000</td>
<td>25.132</td></tr><tr class='altrow'><td>0630</td><td>20</td><td>0</td><td>20</td>
<td>21.952</td><td>0.000</td><td>23.863</td><td>3.380</td><td>0.000</td><td>3.380</td>
<td>2.262</td><td>0.000</td><td>2.354</td><td>27.593</td><td>0.000</td><td>29.597</td><td>1.576</td><td>0.000</td><td>1.576</td><td>14.839</td><td>29.169</td><td>0.000</td><td>31.172</td></tr><tr><td>0700</td><td>42</td><td>12</td><td>54</td><td>17.212</td><td>7.740</td><td>15.107</td><td>1.444</td><td>0.368</td><td>1.205</td><td>2.442</td><td>0.826</td><td>2.083</td><td>21.099</td><td>8.935</td><td>18.396</td><td>0.561</td><td>0.171</td><td>0.474</td><td>15.983</td><td>21.660</td><td>9.106</td><td>18.870</td></tr><tr class='altrow'><td>0730</td><td>73</td><td>9</td><td>82</td><td>13.539</td><td>15.046</td><td>13.705</td><td>1.005</td><td>1.272</td><td>1.035</td><td>2.057</td><td>1.059</td><td>1.947</td><td>16.602</td><td>17.378</td><td>16.687</td><td>0.142</td><td>0.681</td><td>0.201</td><td>15.867</td><td>16.743</td><td>18.059</td><td>16.888</td></tr><tr><td>0800</td><td>86</td><td>20</td><td>106</td><td>12.600</td><td>15.325</td><td>13.114</td><td>1.924</td><td>0.767</td><td>1.705</td><td>1.237</td><td>1.394</td><td>1.267</td><td>15.761</td><td>17.486</td><td>16.086</td><td>0.715</td><td>0.014</td><td>0.582</td><td>15.250</td><td>16.475</td><td>17.500</td><td>16.669</td></tr><tr class='altrow'><td>0830</td><td>70</td><td>19</td><td>89</td><td>13.039</td><td>20.487</td><td>14.629</td><td>1.552</td><td>1.546</td><td>1.551</td><td>1.995</td><td>5.735</td><td>2.793</td><td>16.586</td><td>27.768</td><td>18.973</td><td>1.098</td><td>0.107</td><td>0.887</td><td>17.333</td><td>17.685</td><td>27.875</td><td>19.860</td></tr><tr><td>0900</td><td>79</td><td>33</td><td>112</td><td>11.347</td><td>17.452</td><td>13.146</td><td>1.410</td><td>1.835</td><td>1.536</td><td>1.438</td><td>5.544</td><td>2.648</td><td>14.195</td><td>24.831</td><td>17.329</td><td>0.624</td><td>1.274</td><td>0.815</td><td>17.065</td><td>14.819</td><td>26.105</td><td>18.144</td></tr><tr class='altrow'><td>0930</td><td>62</td><td>58</td><td>120</td><td>11.863</td><td>9.514</td><td>10.728</td><td>1.278</td><td>1.530</td><td>1.400</td><td>1.868</td><td>2.609</td><td>2.226</td><td>15.009</td><td>13.654</td><td>14.354</td><td>0.705</td><td>0.721</td><td>0.713</td><td>16.625</td><td>15.714</td><td>14.375</td><td>15.067</td></tr><tr><td>1000</td><td>73</td><td>39</td><td>112</td><td>12.805</td><td>13.308</td><td>12.980</td><td>1.366</td><td>1.086</td><td>1.269</td><td>1.723</td><td>2.753</td><td>2.081</td><td>15.893</td><td>17.147</td><td>16.330</td><td>0.360</td><td>0.753</td><td>0.497</td><td>17.275</td><td>16.253</td><td>17.900</td><td>16.827</td></tr><tr class='altrow'><td>1030</td><td>106</td><td>30</td><td>136</td><td>10.530</td><td>15.892</td><td>11.713</td><td>2.047</td><td>1.909</td><td>2.016</td><td>1.658</td><td>3.136</td><td>1.984</td><td>14.234</td><td>20.937</td><td>15.712</td><td>0.341</td><td>1.141</td><td>0.517</td><td>17.139</td><td>14.574</td><td>22.078</td><td>16.230</td></tr><tr><td>1100</td><td>98</td><td>44</td><td>142</td><td>9.911</td><td>14.486</td><td>11.329</td><td>1.027</td><td>0.799</td><td>0.956</td><td>0.888</td><td>2.059</td><td>1.251</td><td>11.825</td><td>17.344</td><td>13.535</td><td>0.630</td><td>0.203</td><td>0.498</td><td>16.017</td><td>12.455</td><td>17.547</td><td>14.033</td></tr><tr class='altrow'><td>1130</td><td>93</td><td>60</td><td>153</td><td>10.327</td><td>12.664</td><td>11.243</td><td>1.621</td><td>1.053</td><td>1.398</td><td>1.052</td><td>1.229</td><td>1.122</td><td>13.000</td><td>14.946</td><td>13.763</td><td>0.369</td><td>0.268</td><td>0.329</td><td>16.751</td><td>13.369</td><td>15.214</td><td>14.092</td></tr><tr><td>1200</td><td>107</td><td>61</td><td>168</td><td>11.503</td><td>13.919</td><td>12.380</td><td>1.101</td><td>0.948</td><td>1.046</td><td>1.538</td><td>1.524</td><td>1.533</td><td>14.143</td><td>16.391</td><td>14.959</td><td>0.851</td><td>0.526</td><td>0.733</td><td>15.800</td><td>14.994</td><td>16.917</td><td>15.692</td></tr><tr class='altrow'><td>1230</td><td>127</td><td>60</td><td>187</td><td>9.198</td><td>12.893</td><td>10.384</td><td>1.638</td><td>0.870</td><td>1.392</td><td>0.814</td><td>0.971</td><td>0.864</td><td>11.650</td><td>14.734</td><td>12.639</td><td>0.690</td><td>0.506</td><td>0.631</td><td>16.217</td><td>12.340</td><td>15.240</td><td>13.270</td></tr><tr><td>1300</td><td>105</td><td>50</td><td>155</td><td>11.266</td><td>13.160</td><td>11.877</td><td>1.067</td><td>0.825</td><td>0.989</td><td>0.603</td><td>0.668</td><td>0.624</td><td>12.936</td><td>14.653</td><td>13.490</td><td>0.917</td><td>1.330</td><td>1.050</td><td>16.271</td><td>13.853</td><td>15.983</td><td>14.540</td></tr><tr class='altrow'><td>1330</td><td>105</td><td>59</td><td>164</td><td>11.154</td><td>13.355</td><td>11.946</td><td>1.243</td><td>0.844</td><td>1.100</td><td>0.620</td><td>1.049</td><td>0.774</td><td>13.017</td><td>15.248</td><td>13.819</td><td>1.130</td><td>0.923</td><td>1.055</td><td>16.908</td><td>14.147</td><td>16.171</td><td>14.875</td></tr><tr><td>1400</td><td>95</td><td>50</td><td>145</td><td>15.041</td><td>19.103</td><td>16.441</td><td>1.443</td><td>1.386</td><td>1.423</td><td>1.683</td><td>1.796</td><td>1.722</td><td>18.166</td><td>22.285</td><td>19.586</td><td>0.926</td><td>0.472</td><td>0.770</td><td>17.075</td><td>19.093</td><td>22.757</td><td>20.356</td></tr><tr class='altrow'><td>1430</td><td>99</td><td>70</td><td>169</td><td>13.438</td><td>14.066</td><td>13.698</td><td>1.331</td><td>0.935</td><td>1.167</td><td>1.942</td><td>1.553</td><td>1.781</td><td>16.711</td><td>16.553</td><td>16.646</td><td>0.948</td><td>1.363</td><td>1.120</td><td>17.000</td><td>17.659</td><td>17.916</td><td>17.765</td></tr><tr><td>1500</td><td>84</td><td>78</td><td>162</td><td>14.921</td><td>13.699</td><td>14.333</td><td>1.390</td><td>1.162</td><td>1.280</td><td>1.872</td><td>1.295</td><td>1.594</td><td>18.183</td><td>16.156</td><td>17.207</td><td>1.286</td><td>0.859</td><td>1.080</td><td>17.575</td><td>19.469</td><td>17.015</td><td>18.287</td></tr><tr class='altrow'><td>1530</td><td>67</td><td>63</td><td>130</td><td>18.298</td><td>14.476</td><td>16.446</td><td>1.833</td><td>0.850</td><td>1.357</td><td>1.863</td><td>0.979</td><td>1.435</td><td>21.995</td><td>16.306</td><td>19.238</td><td>1.398</td><td>1.207</td><td>1.305</td><td>16.475</td><td>23.392</td><td>17.513</td><td>20.543</td></tr><tr><td>1600</td><td>74</td><td>61</td><td>135</td><td>17.055</td><td>18.697</td><td>17.797</td><td>2.100</td><td>1.473</td><td>1.817</td><td>1.655</td><td>2.616</td><td>2.089</td><td>20.810</td><td>22.786</td><td>21.703</td><td>0.823</td><td>0.807</td><td>0.816</td><td>16.850</td><td>21.634</td><td>23.593</td><td>22.519</td></tr><tr class='altrow'><td>1630</td><td>67</td><td>71</td><td>138</td><td>17.288</td><td>13.447</td><td>15.312</td><td>2.450</td><td>1.115</td><td>1.763</td><td>2.284</td><td>1.648</td><td>1.957</td><td>22.022</td><td>16.211</td><td>19.032</td><td>1.534</td><td>1.423</td><td>1.477</td><td>16.181</td><td>23.556</td><td>17.634</td><td>20.509</td></tr><tr><td>Total</td>
<td>1748</td><td>960</td><td>2708</td><td>12.846</td><td>14.207</td><td>13.329</td>
<td>1.521</td><td>1.108</td><td>1.375</td><td>1.478</td><td>1.821</td><td>1.600</td>
<td>15.846</td><td>17.137</td><td>16.303</td><td>0.799</td><td>0.813</td><td>0.804</td>
<td>16.622</td><td>16.644</td><td>17.950</td><td>17.107</td></tr>
</table><br/>
<a href='csvexport.php'>CSV Export</a><br/></div>
<div id="fakefooter"></div>
</div>
<div id="footer"><p><span class='copyright'>© 2014</span></p></div>
<div id="header"><div class='left'><img src='/img/pace_logo_smaller.gif' alt='Pace Logo' /></div><div class='right'><div style='float: right;'>User: [<a href='index.php?logout=1'>Logout</a>]<br />Access Level: User<br /></div></div><span class='subtitle' style='cursor:pointer;' onclick="document.location='main.php';">Reporting</span><br/><span id='subpagetitle'></span></div>
</body>
</html>
Was able to get the oode to work using the copy and paste it all. And use two more subs to clear out extra items not needed .
Global slogininfo As String
Global appIE As Object ' InternetExplorer.Application
Global sURL As String
Global sLogin As String
Global sNotes As String
Global ID As Object ' MSHTML.IHTMLElement
Global infraction As Object ' MSHTML.IHTMLElement
Global Element As Object ' HTMLButtonElement
Global Btninput As Object ' MSHTML.HTMLInputElement
Global ElementCol As Object ' MSHTML.IHTMLElementCollection
Sub AHT()
Application.ScreenUpdating = False
Application.ScreenUpdating = True
Set appIE = CreateObject("InternetExplorer.Application")
sURL = "http://cctools/reporting/main.php?p=centeraht"
' Instructes the macro to open IE and navigate to sURL.
With appIE
.Navigate sURL
.Visible = True
Application.Wait Now + TimeValue("00:00:02")
Set HTMLDOC = .Document
End With
Application.Wait Now + TimeValue("00:00:02")
For Each Btninput In appIE.Document.getElementsByTagName("INPUT")
If Btninput.Value = "Run" Then
Btninput.Click
Exit For
End If
Next
Application.Wait Now + TimeValue("00:00:2")
appIE.ExecWB OLECMDID_SELECTALL, OLECMDEXECOPT_DODEFAULT
appIE.ExecWB OLECMDID_COPY, OLECMDEXECOPT_DODEFAULT
appIE.Quit
Range("A1").Select
ActiveSheet.Paste
Call Cleanup
Call DeleteObj
End Sub
Sub Cleanup()
'
' Cleanup Macro
'
'
Rows("1:15").Select
Range("A15").Activate
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=-24
End Sub
Sub DeleteObj()
Dim obj As Object
For Each obj In ActiveSheet.Shapes
obj.Delete
Next
End Sub
Now with another site I had issues with the copy and paste method wasn't working. But the site has a CSV option to download the date i altered the code to capture that and paste it as such.
Sub Metrics()
Application.ScreenUpdating = False
Application.ScreenUpdating = True
Set appIE = CreateObject("InternetExplorer.Application")
sURL = "http://cctools/rportal/main.php?p=agentavaya"
' Instructes the macro to open IE and navigate to sURL.
With appIE
.Navigate sURL
.Visible = True
Application.Wait Now + TimeValue("00:00:02")
Set HTMLDOC = .Document
End With
Application.Wait Now + TimeValue("00:00:02")
For Each Btninput In appIE.Document.getElementsByTagName("INPUT")
If Btninput.Value = " Run " Then
Btninput.Click
Exit For
End If
Next
Application.Wait Now + TimeValue("00:00:04")
Call CSV
End Sub
Sub CSV()
sCSVLink = "http://cctools/rportal/csvexport.php"
sfile = "csvexport.php"
ssheet = "Sheet10"
Set wnd = ActiveWindow
Application.ScreenUpdating = False
Workbooks.Open Filename:=sCSVLink
Windows(sfile).Activate
ActiveSheet.Cells.Copy
wnd.Activate
Range("A1").Select
ActiveSheet.Paste
Application.DisplayAlerts = False
Windows(sfile).Close False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

Convert String into Div Object in vb.net/asp

I have a bit of a difficult problem which I can't seem to find out how to solve.
Basically, I have a couple tables on my database which, identify, by client, which divs IDs the client has access to, by using the tab
So I have a table which identifies the divs by their ID, by using the table index:
id | id_div
0 | D0
1 | D1
(and so on..)
And then another one which has only the clients ID and the divs (identified by the "id" field) he has access to:
client_id | div_id
29 | 0
29 | 1
(and so on..)
Then I'm cross referencing which divs should be visible and which should not.
The problem is I am getting the divs id as a string and in order to be able to tell in code-behind to set the visibility to false I need to reference the div in itself..
A sample:
<dx:TabPage Name="tabServico" Text="<%$ Resources:InterfaceGenerica, lblServico %>">
<ContentCollection>
<dx:ContentControl>
<div class="conteudo_pagina_tab">
<asp:HiddenField ID="hidID" runat="server" Value="0" EnableViewState="true" />
<asp:HiddenField ID="hidIdCliente" runat="server" Value="0" EnableViewState="true"/>
<div id="D0" runat="server">
<div class="cols coluna1">
<asp:Literal ID="litClientes" runat="server" Text="<%$ Resources:InterfaceGenerica, lblCliente %>"></asp:Literal>
</div>
<div class="cols coluna2-4">
<dx:ASPxComboBox ID="cboClientes" runat="server" HelpText="" ValueField="id_cliente" TextField="nome_completo" SelectedValue="" Width="100%" AutoPostBack="true"></dx:ASPxComboBox>
</div>
</div>
<clear></clear>
<div id="D1" runat="server">
<div class="cols coluna1">
<asp:Literal ID="litTipoOperacao" runat="server" Text="<%$ Resources:InterfaceGenerica, lblOperacao %>"></asp:Literal>
</div>
<div class="cols coluna2-4">
<dx:ASPxComboBox ID="cboTipoOperacao" runat="server" Width="100%" HelpText="" ValueField="id_operacoes" TextField="nome" SelectedValue="" AutoPostBack="true">
</dx:ASPxComboBox>
</div>
</div>
<clear></clear>
<div id="D2" runat="server">
<div class="cols coluna1">
<asp:Literal ID="litTipoServs" runat="server" Text="<%$ Resources:InterfaceGenerica, lblTipoServico %>"></asp:Literal>
</div>
<div class="cols coluna2-4">
<dx:ASPxComboBox ID="cboTipoServs" runat="server" HelpText="" ValueField="id_tipo_servs" TextField="nome" SelectedValue="" AutoPostBack="true" Width="100%"></dx:ASPxComboBox>
</div>
</div>
<div id="D3" runat="server">
<div class="cols coluna5">
<asp:Literal ID="litSubTipoServs" runat="server" Text="<%$ Resources:InterfaceGenerica, lblSubtipoServico %>"></asp:Literal>
</div>
<div class="cols coluna6-8">
<dx:ASPxComboBox ID="cboSubTipoServs" runat="server" HelpText="" ValueField="id_tipo_subtipos" TextField="nome" SelectedValue=""></dx:ASPxComboBox>
</div>
</div>
And in code behind I have:
Dim cross As New Hashtable()
Dim divsCliente() As String
Dim lstDivs As List(Of campos_agd_form)
lstDivs = campos_agd_form_mapper.CarregarDivs()
If lstDivs IsNot Nothing Then
For Each i In lstDivs
cross.Add(i.id, i.id_div)
Next
End If
Dim lstDivsCliente As List(Of clientes_campos_agd)
lstDivsCliente = clientes_campos_agd_mapper.CarregarCamposCliente(guser.id)
If lstDivsCliente IsNot Nothing Then
divsCliente = (lstDivsCliente.Item(0).id_campos_enum).Split(",")
End If
'Dim divsCliente() As Integer = Convert.ToInt32((lstDivsCliente.id_divs).Split(","))
For Each item In cross
For Each i In divsCliente
If item.Key = Convert.ToInt32(i) Then
Dim div As System.Web.UI.HtmlControls.HtmlGenericControl
div = TryCast(item.Value, System.Web.UI.HtmlControls.HtmlGenericControl)
div.Visible = False
End If
Next
Next
As I was already expecting I can't convert a string into a HtmlObject so what I need to do is to find an object by it's id (the string), without having to go through the parent-object (basically, search the whole document, like one would do with javascript with a getElementById)
How can this be accomplished?
The framework I'm using is .NET 4.0
I Recommend the following approach.
You need to know which information to show to each user, so you might want to store this in session for example (Global.asax):
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fetch from DB
Session("Rights") = {"MyID1", "MyID3"}
End Sub
Then create a base user control that checks from the session if it's id is in the list of the rights the user has. If not, the control will automatically hide it self:
Imports System.Linq
Public MustInherit Class MyBaseControl
Inherits System.Web.UI.UserControl
Private Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
If Page.IsPostBack Then Return
Dim rights As String() = CType(Session("Rights"), String())
If Not rights.Any((Function(s) s = Me.ID)) Then Me.Visible = False
End Sub
End Class
Then create x number of content controls that inherit from this base control. These controls can have totally different content, but consider making as few as possible, since your D0, D1 etc seem to have almost same content. So just customize the control to handle different texts and values:
Public Class MyControl1
Inherits MyBaseControl
End Class
Then on the page you will have as many of these controls as needed:
<div>
<uc1:MyControl1 ID="MyID1" runat="server" />
<uc2:MyControl2 ID="MyID2" runat="server" />
<uc3:MyControl3 ID="MyID3" runat="server" />
</div>
Hope this helps.
So, I ended up doing things a little differently.
Basically I'm using a ClientScriptManager, and constructing an array with the elements to hide. (Which is then passed to the client side).
So the function now looks like this:
Private Sub ManipulaFormCliente()
Dim cross As New Hashtable()
Dim divsCliente() As String = New String() {}
Dim aux() As String = New String() {}
Dim cs As ClientScriptManager = Page.ClientScript
Dim lstDivs As List(Of campos_agd_form)
lstDivs = campos_agd_form_mapper.CarregarDivs()
If lstDivs IsNot Nothing Then
For Each i In lstDivs
cross.Add(i.id, i.id_div)
Next
End If
Dim lstDivsCliente As List(Of clientes_campos_agd)
lstDivsCliente = clientes_campos_agd_mapper.CarregarCamposCliente(" id_cliente = " & Convert.ToInt32(hidIdCliente.Value))
If lstDivsCliente IsNot Nothing Then
If lstDivsCliente.Count <> 0 Then
divsCliente = (lstDivsCliente.Item(0).id_campos_enum).Split(",")
End If
End If
For Each item In cross
For Each i In divsCliente
If item.Key = Convert.ToInt32(i) Then
cs.RegisterArrayDeclaration("divsCliente", "'" & item.Value & "'")
End If
Next
Next
End Sub
Then, on the client side I made a function which runs once the window has loaded, and uses the array constructed on code-behind to apply a css "display: none" on the divs whose IDs get passed on the array.
The code is the following:
window.onload = function hideFields() {
if (divsCliente.length > 0) {
for (var i = 0; i < divsCliente.length; i++) {
document.getElementById(divsCliente[i]).style.display = 'none';
}
}
}
This implements the behaviour desired: Whenever there's a postback (and respective load) this function is run, hiding the required divs/fields.
As a final touch, I had to add the 'clientidmode = "static"' attribute to the divs, in order to get the getElementById() function to work properly (according to the data in the DB)
I hope this helps anyone in need of a similar solution.