Telerik winforms radgridview hierarchical data not showing correctly - vb.net

Good day,
I am using telerik radgridview hierarchical data in vb.net winforms vs2013.
I am getting this problem, I see correctly the first list in the radgridview and in the first gridviewtemplate, but I do not see a thing in the second gridviewtemplate. I am out of ideas, I post the code here to see if anyone can help me.
Private Function loaddt0() As Data.DataSet
Dim dt As New Data.DataSet
dt.Tables.Add("person")
dt.Tables("person").Columns.Add("personID")
dt.Tables("person").Columns.Add("personName")
For i As Integer = 1 To 3
Dim rw As Data.DataRow
rw = dt.Tables("person").NewRow
rw.Item("personID") = i
rw.Item("personName") = "person" & " - " & i.ToString
dt.Tables("person").Rows.Add(rw)
Next
Return dt
End Function
Private Function loaddt1() As Data.DataSet
Dim dt As New Data.DataSet
dt.Tables.Add("project")
dt.Tables("project").Columns.Add("projectID")
dt.Tables("project").Columns.Add("projectName")
dt.Tables("project").Columns.Add("personID")
dt.Tables("project").Columns.Add("personprojectID")
Dim rw As Data.DataRow
rw = dt.Tables("project").NewRow
rw.Item("projectID") = 1
rw.Item("projectName") = "Proyect 1"
rw.Item("personID") = 1
rw.Item("personprojectID") = "1-1"
dt.Tables("project").Rows.Add(rw)
Dim rw1 As Data.DataRow
rw1 = dt.Tables("project").NewRow
rw1.Item("projectID") = 2
rw1.Item("projectName") = "Proyect 2"
rw1.Item("personID") = 1
rw1.Item("personprojectID") = "1-2"
dt.Tables("project").Rows.Add(rw1)
Dim rw2 As Data.DataRow
rw2 = dt.Tables("project").NewRow
rw2.Item("projectID") = 1
rw2.Item("projectName") = "Proyect 1"
rw2.Item("personID") = 2
rw2.Item("personprojectID") = "2-1"
dt.Tables("project").Rows.Add(rw2)
Dim rw3 As Data.DataRow
rw3 = dt.Tables("project").NewRow
rw3.Item("projectID") = 1
rw3.Item("projectName") = "Proyect 1"
rw3.Item("personID") = 3
rw3.Item("personprojectID") = "3-1"
dt.Tables("project").Rows.Add(rw3)
Return dt
End Function
Private Function loaddt2() As Data.DataSet
Dim dt As New Data.DataSet
dt.Tables.Add("task")
dt.Tables("task").Columns.Add("personprojectID")
dt.Tables("task").Columns.Add("taskID")
dt.Tables("task").Columns.Add("taskName")
dt.Tables("task").Columns.Add("personID")
dt.Tables("task").Columns.Add("personprojecttaskID")
Dim rw As Data.DataRow
rw = dt.Tables("task").NewRow
rw.Item("personprojectID") = "1-1"
rw.Item("taskID") = 3
rw.Item("taskName") = "Task 3"
rw.Item("personID") = 1
rw.Item("personprojecttaskID") = "1-1-3"
dt.Tables("task").Rows.Add(rw)
Dim rw1 As Data.DataRow
rw1 = dt.Tables("task").NewRow
rw1.Item("personprojectID") = "1-1"
rw1.Item("taskID") = 5
rw1.Item("taskName") = "Task 5"
rw1.Item("personID") = 1
rw1.Item("personprojecttaskID") = "1-1-5"
dt.Tables("task").Rows.Add(rw1)
Dim rw2 As Data.DataRow
rw2 = dt.Tables("task").NewRow
rw2.Item("personprojectID") = "1-1"
rw2.Item("taskID") = 8
rw2.Item("taskName") = "Task 8"
rw2.Item("personID") = 1
rw2.Item("personprojecttaskID") = "1-1-8"
dt.Tables("task").Rows.Add(rw2)
Dim rw3 As Data.DataRow
rw3 = dt.Tables("task").NewRow
rw3.Item("personprojectID") = "1-2"
rw3.Item("taskID") = 6
rw3.Item("taskName") = "Task 6"
rw3.Item("personID") = 1
rw3.Item("personprojecttaskID") = "1-2-6"
dt.Tables("task").Rows.Add(rw3)
Dim rw4 As Data.DataRow
rw4 = dt.Tables("task").NewRow
rw4.Item("personprojectID") = "2-1"
rw4.Item("taskID") = 1
rw4.Item("taskName") = "Task 1"
rw4.Item("personID") = 1
rw4.Item("personprojecttaskID") = "2-1-1"
dt.Tables("task").Rows.Add(rw4)
Dim rw5 As Data.DataRow
rw5 = dt.Tables("task").NewRow
rw5.Item("personprojectID") = "3-1"
rw5.Item("taskID") = 8
rw5.Item("taskName") = "Task 8"
rw5.Item("personID") = 3
rw5.Item("personprojecttaskID") = "3-1-8"
dt.Tables("task").Rows.Add(rw5)
Return dt
End Function
Private Sub load2()
Dim ldt As Data.DataSet
ldt = loaddt0()
rgvtareas.DataSource = ldt.Tables("person").DefaultView
ldt.Dispose()
Dim gridviewtemple As New Telerik.WinControls.UI.GridViewTemplate
Dim ldt2 As Data.DataSet
ldt2 = loaddt1()
gridviewtemple.DataSource = ldt2.Tables("project").DefaultView
ldt2.Dispose()
Dim ldt3 As Data.DataSet
ldt3 = loaddt2()
Dim gridviewtemple2 As New Telerik.WinControls.UI.GridViewTemplate
gridviewtemple2.DataSource = ldt3.Tables("task").DefaultView
ldt3.Dispose()
rgvtareas.MasterTemplate.Templates.Add(gridviewtemple)
Dim relation As New Telerik.WinControls.UI.GridViewRelation(rgvtareas.MasterTemplate)
relation.ChildTemplate = gridviewtemple
relation.RelationName = "PERSONS - PROJECTS"
relation.ParentColumnNames.Add("personID")
relation.ChildColumnNames.Add("personID")
rgvtareas.Relations.Add(relation)
gridviewtemple.AllowAddNewRow = False
gridviewtemple.AllowDragToGroup = False
gridviewtemple.AllowDeleteRow = False
gridviewtemple.AllowEditRow = False
gridviewtemple.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill
'Me.cargaridiomagrv3(gridviewtemple2)
'Me.dgdarformatogvt(gridviewtemple)
gridviewtemple.Templates.Add(gridviewtemple2)
Dim relation2 As New Telerik.WinControls.UI.GridViewRelation(gridviewtemple)
relation2.ChildTemplate = gridviewtemple2
relation2.RelationName = "PERSONPROJECTS - TASKS"
relation2.ParentColumnNames.Add("personprojectID")
relation2.ChildColumnNames.Add("personprojectID")
gridviewtemple2.AllowAddNewRow = False
gridviewtemple2.AllowDragToGroup = False
gridviewtemple2.AllowDeleteRow = False
gridviewtemple2.AllowEditRow = False
gridviewtemple2.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill
rgvtareas.Refresh()
End Sub
The image of what I get is:

You've missed adding the second GridViewRelation to the Relations collection of the control. Just add this line at the bottom:
rgvtareas.Relations.Add(relation2)

Related

Speed up my function - Dynamic button creation vb.net

I have a function that creates button dynamically based on a database table, there are about 250 records inside. Everything is working properly but I'd like to make it faster but I don't know how.
Maybe it's due to the language I don't know.
Actually, on my development machine, it takes about 56 seconds to load. I'm not an experienced developper so maybe I'm missing something.
The problem is that on the client machine, that has only 4Go of RAM, the loading time is much bigger, 2.5 to 3.5 minutes.
Thans you for your help.
This is my code :
Public Sub LoadProducts()
Me.ProgressBar1.Value = 0
Me.ProgressBar1.Visible = True
Dim oSim As New SimFonction
Dim str As String = "SELECT * FROM produits ORDER BY ref;"
Dim oCmd As New MySqlCommand(str, oSim.ConnectDb)
Dim oData As New DataSet
Dim oAdapt As New MySqlDataAdapter With {
.SelectCommand = oCmd
}
oAdapt.Fill(oData)
oSim.conn.Close()
recCount = oData.Tables(0).Rows.Count
Dim btn(recCount) As Button
Dim x, y, j As Integer
oAdapt = Nothing
oCmd = Nothing
str = Nothing
Dim ref As String
x = 0
y = 0
Dim valeurIncr As Integer = 100 / recCount
valeurBar = 0
i = 0
For i = 0 To oData.Tables(0).Rows.Count - 1
If Me.ProgressBar1.Value >= 90 Then
Me.ProgressBar1.Value = 0
End If
If j = 5 Then
y += 90
j = 0
x = 0
End If
x += 90
btn(i) = New Button With {
.Parent = productPanel,
.Location = New Point(x, y),
.Height = 90,
.Width = 90,
.Font = New Font("Microsoft Sans Serif", 14, FontStyle.Bold),
.ForeColor = Color.Orange,
.UseVisualStyleBackColor = True,
.TextAlign = ContentAlignment.BottomCenter
}
ref = oData.Tables(0).Rows(i).Item("ref").ToString
If IsDBNull(oData.Tables(0).Rows(i).Item("photo")) Then
btn(i).Text = oData.Tables(0).Rows(i).Item("ref").ToString
btn(i).Tag = oData.Tables(0).Rows(i).Item("ref").ToString
btn(i).Name = "bt" & ref
Else
Dim photoP As New IO.MemoryStream(CType(oData.Tables(0).Rows(i).Item("photo"), Byte()))
btn(i).BackgroundImage = Image.FromStream(photoP)
btn(i).BackgroundImageLayout = ImageLayout.Stretch
btn(i).Tag = oData.Tables(0).Rows(i).Item("ref").ToString
btn(i).Text = oData.Tables(0).Rows(i).Item("ref").ToString
btn(i).Name = "bt" & ref
photoP = Nothing
End If
If oSim.CheckProduiEnStock(ref) = False Then
btn(i).Enabled = False
End If
AddHandler btn(i).Click, AddressOf ButtonClicked
j += 1
Me.ProgressBar1.Value += 1
btn(i) = Nothing
Next
Me.ProgressBar1.Visible = False
End Sub
You may use the following command:
At the beginning: Me.SuspendLayout() ,and
at the end: Me.ResumeLayout()

Vb.net export data to excel

I have a problem with the following code to export the data to excel with following button click Event:
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
ExportToExcel()
End Sub
here is the code
Private Sub ExportToExcel()
Dim ExcelApp As Object, ExcelBook As Object
Dim ExcelSheet As Object
Dim i As Integer
Dim j As Integer
Try
Me.DgView.DefaultCellStyle.ForeColor = Color.Navy
Me.DgView.RowsDefaultCellStyle.BackColor = Color.AliceBlue
Me.DgView.GridColor = Color.Blue
Me.DgView.BorderStyle = BorderStyle.Fixed3D
Me.DgView.RowHeadersBorderStyle = BorderStyle.Fixed3D
DgView.AutoGenerateColumns = False
Dim ReferColumn As New DataGridViewTextBoxColumn()
ReferColumn.DataPropertyName = "Refer_no"
ReferColumn.HeaderText = "ካሴት መ/ቁ"
ReferColumn.Width = 80
Dim TitleColumn As New DataGridViewTextBoxColumn()
TitleColumn.DataPropertyName = "Title"
TitleColumn.HeaderText = "ካሴት ርእስ"
TitleColumn.Width = 150
Dim GnrNmColumn As New DataGridViewTextBoxColumn()
GnrNmColumn.DataPropertyName = "Genre_Name"
GnrNmColumn.HeaderText = "የካሴት ዓይነት"
GnrNmColumn.Width = 100
Dim GrpNmColumn As New DataGridViewTextBoxColumn()
GrpNmColumn.DataPropertyName = "Group_Name"
GrpNmColumn.HeaderText = "የምድብ ስም"
GrpNmColumn.Width = 100
Dim ActColumn As New DataGridViewTextBoxColumn()
ActColumn.DataPropertyName = "Actors"
ActColumn.HeaderText = "ሪፖርተር"
ActColumn.Width = 150
Dim DirecColumn As New DataGridViewTextBoxColumn()
DirecColumn.DataPropertyName = "Director"
DirecColumn.HeaderText = "ኃላፊ"
DirecColumn.Width = 150
Dim LangColumn As New DataGridViewTextBoxColumn()
LangColumn.DataPropertyName = "Language"
LangColumn.HeaderText = "ቋንቋ"
LangColumn.Width = 150
Dim releasedateColumn As New DataGridViewTextBoxColumn()
LangColumn.DataPropertyName = "release_date"
LangColumn.HeaderText = "የተቀረፀበተት ቀነን"
LangColumn.Width = 150
Dim StatusColumn As New DataGridViewTextBoxColumn()
StatusColumn.DataPropertyName = "status"
StatusColumn.HeaderText = "ሁኔታ"
StatusColumn.Width = 80
Dim synopsisColumn As New DataGridViewTextBoxColumn()
synopsisColumn.DataPropertyName = "synopsis"
synopsisColumn.HeaderText = "የተቀረፀበተት ጉዳይ"
synopsisColumn.Width = 180
DgView.Columns.Add(ReferColumn)
DgView.Columns.Add(TitleColumn)
DgView.Columns.Add(GnrNmColumn)
DgView.Columns.Add(GrpNmColumn)
DgView.Columns.Add(ActColumn)
DgView.Columns.Add(DirecColumn)
DgView.Columns.Add(LangColumn)
DgView.Columns.Add(releasedateColumn)
DgView.Columns.Add(StatusColumn)
DgView.Columns.Add(synopsisColumn)
Dim columns As String() = {"Refer_No", "Title", "genre_name", "group_name", "Actors", "Director", "Language", "release_date", "Status", "synopsis"}
DVDModule.FillListWithoutParam(DVDList, columns, "usp_SelectDVDList", _
GetType(Entity.DVD))
FormatGridWithBothTableAndColumnStyles()
DgView.DataSource = DVDList
'create object of excel
ExcelApp = CreateObject("Excel.Application")
ExcelBook = ExcelApp.WorkBooks.Add
ExcelSheet = ExcelBook.WorkSheets(1)
With ExcelSheet
For Each column As DataGridViewColumn In DgView.Columns
.cells(1, column.Index + 1) = column.HeaderText
Next
For i = 1 To Me.DgView.RowCount
.cells(i + 1, 1) = Me.DgView.Rows(i - 1).Cells("Refer_no").Value
For j = 1 To DgView.Columns.Count - 1
.cells(i + 1, j + 1) = DgView.Rows(i - 1).Cells(j).Value
Next
Next
End With
ExcelApp.Visible = True
'
ExcelSheet = Nothing
ExcelBook = Nothing
ExcelApp = Nothing
I admit I didn't read all of your code. It's a mess and there's too much code for your question. It gives you some kind of error or what?
Anyway, if you just want to export a table showing some data, I suggest you to create a .csv file instead of using MS Excel. It's much more easier to code, faster during execution, and the output file is portable

BindingSource.Count always display as 1 unless it is not null VB.Net

I'm developing a program to keep stocks. I need to Update the stock of table if the ShoeID and Size are already excisting.Otherwise it should add a new row.
When I enter data, if the same shoeID and Size in previous record, it updates. But if I add the record after some records it creates a new record. Does not update the previous record.
Private Sub AddStockBtn_Click(sender As Object, e As EventArgs) Handles AddStockBtn.Click
Dim Size, Stock As Integer
Dim stock_check As String
Dim status As Boolean = False
stock_check = "Pending"
StockBindingSource.ResetBindings(True)
Try
Size = Integer.Parse(SizeTxt.Text)
Stock = Integer.Parse(StockTxt.Text)
Console.WriteLine(stock_check)
Catch ex As Exception
MessageBox.Show("Invalid Size or Stock")
End Try
If (StockBindingSource.Count = 0) Then
StockBindingSource.AddNew()
StockBindingSource.Current("No") = 1
StockBindingSource.Current("ShoeID") = IDBox.Text
For i As Integer = 0 To ShoeDataBindingSource.Count - 1
Dim rowData As DataRowView = ShoeDataBindingSource.Item(i)
If rowData("ShoeID").ToString = IDBox.Text Then
StockBindingSource.Current("ShoeType") = ShoeDataBindingSource.Current("Type")
StockBindingSource.Current("Description") = ShoeDataBindingSource.Current("Name")
End If
Next
StockBindingSource.Current("Size") = Size
StockBindingSource.Current("Stock") = Stock
StockBindingSource.EndEdit()
TableAdapterManager.UpdateAll(SilexDatabaseDataSet)
Else
For i As Integer = 0 To ShoeDataBindingSource.Count - 1
Dim rowName As DataRowView = ShoeDataBindingSource.Item(i)
If rowName("ShoeID").ToString = IDBox.Text And StockBindingSource.Current("Size") = Size Then
StockBindingSource.Current("Stock") = StockBindingSource.Current("Stock") + Stock
StockBindingSource.EndEdit()
TableAdapterManager.UpdateAll(SilexDatabaseDataSet)
status = True
End If
Console.WriteLine(ShoeDataBindingSource.Count)
stock_check = "Loop"
Next
If (Not status And stock_check = "Loop") Then
Dim no As Integer
no = StockBindingSource.Count + 1
StockBindingSource.AddNew()
StockBindingSource.Current("No") = no
StockBindingSource.Current("ShoeID") = IDBox.Text
For i As Integer = 0 To ShoeDataBindingSource.Count - 1
Dim rowData As DataRowView = ShoeDataBindingSource.Item(i)
If rowData("ShoeID").ToString = IDBox.Text Then
StockBindingSource.Current("ShoeType") = ShoeDataBindingSource.Current("Type")
StockBindingSource.Current("Description") = ShoeDataBindingSource.Current("Name")
End If
Next
StockBindingSource.Current("Size") = Size
StockBindingSource.Current("Stock") = Stock
StockBindingSource.EndEdit()
TableAdapterManager.UpdateAll(SilexDatabaseDataSet)
End If
End If
End Sub
I enter my data First time
Updated same data
Add an another data and added the same data again,
New Data Updates here
Hope you understood the problem. Somebody help please.
StockBindingSource.count does not update. It always shows as 1, unless it is null.
See my comment above in regards to my attempt to post this code into a comment.
Dim ShoeId As Integer = 1
Dim ShoeSize As Integer = 15
Dim Stock As Integer = 1
Dim thisRow As DataRow = Nothing
Dim dt As New DataTable
dt.Columns.Add(New DataColumn With
{
.ColumnName = "Id",
.DataType = GetType(Integer),
.AutoIncrement = True,
.AutoIncrementSeed = 1
})
dt.Columns.Add(New DataColumn With
{
.ColumnName = "ShoeId",
.DataType = GetType(Integer),
.AutoIncrement = True
})
dt.Columns.Add(New DataColumn With
{
.ColumnName = "Size",
.DataType = GetType(Integer)
})
dt.Columns.Add(New DataColumn With
{
.ColumnName = "ShoeType",
.DataType = GetType(String)
})
dt.Columns.Add(New DataColumn With
{
.ColumnName = "Stock",
.DataType = GetType(Integer)
})
dt.Rows.Add(New Object() {Nothing, 1, 15, "Shoe", 5})
bs.DataSource = dt
thisRow =
(
From t In CType(bs.DataSource, DataTable).AsEnumerable
Where t.Field(Of Integer)("ShoeId") = ShoeId AndAlso t.Field(Of Integer)("Size") = ShoeSize
Select t).FirstOrDefault
If thisRow IsNot Nothing Then
thisRow.SetField(Of Integer)("Stock", thisRow.Field(Of Integer)("Stock") + 1)
Else
' add
End If
ShoeId = 2
ShoeSize = 15
thisRow =
(
From t In CType(bs.DataSource, DataTable).AsEnumerable
Where t.Field(Of Integer)("ShoeId") = ShoeId AndAlso t.Field(Of Integer)("Size") = ShoeSize
Select t).FirstOrDefault
If thisRow IsNot Nothing Then
thisRow.SetField(Of Integer)("Stock", thisRow.Field(Of Integer)("Stock") + 1)
Else
CType(bs.DataSource, DataTable).Rows.Add(New Object() {Nothing, ShoeId, ShoeSize, "Shoe", 5})
End If
ShoeId = 1
ShoeSize = 15
thisRow =
(
From t In CType(bs.DataSource, DataTable).AsEnumerable
Where t.Field(Of Integer)("ShoeId") = ShoeId AndAlso t.Field(Of Integer)("Size") = ShoeSize
Select t).FirstOrDefault
If thisRow IsNot Nothing Then
thisRow.SetField(Of Integer)("Stock", thisRow.Field(Of Integer)("Stock") + 1)
Else
CType(bs.DataSource, DataTable).Rows.Add(New Object() {Nothing, ShoeId, ShoeSize, "Shoe", 5})
End If
Finally I found an easy way to complete the task. Thanks Karen for help.
For Each row As DataGridViewRow In StockDataGrid.Rows
Dim tempID As String = row.Cells(1).Value
Dim tempSize As String = row.Cells(3).Value
If tempID = IDBox.Text And tempSize = Size Then
StockBindingSource.Position = count
StockBindingSource.Current("Stock") = StockBindingSource.Current("Stock") + Stock
StockBindingSource.EndEdit()
TableAdapterManager.UpdateAll(SilexDatabaseDataSet)
status = True
End If
count = count + 1
Next
This way, I could solve my problem. I used a datagridview.

dynamic table and button creation in asp.net

I have created a dynamic table using for loop condition.In which it has a button while i click a specific button it should open a file.But in my coding it is opening a file button in the last row.
If Not IsPostBack Then
txtlogsdate.Text = FormatDate(Now)
End If
Try
trViewlogs.Visible = True
lbllogs.Visible = False
lbllogname.Visible = True
RT1.Visible = False
pb.Visible = False
Dim d1 As DateTime = txtlogsdate.Text
Dim dd As String = d1.ToString("dd")
Dim mm As String = d1.ToString("MM")
Dim yy As String = d1.ToString("yy")
Dim d2 As String = yy & "" & mm & "" & dd
Dim di As DirectoryInfo = New DirectoryInfo(Server.MapPath("~\logs"))
Dim files As FileInfo() = di.GetFiles("*.log")
Dim tab As New Table()
tab.CellPadding = 0
tab.CellSpacing = 0
tab.BorderStyle = BorderStyle.Double
tab.Attributes.Add("style", "margin-left: 0.5px; width: 800px;")
Dim row As New TableRow()
Dim headerCell1 As New TableHeaderCell()
headerCell1.Text = "Logs"
headerCell1.Attributes.Add("style", "margin-left: 0.5px; height: 20px;")
headerCell1.BackColor = System.Drawing.Color.CornflowerBlue
headerCell1.ForeColor = System.Drawing.Color.White
row.Controls.Add(headerCell1)
tab.Controls.Add(row)
Dim headerCell2 = New TableHeaderCell()
headerCell2.Attributes.Add("style", "margin-left: 0.5px; height: 20px;")
headerCell2.BackColor = System.Drawing.Color.CornflowerBlue
headerCell2.ForeColor = System.Drawing.Color.White
headerCell2.Text = "Download"
row.Controls.Add(headerCell2)
tab.Controls.Add(row)
For i As Integer = 0 To files.Length - 1
Dim a As String = files(i).ToString.Replace("Event-", "")
Dim c As String = a.Substring(0, 6)
Dim sw As String
If d2 = c Then
sw = My.Computer.FileSystem.ReadAllText(_
GetWebSitePhysicalRoot & "\logs\" & files(i).ToString)
lbllogname.Text = files(i).ToString
lbllogname.Visible = False
row = New TableRow()
If i Mod 2 = 0 Then
row.BackColor = System.Drawing.Color.White
Else
row.BackColor = System.Drawing.Color.AliceBlue
End If
Dim cell As New TableCell()
cell.Text = lbllogname.Text
'cell.Width = New Unit("1000px")
cell.HorizontalAlign = HorizontalAlign.Center
row.Controls.Add(cell)
Dim cell2 As New TableCell()
Dim bt As New Button
bt.BorderStyle = BorderStyle.Solid
bt.Text = files(i).ToString
AddHandler bt.Click, AddressOf bt_Click
cell2.HorizontalAlign = HorizontalAlign.Center
cell2.Controls.Add(bt)
row.Controls.Add(cell2)
tab.Controls.Add(row)
Panel1.Controls.Add(tab)
End If
Next i
If lbllogname.Text = "" Then
lbllogname.Text = "No Logs to Display !"
End If
Session("pageurl") = ""
Session("pagecount") = ""
ib.SetInfo("Reports > View Logs", Infobar.InfoTypes.Caption)
Dim mi As Integer = GetQueryStringToInt("menuindex", 1)
If Not IsPostBack Then
leftmenu1.AddItem("View Logs", _
GetWebSiteUrlRoot & "/staff_rpt.aspx?rpt=logs&page=1&menuindex=" & mi)
End If
Catch ex As Exception
WriteLog(LogWriter.EventType.eError, ex.StackTrace.ToString)
End Try
Protected Sub bt_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs
Dim a As String
a = lbllogname.Text
Response.ContentType = "text/plain"
Response.AppendHeader("Content-Disposition", "attachment; filename=" & a)
Response.TransmitFile(Server.MapPath("~/logs/" & a))
Response.End()
End Sub
To use the dynamic table structure you have built in your code, then you need to uniquely name each button in each row; otherwise the button click handler (bt_Click) cannot figure out the correct row to open the file in, because they are all called the same and will use the last one.
Since you want a table structure, then I suggest you use the GridView server control, as it will provide similar output, but provide the ability to use templating to name the controls of each row the same, but allow for you to differentiate individual rows when a click event happens.

Add a Parameter Value in SSRS

I have a report already setup on the ReportServer. And its subscription as well. What I'm trying to do is add the ParameterValue "CC" and some email addresses then send the email out. It doesn't seem to work.
My code:
Dim emailReader As SqlDataReader = selCount.ExecuteReader
Dim emailsTest As List(Of String) = New List(Of String)
emailsTest.Add("test1#pen.com")
emailsTest.Add("test2#pen.com")
emailsTest.Add("test3#pen.com")
emailsTest.Add("test4#pen.com")
If emailReader.HasRows() Then 'checks to see if there any quotes in query
For Each subscrp As rs.Subscription In subscr
Dim allValues = subscrp.DeliverySettings.ParameterValues
Dim allValuesList As List(Of ReportTriggerTemplate1.rs.ParameterValueOrFieldReference) = allValues.ToList()
Dim CCParameter As ReportTriggerTemplate1.rs.ParameterValue = New ReportTriggerTemplate1.rs.ParameterValue()
CCParameter.Name = "CC"
CCParameter.Value = String.Empty
allValuesList.Add(CCParameter)
Dim toValue = CType(allValuesList.Item(7), ReportTriggerTemplate1.rs.ParameterValue)
For Each testEmail As String In emailsTest
Dim ownerEmail As String = testEmail
If toValue.Value.Contains(ownerEmail) Then
'skip
ElseIf toValue.Value = String.Empty Then
toValue.Value += ownerEmail
Else
toValue.Value += "; " & ownerEmail
End If
Next
subscrp.DeliverySettings.ParameterValues = allValuesList.ToArray()
Dim hello As String = "hi"
tr.FireEvent(EventType, subscrp.SubscriptionID) 'forces subscription to be sent
Next
What I'm adding to toValue.Value doesn't seem to be adding to the report's CC subscription field at all. So what am I missing?
http://msdn.microsoft.com/en-us/library/ms154020%28v=SQL.100%29.aspx
http://msdn.microsoft.com/en-us/library/reportservice2005.reportingservice2005.getsubscriptionproperties.aspx
http://msdn.microsoft.com/en-us/library/reportservice2005.reportingservice2005.setsubscriptionproperties%28v=SQL.105%29.aspx
Try
tr = New rs.ReportingService2005
Dim extSettings As ExtensionSettings = Nothing
Dim desc As String = Nothing
Dim active As ActiveState = Nothing
Dim status As String = Nothing
Dim matchData As String = Nothing
Dim values As ParameterValue() = Nothing
Dim extensionParams As ParameterValueOrFieldReference() = Nothing
Dim mainLogin As System.Net.NetworkCredential = New System.Net.NetworkCredential("ADUser", "Password", "NetworkName")
If mainLogin Is Nothing Then
tr.Credentials = System.Net.CredentialCache.DefaultCredentials
Else
tr.Credentials = mainLogin
End If
'skip to relevant code
For Each subscrp As rs.Subscription In subscr
Dim allValues = subscrp.DeliverySettings.ParameterValues
Dim allValuesList As List(Of ReportTriggerTemplate1.rs.ParameterValueOrFieldReference) = allValues.ToList()
If CType(allValuesList.Item(0), ReportTriggerTemplate1.rs.ParameterValue).Value = "test#pen.com" Then
Dim subsID = subscrp.SubscriptionID
'important code just below
tr.GetSubscriptionProperties(subsID, extSettings, desc, active, status, EventType, matchData, extensionParams)
''''add change to CC here
Dim extSettingsList As List(Of ReportTriggerTemplate1.rs.ParameterValueOrFieldReference) = extSettings.ParameterValues.ToList()
If CType(extSettingsList.Item(1), ReportTriggerTemplate1.rs.ParameterValue).Name = "CC" Then
If CType(extSettingsList.Item(1), ReportTriggerTemplate1.rs.ParameterValue).Value = String.Empty Then
CType(extSettingsList.Item(1), ReportTriggerTemplate1.rs.ParameterValue).Value = emailsTest.Item(0) & ";" & emailsTest.Item(1)
Else
CType(extSettingsList.Item(1), ReportTriggerTemplate1.rs.ParameterValue).Value += ";" & emailsTest.Item(0) & ";" & emailsTest.Item(1)
End If
Else
Dim CCParameter As ReportTriggerTemplate1.rs.ParameterValue = New ReportTriggerTemplate1.rs.ParameterValue()
CCParameter.Name = "CC"
CCParameter.Value = emailsTest.Item(0) & ";" & emailsTest.Item(1)
extSettingsList.Insert(1, CCParameter)
extSettings.ParameterValues = extSettingsList.ToArray
End If
'important code just below
tr.SetSubscriptionProperties(subsID, extSettings, desc, EventType, matchData, extensionParams)
tr.FireEvent(EventType, subscrp.SubscriptionID) 'forces subscription to be sent
Else
End If
Next