 |
| ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

December 15th, 2003, 07:55 PM
|
|
Authorized User
|
|
Join Date: Oct 2003
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Make multiple buttons
Hi all,
I just wondering if anybody knows a good way to generate multiple buttons in ASPX.
What I want to do is this:
I have an SQL table containing Groups, here I also have info about who made the group.
In a page I want to list all the groups any user has made. And I want two buttons next to each group that says "Send MSG" and "Edit Members"
Like this :
GroupName - Button1 - Button2
Group1 "Send MSG" "Edit Members"
Group2 "Send MSG" "Edit Members"
Group3 "Send MSG" "Edit Members"
++
Anybody got a nice way to do this?
Thanks for all and any help out there
PS. Forgot to mention if anybody didn't get that. I want to get the same page for all buttons containing a variable for the group next to the button clicked.
------------------------
All help is Good help!
Regards
Michael
__________________
------------------------
All help is Good help!
Regards
Michael
|
|

December 15th, 2003, 10:40 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
use this code for dynamic generation for Buttons:
i only added a label to view texts
and a Flowgridpanel to contain the buttons
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim but(3) As Button
Dim i As Integer
For i = 0 To 2
but(i) = New Button()
but(i).Text = "hello" & i.ToString
Fpanel1.Controls.Add(but(i))
AddHandler but(i).Click, AddressOf But_click
Next i
End Sub
Private Sub But_click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Label1.Text = sender.text & " is clicked"
End Sub
Ahmed Ali
Software Developer
|
|

December 15th, 2003, 10:48 PM
|
|
Authorized User
|
|
Join Date: Oct 2003
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Ahmed,
It looks to be exactly what I wanted!
I'll try it out now.
------------------------
All help is Good help!
Regards
Michael
|
|

December 16th, 2003, 08:02 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
I think you'll find there is a fundamental problem with this approach. Though you now have several buttons on the form that are arranged next to each group in your table, you have no programmatic association with them unless you put something associative in the button text. This is not usually a suitable situation.
You should look into the datalist or datagrid controls. These allow you to create buttons, links, just about any control and be able to link it back to a source row in which you could retrieve the useful data such as a row ID of some sort. Plus because they support databinding, they are much easier to connect with a data structure. If you'd like more info/help with the datalist/grid, post again.
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

December 16th, 2003, 05:09 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Peter, is what you're talking about called Event Bubbling?
|
|

December 16th, 2003, 07:08 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Not really. In this case we are working with controls that are all in the same page.
Event bubbling refers to when you need to "bubble" an event from controls inside another control up to the containing control. As simple example is this:
Code:
+-----------------------------+
|aspx page X |
| O |
| +----------------O -----+ |
| |user control O | |
| | O | |
| | (Public Event | |
| | ButtonClicked) | |
| | o | |
| | +-------------o --+ | |
| | |asp:button o | | |
| | | OnClick Event | | |
| | +-----------------+ | |
| | | |
| +-----------------------+ |
| |
+-----------------------------+
In this case, we have an event on the button. We handle the button click event with a sub in the user control. Then from that handler, we raise a public event on the user control (ButtonClicked). The ASPX page can thus handle the event on the control. So thus, we "bubble" the button event up to the top. (Like my bubbles? ;))
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

December 17th, 2003, 09:54 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Yes very nice drawing! I bet that took a long time to draw out. :D
|
|

December 18th, 2003, 02:18 PM
|
|
Authorized User
|
|
Join Date: Oct 2003
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Well, peter.
Regarding the datalist/grid.
What I'm doing on my page is this:
I have a table in SQL called GROUP and another called TEXT. In the page where I display the different postings(Listed in table TEXT) to the different groups I use an SQL querry to list all the groups the user is a member of with an Do while Read() = True querry.
Inside the querry I use Response.Write with some HTML coding to display the text and other things (Like if there is replys, and if the text har a picture linked to it), and another SQL querry to list all the relys for this TEXT.
This works quite nicely. So how would the Datalist/grid improve this?
------------------------
All help is Good help!
Regards
Michael
|
|

December 18th, 2003, 04:04 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
You should avoid using Response.Write in ASPX as much as possible. Namely, using that doesn't target the output to a particular location (if in the code-behind).
Using the right combination of bindable controls (grids, lists) you can eliminate all of the manual looping in your code. By using a properly constructed dataset you can use the dataset's table relationships to automatically draw the "children" for a given item in the repeated control.
I'm not quite clear on what your structure is (groups, text, users?) so I'll just use this example to illustrate my point:
Lets say we set up a datalist to show a list of groups. Within the datalist item template we create another datalist. The inner list will show us all the users in each group. Using the right dataset tables and relationships, it's really simple to set this up in the markup. In the code, we have to set the DataSource of the outer list, and DataBind() it. We also have to make sure we are using a dataset that has a relationship between the tables. This can be done by creating a new DataRelation for the two table's related columns.
Here's what the markup would look like:
<asp:datalist runat="server" id="lstGroups">
<itemtemplate>
<b><%# Container.DataItem("GroupName") %></b><br>
<asp:datalist runat="server"
DataSource='<%# Container.DataItem.Row.GetChildRows("GroupUsers") %>'>
<itemtemplate>
- <%# Container.DataItem("UserName") %><br>
</itemtemplate>
</asp:datalist>
</itemtemplate>
</asp:datalist>
About the only thing that might not be obvious is the value for the DataSource attribute of the inner list. What that data bind code is doing is selecting all the related rows based on the named relationship ("GroupUsers") for the current item (group). So for each group item in the outer list, the inner list shows that groups users. Pretty cool!
The result of our template will be something like this:
Group1
- User 1
- User 4
Group2
- User 1
- User 2
- User 3
Group3
- User 4
- User 5
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

December 18th, 2003, 05:36 PM
|
|
Authorized User
|
|
Join Date: Oct 2003
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Cool.. this sounds like a thing I have to try. Does this only depend upon your first SQL querry(databinding) then? I mean regarding the datarelation?
------------------------
All help is Good help!
Regards
Michael
|
|
 |