I'm using Devexpress Xtragrid TileView module.
Basically I want my code works like this :
user input member ID on the upper left textbox and press load.
If they exists, then a Tile will be appeared.
A tile should contain : Name, Status, member ID and a photo.
If user press load again (either same ID or another ID) a Tile will be added also, and so on. Unless they press Clear & Load, It should be only 1 latest tile left.
So, I'm able to produce up to Step 3.
But I couldn't be able to load the picture.
The picture itself, It's not a byte array. It's a Image path.
e.q : D:/test/1.jpg
So, how do I load the picture?
Protected Overridable Sub InitData()
Try
Dim homesTable = ds.Tables(0)
homesTable.Columns.Add("ImageCol")
For Each row_Renamed As DataRow In homesTable.Rows
Dim img As Image = Image.FromFile(row_Renamed("memberPhoto")) 'I tried this, but didn't work
row_Renamed("ImageCol") = img
Next row_Renamed
GridControl1.DataSource = homesTable
Catch
End Try
End Sub
Private Sub setupTile()
'For i = 0 To j - 1
Try
TileView1.BeginUpdate()
'TileView1.DataSource = ds.Tables(0)
TileView1.OptionsTiles.RowCount = 3
TileView1.OptionsTiles.Padding = New Padding(20)
TileView1.OptionsTiles.ItemPadding = New Padding(10)
TileView1.OptionsTiles.IndentBetweenItems = 20
TileView1.OptionsTiles.ItemSize = New Size(320, 170)
TileView1.Appearance.ItemNormal.ForeColor = Color.White
TileView1.Appearance.ItemNormal.BorderColor = Color.Transparent
'Setup tiles template
Dim leftPanel As New TileViewItemElement()
Dim splitLine As New TileViewItemElement()
Dim nameCaption As New TileViewItemElement()
Dim nameValue As New TileViewItemElement()
Dim statusCaption As New TileViewItemElement()
Dim statusValue As New TileViewItemElement()
Dim RGPCaption As New TileViewItemElement()
Dim RGPvalue As New TileViewItemElement()
Dim imageTile As New TileViewItemElement()
TileView1.TileTemplate.Add(leftPanel)
TileView1.TileTemplate.Add(splitLine)
TileView1.TileTemplate.Add(nameCaption)
TileView1.TileTemplate.Add(nameValue)
TileView1.TileTemplate.Add(statusCaption)
TileView1.TileTemplate.Add(statusValue)
TileView1.TileTemplate.Add(RGPCaption)
TileView1.TileTemplate.Add(RGPvalue)
TileView1.TileTemplate.Add(imageTile)
'
'nameValue.Text = ""
'statusValue.Text = ""
'RGPvalue.Text = ""
'imageTile.Image = Nothing
'
leftPanel.StretchVertical = True
leftPanel.Width = 190
leftPanel.TextLocation = New Point(-10, 0)
leftPanel.Appearance.Normal.BackColor = Color.FromArgb(58, 166, 101)
'
splitLine.StretchVertical = True
splitLine.Width = 3
splitLine.TextAlignment = TileItemContentAlignment.Manual
splitLine.TextLocation = New Point(190, 0)
splitLine.Appearance.Normal.BackColor = Color.White
'
nameCaption.Text = "Name"
nameCaption.TextAlignment = TileItemContentAlignment.TopLeft
nameCaption.Appearance.Normal.FontSizeDelta = -1
'
nameValue.Column = TileView1.Columns("preferredName")
nameValue.AnchorElement = nameCaption
nameValue.AnchorIndent = 2
nameValue.MaxWidth = 200
nameValue.Appearance.Normal.FontStyleDelta = FontStyle.Bold
'nameValue.Text = ds.Tables(0).Rows(i)("preferredName").ToString
'
statusCaption.Text = "Status"
statusCaption.AnchorElement = nameValue
statusCaption.AnchorIndent = 14
statusCaption.Appearance.Normal.FontSizeDelta = -1
'
statusValue.Column = TileView1.Columns("memberStatus")
statusValue.AnchorElement = statusCaption
statusValue.AnchorIndent = 2
statusValue.Appearance.Normal.FontStyleDelta = FontStyle.Bold
'statusValue.Text = ds.Tables(0).Rows(i)("memberStatus").ToString
'
RGPCaption.Text = "RGP"
RGPCaption.AnchorElement = nameValue
RGPCaption.AnchorIndent = 65
'RGPCaption.TextLocation
'RGPCaption.Appearance.Normal.FontSizeDelta = -1
RGPCaption.Appearance.Normal.Font = New Font("Segoe UI Semibold", 12.0F, System.Drawing.FontStyle.Regular)
'
RGPvalue.Column = TileView1.Columns("code")
RGPvalue.AnchorElement = RGPCaption
RGPvalue.AnchorIndent = 1
RGPvalue.TextAlignment = TileItemContentAlignment.BottomLeft
RGPvalue.Appearance.Normal.Font = New Font("Segoe UI Semilight", 25.75F, System.Drawing.FontStyle.Regular)
'RGPvalue.Text = ds.Tables(0).Rows(i)("code").ToString
'
imageTile.Column = TileView1.Columns("ImageCol")
imageTile.ImageSize = New Size(120, 170)
imageTile.ImageAlignment = TileItemContentAlignment.MiddleRight
imageTile.ImageScaleMode = TileItemImageScaleMode.Stretch
imageTile.ImageLocation = New Point(12, 0)
Catch ex As Exception
XtraMessageBox.Show(ex.Message)
Finally
TileView1.EndUpdate()
End Try
'Next
End Sub
Private Sub loadBtn_Click(sender As Object, e As EventArgs) Handles loadBtn.Click
initData()
setupTile()
End Sub
Maybe it's too late but in my case only need to read file from disk and assign to a byte() column.
First of all, table column should be byte array so replace:
homesTable.Columns.Add("ImageCol")
for:
homesTable.Columns.Add(New DataColumn("ImageCol", GetType(Byte)))
Then I'd try to replace:
row_Renamed("ImageCol") = img
for:
row_Renamed("ImageCol") = IO.File.ReadAllBytes(row_Renamed("memberPhoto"))
That would load disk file to byte array and shown in tile. I'd check if file exists to avoid exceptions.
That's what I do to load image from disk.
Hope it helps.
Related
I am creating an ASP.Net website with VB.Net as code behind and this is the error that appears from the published version on a web server (this does not appear when run directly from the code or from the published version on the IIS server):
error message screenshot
This is a snippet from the controller:
Function Index(ByVal pSurveyName As String) As ActionResult
Try
If IsNothing(pSurveyName) Then
Return New HttpStatusCodeResult(HttpStatusCode.BadRequest)
End If
Dim l_question As Object = GetQuestion()
Return View(l_question)
Catch ex As Exception
Call ExceptionHandler(ex)
Return View()
End Try
End Function
Function GetQuestion() As Object
Dim l_questionnaire = Session("ActiveQuestionnaire")
Dim l_surveySession = Session("SurveySession")
Dim l_redirectQueue = Session("RedirectQueue")
Dim l_sessionAnswers = Session("SessionAnswers")
Dim l_CurrentQuestion As CurrentItem = New CurrentItem
Dim l_Choices As List(Of Choice) = New List(Of Choice)
Dim l_TempDBQuestions = db.Questions
Dim l_TempDBChildQuestions = db.ChildQuestions
Dim l_TempDBChoices = db.Choices
Dim l_tempFiltered_Q
Dim li_questionnaireID As Integer
Dim li_questionCtr As Integer
Dim li_total_NoOfQuestion As Integer = 0
Dim li_resultCount As Integer = 0
Dim li_childQID As Integer = 0
Dim ls_prevAnswer As String = ""
Dim ls_err As String = ""
Try
li_questionnaireID = l_questionnaire.ID
li_questionCtr = l_surveySession.QuestionCtr
If Session("Back") = False Then
li_questionCtr = GetQuestionCtr(NEXT_QUESTION, l_surveySession, l_redirectQueue, l_sessionAnswers,, ls_prevAnswer)
Else
Dim l_current = Session("CurrentQuestion")
li_questionCtr = GetQuestionCtr(PREVIOUS_QUESTION, l_surveySession, l_redirectQueue, l_sessionAnswers, l_current, ls_prevAnswer)
End If
l_tempFiltered_Q = l_TempDBQuestions.Where(Function(q) q.QuestionnaireID.Equals(li_questionnaireID) And q.QuestionOrder.Equals(li_questionCtr))
li_resultCount = l_TempDBQuestions.Where(Function(q) q.QuestionnaireID.Equals(li_questionnaireID) And q.QuestionOrder.Equals(li_questionCtr)).Count
If li_resultCount = 0 Then
l_tempFiltered_Q = l_TempDBChildQuestions.Where(Function(q) q.QuestionnaireID.Equals(li_questionnaireID) And q.QuestionOrder.Equals(li_questionCtr))
Session("FrmChildQuestions") = True
Else
Session("FrmChildQuestions") = False
End If
For Each item In l_tempFiltered_Q
'item could be from Questions or ChildQuestions
If li_resultCount = 0 Then
Session("IsNextQuestionChild") = item.IsNextQuestionChild
End If
With l_CurrentQuestion
.ID = item.ID
.QuestionnaireID = item.QuestionnaireID
.QuestionOrder = item.QuestionOrder
.Description = item.Description
.AnswerType = item.AnswerType
.AllowMultipleAnswers = item.AllowMultipleAnswers
.QuestionNo = item.QuestionNo
.Required = item.Required
.TempAnswer = ls_prevAnswer
End With
Next
If l_CurrentQuestion.AnswerType = constants.MULTIPLE_CHOICE Then
'Get Choices
Dim li_questionID As Integer = l_CurrentQuestion.ID
If li_resultCount = 0 Then
l_Choices = db.Choices.SqlQuery("select * from Choices where ChildQuestionID = " & li_questionID & "").ToList
Else
l_Choices = db.Choices.SqlQuery("select * from Choices where QuestionID = " & li_questionID & "").ToList
End If
Session("Choices") = l_Choices
End If
If Session("TotalQuestions") Is Nothing Then
li_total_NoOfQuestion = db.Database.SqlQuery(Of Integer) _
("select max(a.MaxOrder) from(select max(QuestionOrder) " &
"as MaxOrder from Questions union select QuestionOrder from " &
"ChildQuestions)a").FirstOrDefault
Session("TotalQuestions") = li_total_NoOfQuestion
End If
With l_surveySession
.QuestionCtr = li_questionCtr
End With
Session("SurveySession") = l_surveySession
Session("CurrentQuestion") = l_CurrentQuestion
Session("Back") = False
Return l_CurrentQuestion
Catch ex As Exception
Call ExceptionHandler(ex)
End Try
End Function
And this is from the view:
#ModelType Survey_App.Models.CurrentItem
#Code
ViewData("Title") = "Index"
Layout = "~/Views/Shared/_Layout.vbhtml"
Dim l_choices = Session("Choices")
Dim l_activeSurvey = Session("ActiveSurvey")
Dim ls_tempAnsType As String = Model.AnswerType.ToString 'this is the line indicated in the error msg
Dim ls_temp As String = ""
Dim ls_tempAnswer() As String = Nothing
Dim li_totalQuestions As Integer = 0
li_totalQuestions = Session("TotalQuestions")
Dim ls_POSTAction As String = vbNullString
The error appears some time (maybe 10-15 seconds) after going through the home page but not always immediately. I also tried some debugging and it looks like the session variables also return nothing after that some time.
I am dynamically adding asp check boxes to my page based off of number of rows in my db table, by ID. Also the checkbox is being assigned an ID from the db table. I also two columns in my db table "numberOffered" and "numberAllowed". My idea is on page load only allow the user to check say 3 of the 10 check boxes shown. I have removed a lot of the code I thought would be unnecessary. Thank you very much in advance.
For Each Arow As Object In ATable.Rows
For Each Brow As Object In BTable.Rows
If Brow(1) = a_ID Then
If Brow(2) = b_ID Then
Dim cbShown As Integer = Arow(5)
Dim cbAllowed As Integer = Arow(6)
Dim checkBox As New CheckBox()
End If
End If
Next
Next
checkBox.ID = Crow(0)
divcontrol.Controls.Add(checkBox)
EDIT:
Full Page_load sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not (Session("studentLoggedIn") Or Session("adminLoggedIn")) Then
Routines.LogOut()
End If
If Session("adminLoggedIn") = True Then
castVote.Enabled = False
castVote.CssClass = "btnDisabled"
Dim p As New HtmlGenericControl()
p.TagName = "p"
p.InnerText = "Vote button disabled. Only students may vote."
adminMsg.Controls.Add(p)
End If
Dim ballot_ID As Integer = CType(Session.Item("ballot_ID"), Integer)
Dim ballotName As String = CType(Session.Item("ballotName"), String)
Dim ballotsAdapter As New eVoteTableAdapters.ballotsTableAdapter()
Dim ballotsTable As New eVote.ballotsDataTable
ballotsTable = ballotsAdapter.GetDataBy3getBallotsByID(ballot_ID)
Dim sectionsAdapter As New eVoteTableAdapters.sectionsTableAdapter()
Dim sectionsTable As New eVote.sectionsDataTable
sectionsTable = sectionsAdapter.GetDataBygetsectionsByBallotID(ballot_ID)
Dim candidatesAdapter As New eVoteTableAdapters.candidatesTableAdapter()
Dim candidatesTable As New eVote.candidatesDataTable
candidatesTable = candidatesAdapter.GetDataBygetCandidatesByballotID(ballot_ID)
openBallotName.InnerText = ballotName
Dim section_ID
For Each row As Object In sectionsTable.Rows
If row(1) = ballot_ID Then
section_ID = row(0)
Dim sectionName As New HtmlGenericControl()
Dim sectionDescription As New HtmlGenericControl()
Dim divcontrol As New HtmlGenericControl()
Dim br As New HtmlGenericControl()
divcontrol.Attributes("ID") = section_ID
divcontrol.Attributes("runat") = "server"
divcontrol.Attributes("style") = "border: solid;"
divcontrol.TagName = "div"
br.TagName = "br"
sectionName.TagName = "h4"
sectionDescription.TagName = "p"
mainBallotDiv.Controls.Add(divcontrol)
mainBallotDiv.Controls.Add(br)
sectionName.InnerText = row(2)
sectionDescription.InnerText = row(3)
divcontrol.Controls.Add(sectionName)
divcontrol.Controls.Add(sectionDescription)
For Each Crow As Object In candidatesTable.Rows
If Crow(1) = ballot_ID Then
If Crow(2) = section_ID Then
Dim checkBox As New CheckBox()
Dim canImg As New Image()
Dim canName As New HtmlGenericControl()
Dim canBio As New HtmlGenericControl()
Dim rmImg As New Image()
Dim rmName As New HtmlGenericControl()
Dim rmBio As New HtmlGenericControl()
Dim canBytes As Byte() = Crow(6)
Dim canBase64String As String = Convert.ToBase64String(canBytes, 0, canBytes.Length)
Dim rmBytes As Byte() = Crow(11)
Dim rmBase64String As String = Convert.ToBase64String(rmBytes, 0, rmBytes.Length)
checkBox.ID = Crow(0)
canName.TagName = "h3"
canBio.TagName = "p"
rmName.TagName = "h3"
rmBio.TagName = "p"
canName.InnerText = Crow(4) & " " & Crow(5)
canBio.InnerText = Crow(7)
canImg.ImageUrl = Convert.ToString("data:image/png;base64,") & canBase64String
canImg.Height = 120
rmName.InnerText = Crow(9) & " " & Crow(10)
rmBio.InnerText = Crow(12)
rmImg.ImageUrl = Convert.ToString("data:image/png;base64,") & rmBase64String
rmImg.Height = 120
divcontrol.Controls.Add(checkBox)
divcontrol.Controls.Add(canImg)
divcontrol.Controls.Add(canName)
divcontrol.Controls.Add(canBio)
If row(4) = True Then
divcontrol.Controls.Add(rmImg)
divcontrol.Controls.Add(rmName)
divcontrol.Controls.Add(rmBio)
End If
End If
End If
Next
End If
Next
End Sub
You will want a variable (integer) for the amount of checkboxes allowed, then another variable for the amount of checkboxes currently checked, finally a List containing the name of each checkbox, (have all these variables as class fields)
then in your event handler something like
Sub Check_Clicked(sender As Object, e As EventArgs)
checked += 1
If checked >= NumberAllowedChecked Then
For Each a As CheckBox In MyCheckBoxList
If Not CheckBox.Checked Then CheckBox.Enabled = False
Next
End If
End Sub
I am not overly familiar with VB but I think this should set you on the right track on how to implement it for yourself
Edit: you will want to add in logic for if a user unchecks a check box that it will subtract one from 'checked;
I have 3 buttons, one cancels, one applies the changes and one saves/exits. The Cancel and the Save/Exit work fine, but the Apply and reload page fails. When the apply/reload is clicked it loads the unchanged version or the template depending on which way I have tried, instead of showing the updated page. I know this should be a fairly simple thing and have no problems in other languages when I try this, I have left a few of the options I have tried in the code as commented out parts. I went ahead and included the whole class, but the problem area is in the btnApply_Click
Public Class create_worksheet
Inherits System.Web.UI.Page
Public Property editID As Integer
Public Property TemplateID As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
editID = Request.QueryString("id")
TemplateID = Request.QueryString("template")
If Not Page.IsPostBack Then
If (Not editID = Nothing And Not editID = 0) Then
Dim d As New Data.LINQ.LINQWorkflowDAO
Dim wf = d.GetDefaultWorkflow(editID)
If wf.ID > 0 Then
litHeading.Text = "Edit Workflow"
lblWorkflowBreadCrumb.Text = wf.Name
txtWorksheetName.Value = wf.Name
txtProcessDoc.Value = wf.DetailedProcessDocumentLink
rptPrepTasks.DataSource = wf.Tasks.Where(Function(p) p.Type = "Prep-work")
rptPrepTasks.DataBind()
rptMigrationTasks.DataSource = wf.Tasks.Where(Function(p) p.Type = "Migration")
rptMigrationTasks.DataBind()
rptPostTasks.DataSource = wf.Tasks.Where(Function(p) p.Type = "Post-migration")
rptPostTasks.DataBind()
divProcessDoc.Visible = False
Else
If Not TemplateID = Nothing Then
lblWorkflowBreadCrumb.Text = "Create Workflow"
editID = Nothing
End If
End If
ElseIf Not TemplateID = Nothing Then
Dim d2 As New Data.LINQ.LINQWorkflowDAO
Dim wf2 = d2.GetDefaultWorkflow(TemplateID)
If wf2.ID > 0 Then
litHeading.Text = "Edit Workflow"
txtProcessDoc.Value = wf2.DetailedProcessDocumentLink
rptPrepTasks.DataSource = wf2.Tasks.Where(Function(p) p.Type = "Prep-work")
rptPrepTasks.DataBind()
rptMigrationTasks.DataSource = wf2.Tasks.Where(Function(p) p.Type = "Migration")
rptMigrationTasks.DataBind()
rptPostTasks.DataSource = wf2.Tasks.Where(Function(p) p.Type = "Post-migration")
rptPostTasks.DataBind()
divProcessDoc.Visible = False
End If
If Not TemplateID = Nothing Then
lblWorkflowBreadCrumb.Text = "Create Workflow"
editID = Nothing
End If
End If
If Not IsNothing(Request.QueryString("Action")) Then lblStatus.Text = "Workflow Saved"
End If
End Sub
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
If txtWorksheetName.Value.Length > 0 Then
Dim tasks As New List(Of Data.WorkflowTask)
Dim prepTitles = Request.Form.GetValues("txtPrepTitle")
Dim migrationTitles = Request.Form.GetValues("txtMigrationTitle")
Dim postTitles = Request.Form.GetValues("txtPostTitle")
If Not IsNothing(prepTitles) Then
'prep
For i As Integer = 0 To prepTitles.Length - 1
tasks.Add(New Data.WorkflowTask With {.Name = prepTitles(i), .Type = "Prep-work"})
Next
End If
If Not IsNothing(migrationTitles) Then
'migration
For i As Integer = 0 To migrationTitles.Length - 1
tasks.Add(New Data.WorkflowTask With {.Name = migrationTitles(i), .Type = "Migration"})
Next
End If
'post
If Not IsNothing(postTitles) Then
For i As Integer = 0 To postTitles.Length - 1
tasks.Add(New Data.WorkflowTask With {.Name = postTitles(i), .Type = "Post-migration"})
Next
End If
Dim d As New Data.LINQ.LINQWorkflowDAO
Dim newid As Integer = 0
'if this is a new process, create new, else, update existing
If editID = Nothing Then
d.CreateDefaultWorkflow(txtWorksheetName.Value, tasks, txtProcessDoc.Value)
Else
newid = d.UpdateDefaultWorkflow(editID, txtWorksheetName.Value, tasks)
End If
lblStatus.Text = "Workflow Saved"
Dim wf = d.GetDefaultWorkflow(txtWorksheetName.Value)
'Response.Redirect("create-worksheet.aspx?id=" & wf.ID.ToString() & "&action=Saved")
Response.Redirect("default-worksheets.aspx")
Else
lblStatus.Text = "Please Enter a Name for the Workflow"
End If
End Sub
Private Sub btnApply_Click(sender As Object, e As EventArgs) Handles btnApply.Click
If txtWorksheetName.Value.Length > 0 Then
Dim tasks As New List(Of Data.WorkflowTask)
Dim prepTitles = Request.Form.GetValues("txtPrepTitle")
Dim migrationTitles = Request.Form.GetValues("txtMigrationTitle")
Dim postTitles = Request.Form.GetValues("txtPostTitle")
If Not IsNothing(prepTitles) Then
'prep
For i As Integer = 0 To prepTitles.Length - 1
tasks.Add(New Data.WorkflowTask With {.Name = prepTitles(i), .Type = "Prep-work"})
Next
End If
If Not IsNothing(migrationTitles) Then
'migration
For i As Integer = 0 To migrationTitles.Length - 1
tasks.Add(New Data.WorkflowTask With {.Name = migrationTitles(i), .Type = "Migration"})
Next
End If
'post
If Not IsNothing(postTitles) Then
For i As Integer = 0 To postTitles.Length - 1
tasks.Add(New Data.WorkflowTask With {.Name = postTitles(i), .Type = "Post-migration"})
Next
End If
Dim d As New Data.LINQ.LINQWorkflowDAO
Dim newid As Integer = 0
'if this is a new process, create new, else, update existing
If editID = Nothing Then
d.CreateDefaultWorkflow(txtWorksheetName.Value, tasks, txtProcessDoc.Value)
Else
newid = d.UpdateDefaultWorkflow(editID, txtWorksheetName.Value, tasks)
End If
lblStatus.Text = "Workflow Saved"
Dim wf = d.GetDefaultWorkflow(txtWorksheetName.Value)
'testing/issue items below
Dim originThing = d.GetDefaultWorkflow(txtWorksheetName.Value)
'Server.Transfer(Request.Path)
'Response.Redirect("default-worksheets.aspx")
' Response.Redirect("create-worksheet.aspx?id=" & originThing.ID.ToString() & "&action=Saved")
'Response.Redirect("create-worksheet.aspx?id=" & wf.ID.ToString() & "&action=Saved")
'Response.Redirect(Request.RawUrl)
'Response.Redirect(Request.RawUrl, True)
'Server.TransferRequest(Request.Url.AbsolutePath, False)
'Server.TransferRequest(Request.Url.AbsolutePath, True)
Else
lblStatus.Text = "Please Enter a Name for the Workflow"
End If
End Sub
End Class
Thank you all in advance for any direction you can give, it is appreciated
SOLVED IT!!!
Response.Redirect("create-worksheet.aspx?id=" & newid)
what the issue was the code was assigning a new id, and i kept going back to the old one.....
I want to build a table based on data in a recordset with a hyperlink that calls a method which takes the message id from the link and redirects to another page to view the message. I've tried HTMLAnchors, LinkButtons but none seem to work.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim iUserID As Integer
Dim sMsgId, sMsgSubject, sMsgDateSent, sMsgRead, sMsgFrom, sFirstname As String
iUserID = Session("UserID")
Dim cn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ApplicationServices").ConnectionString)
Dim cmd As New SqlCommand()
Dim tblRow As TableRow
Dim tblCell1 As TableCell
Dim tblCell2 As TableCell
Dim tblCell3 As TableCell
Dim tblCell4 As TableCell
tblRow = New TableRow
tblCell1 = New TableCell
tblCell1.Text = ""
tblRow.Cells.Add(tblCell1)
tblCell2 = New TableCell
tblCell2.Text = "From"
tblRow.Cells.Add(tblCell2)
tblCell3 = New TableCell
tblCell3.Text = "Subject"
tblRow.Cells.Add(tblCell3)
tblCell4 = New TableCell
tblCell4.Text = "Received"
tblRow.Cells.Add(tblCell4)
tblMessages.Rows.Add(tblRow)
tblCell1 = Nothing
tblCell2 = Nothing
tblCell3 = Nothing
tblRow = Nothing
cmd.CommandText = "SELECT msg.msg_id, msg.msg_usr_from, usr.usr_firstname, msg.msg_subject, msg.msg_date_sent, msg.msg_read FROM messages msg inner join users usr on msg.msg_usr_to = usr.usr_id WHERE msg.msg_usr_to='" & iUserID & "'"
cmd.Connection = cn
cn.Open()
Dim r As SqlDataReader = cmd.ExecuteReader
Dim objControl As Button
While r.Read()
tblCell1 = New TableCell
tblCell2 = New TableCell
tblCell3 = New TableCell
tblCell4 = New TableCell
tblRow = New TableRow
sMsgId = CStr(r("msg_id"))
sMsgFrom = CStr(r("msg_usr_from"))
sFirstname = CStr(r("usr_firstname"))
sMsgSubject = CStr(r("msg_subject"))
sMsgDateSent = CStr(r("msg_date_sent"))
sMsgRead = CStr(r("msg_read"))
If sMsgRead = "N" Then
tblCell1.Text = "<img width=30px src=images/new_email.png>"
Else
tblCell1.Text = "<img width=30px src=images/email_open.png>"
End If
Dim objLinkbutton As
tblRow.Cells.Add(tblCell1)
tblCell2.Text = sFirstname
tblRow.Cells.Add(tblCell2)
tblCell3.controls.add( HYPERLINK HERE!!!
tblRow.Cells.Add(tblCell3)
tblCell4.Text = FormatDateTime(sMsgDateSent, DateFormat.LongDate)
tblRow.Cells.Add(tblCell4)
If sMsgRead = "N" Then
tblCell2.Font.Bold = True
tblCell3.Font.Bold = True
tblCell4.Font.Bold = True
End If
tblMessages.Rows.Add(tblRow)
tblCell1 = Nothing
tblCell2 = Nothing
tblCell3 = Nothing
tblCell4 = Nothing
tblRow = Nothing
End While
r.Close()
cn.Close()
cn = Nothing
r = Nothing
cmd = Nothing
End Sub
Protected Sub viewmessage(messageid As String)
Context.Items("messageid") = "messageid"
Server.Transfer("viewmessage.aspx")
End Sub
End Class
You have two choices, as I see it.
Massage the data set so it contains the complete URI, with the ID, and then bind to a grid
Use a routine to create the URI and then bind the grid via row binding
Continuing hand binding the table, using hyperlink controls
All are easy enough to do, but the #3 option is the least "ASP.NET" like. I am not fond of hand building tables, when I can do the same with a control, simply by either a) altering the data before bind or b) stopping on the row binding event and adding information.
Use query string to store the id value of the selected link and redirect to the page you want.
try something like this:
Dim a As New HyperLink()
a.Text = "your text"
a.NavigateUrl = "yourPage.aspx?idMsg=" + r["msg_id"]
tblCell3.controls.add(a)
The site is a buy/sell site and the page the code comes from is the "add product" page.
The problem is that the session("change") becomes nothing by some reason, I can't find any errors. The payment.aspx have a button that sends me back to the page with a session("change").
The reason I see the problem is that when I try to edit something the category gets restetted to the first in the list. and when I debug I see that the session is nothing, though it should be something
Heres the code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSubmit.Click
If Not stats > 0 Then
If Session("change") IsNot Nothing Then
Dim dc As New DataClassesDataContext
Dim getP = From prod In dc.Products _
Where prod.ProductID = CInt(Session("change")) _
Select prod
If getP.Any Then
If rdbSell.Checked = True Then
getP.FirstOrDefault.BuySell = True
Else
getP.FirstOrDefault.BuySell = False
End If
If ddlSubSubcat.SelectedValue IsNot String.Empty Then
getP.FirstOrDefault.CategoryID = CInt(ddlSubSubcat.SelectedValue)
Else
getP.FirstOrDefault.CategoryID = CInt(ddlSubCat.SelectedValue)
End If
getP.FirstOrDefault.Content = txtContent.Text.Replace(Environment.NewLine, "<br />")
getP.FirstOrDefault.CountyID = CInt(ddlCounty.SelectedValue)
getP.FirstOrDefault.E_mail = txtEmail.Text
getP.FirstOrDefault.Date = DateTime.Now
getP.FirstOrDefault.Active = 0
getP.FirstOrDefault.Alias = txtAlias.Text.Replace("'", "''")
getP.FirstOrDefault.ShowEmail = 0
Dim PreID As Integer = getP.FirstOrDefault.ProductID
If chkShowEmail.Checked = True Then
getP.FirstOrDefault.ShowEmail = 1
Else
getP.FirstOrDefault.ShowEmail = 0
End If
If chkShowPhone.Checked = True Then
getP.FirstOrDefault.ShowPhone = 1
Else
getP.FirstOrDefault.ShowPhone = 0
End If
getP.FirstOrDefault.Headline = txtHeadline.Text
getP.FirstOrDefault.Password = txtPassword.Text
getP.FirstOrDefault.Phone = txtPhone.Text
getP.FirstOrDefault.Price = txtPrice.Text
If chkUnknown.Checked = True Then
getP.FirstOrDefault.YearModel = String.Empty
Else
getP.FirstOrDefault.YearModel = ddlYear.SelectedValue
End If
For Each item In libPictures.Items
Dim i As String = item.ToString
Dim imagecheck = From img In dc.Pictures _
Where img.Name = i And img.ProductID = CInt(Session("change")) _
Select img
If imagecheck.Any Then
Else
Dim img As New Picture
img.Name = item.ToString
img.ProductID = CInt(Session("change"))
dc.Pictures.InsertOnSubmit(img)
dc.SubmitChanges()
End If
Next
dc.SubmitChanges()
Session.Remove("change")
Response.Redirect("~/precheck.aspx?id=" + PreID.ToString)
End If
Else
Dim dc As New DataClassesDataContext
Dim prod As New Product
If rdbSell.Checked = True Then
prod.BuySell = True
Else
prod.BuySell = False
End If
If ddlSubSubcat.DataValueField IsNot String.Empty Then
prod.CategoryID = CInt(ddlSubSubcat.SelectedValue)
Else
prod.CategoryID = CInt(ddlSubCat.SelectedValue)
End If
prod.Content = txtContent.Text.Replace(Environment.NewLine, "<br />")
prod.CountyID = CInt(ddlCounty.SelectedValue)
prod.E_mail = txtEmail.Text
prod.Date = DateTime.Now
prod.Active = 0
prod.Alias = txtAlias.Text.Replace("'", "''")
prod.ShowEmail = 0
If chkShowEmail.Checked = True Then
prod.ShowEmail = 1
Else
prod.ShowEmail = 0
End If
If chkShowPhone.Checked = True Then
prod.ShowPhone = 1
Else
prod.ShowPhone = 0
End If
prod.Headline = txtHeadline.Text
prod.Password = txtPassword.Text
prod.Phone = txtPhone.Text
prod.Price = txtPrice.Text
If chkUnknown.Checked = True Then
prod.YearModel = String.Empty
Else
prod.YearModel = ddlYear.SelectedValue
End If
dc.Products.InsertOnSubmit(prod)
dc.SubmitChanges()
Dim PreID As Integer = prod.ProductID
For Each item In libPictures.Items
Dim img As New Picture
img.Name = item.ToString
img.ProductID = prod.ProductID
dc.Pictures.InsertOnSubmit(img)
dc.SubmitChanges()
Next
Session.Remove("change")
Response.Redirect("./precheck.aspx?id=" + PreID.ToString, False)
End If
End If
stats = 0
'Catch ex As Exception
'End Try
End Sub
It depends upon how the application is managing session state. If your session state is managed InProc then if the application pool is recycled then all your session information will be lost. If that is happening then it could be a good option to store session state in SQL Server which will persist between app pool recycling.
More info:
ASP.NET Session State Overview
ASP.NET State Management Recommendations