473,378 Members | 1,518 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

ASPNET 2.0: dynamic buttons

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()
Jan 31 '06 #1
0 1144

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: MikeY | last post by:
Hi Everyone, Does anyone know where I can get my hands on a sample with source code of a simple dynamic button control in C# Windows form. I am looking for a sample that uses a class library...
1
by: brian | last post by:
'visual studio 2002 pro 1.0 framwork' I am creating dynamic Link buttons on my intranet site and assigning a click_event to them. A user clicks a link and I call the method to recreate the...
1
by: andrei | last post by:
Hi Group, I have an aspx form with a variable number of buttons added dynamically, with id's like b01, b02, b03... Whenever I click one of these buttons, the form is posted back. I need to...
3
by: WebBuilder451 | last post by:
I have a series of dynamic link buttons created based upon a datareader. I've added a click event and it calls the sub ok: example: "while loop through the reader" Dim ltrCtrl As New...
5
by: Charts | last post by:
I recently upgraded to VS2005. I noticed that in ASP.NET project, the system generated codes are missing from default.aspx.cs file. While I used to be able to see it in VS2003 project. Now, if I...
2
by: WolfyUK | last post by:
Hello, I have a standard asp:DataGrid called CasesGrid that I wish to write my own paging controls for. The aim is to get something like the following rendered to screen: << First < Previous...
13
by: rn5a | last post by:
In a shopping cart app, suppose a user has placed 5 orders, I want to show him 5 LinkButtons (one for each order) so that when he clicks the first LinkButton, he would be shown the details of his...
2
by: remya1000 | last post by:
hai i'm using Vb.net. i'm creating 64 dynamic created buttons of 8 rows and 8 columns. And i have 1 Go button, 1 textbox. those were created dynamically. if i enter one number inside textbox and...
2
Frinavale
by: Frinavale | last post by:
I've created a ASP.NET control that displays a "book" of schedules. It dynamically displays scheduling times and allows the user to page through the schedules. It also lets the user edit the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.