Forum Moderators: open

Message Too Old, No Replies

First Steps with ASP.NET.

I just hate those DataGrids!

         

bateman_ap

1:32 pm on Jul 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



After txbakers excellent thread, Is ASP. NET worth learning?, I bit the bullet, bought a few books and decided to transfer my clunky ASP skills to .NET.

Am currently using Visual Web Developer 2005 Express to make my pages and there are a few lovely bits. The ease of creating a drop down box and posting back for instance is lovely. However there is one thing that I can't for the life of me work out and is my most used ASP bit!

In traditional ASP I would create a header include with all my different SQL connection strings which I understand are now in the master config file. I would then create a SQL statement, ie
sSQL = "SELECT Name FROM Albums ORDER BY Name"
Set RsAlbum = Conn.Execute(sSQL)

I could then build a menu using
Do Until RsAlbum.EOF
Name = RsMenuDisplay("Name")
Albums = RsMenuDisplay("Albums ")%>
<a href="/albums/<%=(Albums)%>.htm"><%=(Name)%></a><br />
<%RsAlbum.MoveNext
Loop%>

However in .NET I just can't see how I can do this. All my books reference Datagrids and suchlike which produce tables and are impossible to get to look nice even if I wanted them (which I don't!)

I think at the moment it is the only thing stopping me getting along, can anyone help!

Many thanks

txbakers

2:04 pm on Jul 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



TEE HEE! Welcome to re-learning he**!

It is possible to do what you want to do in .NET. (If I understand you correctly...)

I have one of these:
<asp:dropdownlist id="ddNames" runat="server" AutoPostBack="True" DataValueField="idnum" DataTextField="fulln" Width="190px"></asp:dropdownlist>

which has the ID of "ddnames"

Then, in a code behind I have this:
Private Sub BindDDL()
dlFams = DB.getFams
ddNames.DataSource = dlFams
ddNames.DataMember = "Families"
ddNames.DataTextField = "fulln"
ddNames.DataValueField = "idnum"
ddNames.DataBind()
ddNames.Items.Insert(0, New ListItem("-- Choose a Household --"))

End Sub

which binds the data to the dropdownlist.

Then I have a separate routine to capture the onChange event of that and do something.

Personally, I find it a lot more work than the classic way, but I'm still ignorant about the capabilities of .NET.

bateman_ap

2:20 pm on Jul 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, think I must have confused everyone!
Question wasn't about Dropdowns, it was rather about how to display fields outside a datagrid.

So for example I used to use
Name = RsAlbum("Name")
<%=(Name)%>

to display a field. I can't see how to do this in .NET, it only seems to allow me to put it in a dataset which I don't want to do as it is all in tables etc!

I think this might be a long and painfull road, something as simple as include files seems to be laboured!

mfewtrell

3:12 pm on Jul 18, 2005 (gmt 0)

10+ Year Member



You should look at the Repeater control.

Basically you bind the repeater to the data source and then specify what HTML repeats along with a header and footer section in the repeater.

This can for example have the <table> in the header, the </table> in the footer and all the <tr><td>......</tr> in the repeating section.

More commonly though I use it for lists by just sticking the <ul> in the header, </ul> in the footer and <li> ..... </li> around the repeating data. You then style the list using CSS.

There are loads of variations and the code behind is about 3 or 4 lines.

bateman_ap

3:35 pm on Jul 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Fantastic, that worked perfectly.
If I just returned one record form the database, I presume I wouldn't use that again would I?

mfewtrell

4:25 pm on Jul 18, 2005 (gmt 0)

10+ Year Member



I'm not quite sure exactly what you have in mind but you should be able to bind most controls to most data sources.

So for instance if you only have a single record you could use a literal control and bind the text property to your data source. If you use the label control it will add some <span> 's that you may not want.