ASPNET 2.0: dynamic buttons

J

Jim in Arizona

How could I dynamically create a button within a loop that holds a
specific field from a database?

I have a webform that loops through the records in related tables of an
SQL database. I've been displaying the primary key and in order to edit
the specific table of data, I have sql statements already made up within
a buttons click procedure and I just enter the primary key to complete
the sql statement in order to manipulate the data. I want a button to
show up on the webpage for each table shown on the webpage so that we
wouldn't have to enter the key number of the html table showing the
specific data. This is kind of hard to explain. Here a section of code
that I currently do. I use a loop to loop through the records and HTML
to display the data exactly how I want it displayed. So, how could I
dynamically place a button on each HTML table with the ID of the primary
key of my database? I would like to just click a button on any shown
table that I want have an SQL statement execute based on the button i click.

Dim strConnection As String = ConfigurationManager.AppSettings("tickets")
Dim objConnection As New SqlConnection(strConnection)

Dim parentCol As DataColumn
Dim childCol As DataColumn
Dim relation1 As DataRelation
Dim objAdapter As New SqlDataAdapter(strSQLTickets, objConnection)
Dim objAdapter1 As New SqlDataAdapter(strSQLNotes, objConnection)
Dim objDataSet As New DataSet()

objAdapter.Fill(objDataSet, "ticketstable")
objAdapter1.Fill(objDataSet, "notestable")

parentCol = objDataSet.Tables("ticketstable").Columns("PK")
childCol = objDataSet.Tables("notestable").Columns("FK")

relation1 = New DataRelation("RelationA", parentCol, childCol)
objDataSet.Relations.Add(relation1)

Dim strResults As String = ""
Dim r As DataRow

For Each r In objDataSet.Tables("ticketstable").Rows
strResults += "<table border=""3"" cellspacing=""0""
cellpadding=""2"" width=""100%"" bordercolor=""black"" bgcolor=""#e7e7e7"">"
strResults += "<tr bgcolor=" &
r.Item("prioritycolor").ToString & "><td><span
style=""font-family:arial;font-size:10pt;color:black;""><b>Priority:</b><br
/>" & r.Item("prioritynumber").ToString & "</span></td>" & _
"<td bgcolor=""black""><span
style=""font-family:arial;font-size:10pt;color:white;""><b>ID #:</b><br
/>" & r.Item("PK").ToString & "</span></td><td><span
style=""font-family:arial;font-size:10pt;color:black;""><b>Subject:</b><br
/>" & r.Item("subject").ToString & "</span></td>" & _
"<td><span
style=""font-family:arial;font-size:10pt;color:black;""><b>Date &
Time:</b><br />" & r.Item("dtemp").ToString & "</span></td><td><span
style=""font-family:arial;font-size:10pt;color:black;""><b>Emp
Name:</b><br />" & r.Item("name").ToString & "</span></td>" & _
"<td><span
style=""font-family:arial;font-size:10pt;color:black;""><b>AD
Username:</b><br />" & r.Item("unemp").ToString & "</span></td><td><span
style=""font-family:arial;font-size:10pt;color:black;""><b>IP
Address:</b><br />" & r.Item("ip").ToString & "</span></td></tr><tr
bgcolor=" & r.Item("prioritycolor").ToString & ">" & _
"<td colspan=""7""><span
style=""font-family:arial;font-size:10pt;color:black;""><b>Description
of Problem:</b><br />" & r.Item("descript").ToString &
"</td></tr><tr><td><span
style=""font-family:arial;font-size:10pt;color:black;""><b>Assign
To:</b><br />" & r.Item("assign").ToString & "</span></td>" & _
"<td><span
style=""font-family:arial;font-size:10pt;color:black;""><b>Assign
By:</b><br />" & r.Item("unass").ToString & "</span></td><td><span
style=""font-family:arial;font-size:10pt;color:black;""><b>Assign
Date/Time:</b><br />" & r.Item("dtass").ToString & "</span></td>" & _
"<td><span
style=""font-family:arial;font-size:10pt;color:black;""><b>Resolved
By:</b><br />" & r.Item("unresolve").ToString & "</span></td><td><span
style=""font-family:arial;font-size:10pt;color:black;""><b>Resolve
Date/Time:</b><br />" & r.Item("dtresolve").ToString & "</span></td>" & _
"<td><span
style=""font-family:arial;font-size:10pt;color:black;""><b>Approved
By:</b><br />" & r.Item("unapp").ToString & "</span></td><td><span
style=""font-family:arial;font-size:10pt;color:black;""><b>Approve
Date/Time:</b><br />" & r.Item("dtapp").ToString & "</span></td></tr>" & _
"<tr><td colspan=""7""
bgcolor=""silver""><span
style=""font-family:arial;font-size:10pt;color:#004400;""><center><b>- -
- Information System Notes - - -</b></center></span></td></tr>"

Dim childr() As DataRow
childr = r.GetChildRows("RelationA")

Dim theChildRow As DataRow

For Each theChildRow In childr
strResults += "<tr height=""6""><td colspan=""7""
bgcolor=""black""></td></tr>"
strResults += "<tr bordercolor=""#fafafa""><td
colspan=""2""><span
style=""font-family:arial;font-size:10pt;color:black;""><b>Posted
By:</b><br />" & theChildRow.Item("unnotes").ToString & "</span></td>"
strResults += "<td colspan=""2""><span
style=""font-family:arial;font-size:10pt;color:black;""><b>Posted
Date/Time:</b><br />" & theChildRow.Item("dtnotes").ToString &
"</span></td>"
strResults += "<td colspan=""3""><span
style=""font-family:arial;font-size:10pt;color:black;""><b>Comments/Notes:</b><br
/>" & theChildRow.Item("notes").ToString & "</span></td></tr>"
Next
strResults += "</table><br /><br />"
Next
testgrid.InnerHtml = strResults
objConnection.Close()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top