How to add a small HTML table under a row of a GridView

O

onearth

Hello

I already managed to add a dynamic DetailView under a row of Gridview
if a user presses the row with the mouse...

Is it possible to add under it a table(or even better load a simple
HTML file that contains the tables).. not a detailview like I already
did..Because i would like to be able to design the table as i wish and
not to be limited to the DetailView Design which only contains rows &
coluwns.
I want totally new design....

I really need this if anyone knows..
so please :)
 
E

Edwin Knoppert

I often use resources.
You could embed the html as resource and still design it.
Maybe a little bit last-minute stripping or so? (removing tags)
 
O

onearth

Hello Edwin..

What do you mean embed the html as a resoruce... What object does this?
 
E

Edwin Knoppert

Start new project (or existing)
Add special folder: App_GlobalResources
Add in this folder a resource: Resource.resx (new item)
Add the html to that folder (evt refresh).
Open Resource.resx, something with string is shown, forget that.
Just drag the html in the new screen, a pretty large image with the filename
is now shown.
Close, go to any page_load or whatever code.

To get a string:
Dim T as String = Resources.Resource.thefilenamehere.ToString

And so you can insert the html as styring into any trag you like :)

Note the codetip will show present resources after: Resources.Resource....
 
E

Edwin Knoppert

It's silly but i tested the html by embedding it into the aspx.
Of course <html> twice isn't good but it worked:

......
</form>
</body>
<%=Resources.Resource.HTMLPage.ToString%>
</html>
 
O

onearth

Hello

Thank you a lot for this example!...

Something i have missing is if i create this HTML from CODE Behind
since i want to be able to create for each ROW of the gridview an HTML
file to display below it.. if i could create the HTML from codebehind
that would be helpul..
 
E

Edwin Knoppert

It might be easier to prepare a usercontrol?
Or at least more solid since html stuff is correct then.
 
O

onearth

Hello

I have tried your solution and indeed it is nice... didn't know about
the resources before..

What i did is: If your press 1 of the rows in a GridView it creates a
row below it and in that row I add a label from code. To that label i
added the resource of an HTML file like you showed me.. it worked
nicely ..
Now comes the question if i can bind data from a datasource into that
HTML file i bind from the resource so it will display some data
(customized with the HTML i add) in that label (HTML actually).. I
already tried to use DetailView which works since it contains binding
method built-in, but the problem with DetailView is that I couldn't
customize its appearance from code so it only shows like the standard
DetailView with rows and coluwns.. (I added the DetailView from code,
created that object)..

If you have a solution for this I will be grateful :)
 
E

Edwin Knoppert

I still recommend you to take a peek at usercontrols.
They are directly embedable into a template item.

If you want to change on-the-fly in your html.
You could use replace( "%1", eval("mydatafield).tostring )
But that's a problem in-line.
So you'll need a wrapper function.
I put that in the codebehind and used a public function

Public Function ReplaceNow( byval s as string ) AS String
Dim shtml as string = ... (your resource)
sHtml = shTml.replace( "%1", s )
Return sHTML
End Function

IN your template (~):
<%#ReplaceNow(eval("mydatafield).tostring))%>
 
E

Edwin Knoppert

I love resources.
I use them a lot with javascript and SQL statements.
No more conversions having chr$( 34) misery etc..

I often use %1 and so on to be replaced, like in queries.

:)
 
O

onearth

You mean that i can use a usercontrol..
In that UserControl i will make the nice table and also bind the data
into that table and display it under the row i wanted?

sounds like an easier solution if i get you right..

If i get you right do you know how to add a usercontrol from code
behind?
 
O

onearth

I meant i will premake a usercontrol, but i will have to ADD it in
code... I always used usercontrols but i placed them in the HTML not
from code :)
 
E

Edwin Knoppert

I guess you could change things on-the-fly.
In fact i do the same with a label in a gridview, why should it be different

Here is a snapshot of a line required to let the aspx know that there is a
usercontrol (so no need to compile).

<%@ Register TagPrefix="pflr" TagName ="pflr" Src= "~/licreg.ascx" %>

.....

<form id="form1" runat="server">
<div>
<pflr:pflr ID="pflr1" runat="server" />
<br />
etc..

Afaik, the tagname and prefix should differ i guess, it does work though :)
 
E

Edwin Knoppert

sounds like an easier solution if i get you right..
Yes, but i offered another approach.
Use it as it should and not with html.

:)
 
O

onearth

Thank you for all the information...

I just want to see if i get it right before i test it:

1) I create an ASPX (not HTML :) ) resource and let it know there is a
usercontrol (with "Register" tag).
2) I create a UserControl that contains the table with binding Tags
(for data binding) (so i do not use the ReplaceNow function now)
3) I place in the Label (the 1 inside the new row of the GridView) and
in that label i put the ASPX code inside.. (MyLabel.Text =
Resources.Resource.MYASPXPage.ToString();)
4) Ummm, that is it? :)
 
E

Edwin Knoppert

No forget resources, just create a control.

I just tested, works fine, here is a label + usercontrol.

<asp:TemplateField HeaderText="Gegevens">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Trim( Server.HtmlEncode(
Eval("Voornaam").ToString & " " & Eval("TussenVoegsels").ToString & " " &
Eval("Achternaam").ToString ) ).replace( " ", " " ).Replace( " ", "&nbsp;" )
& "<BR>" & BankOfGiro( Eval("BankOfGiro").ToString,
Eval("BankNummer").ToString, Eval("GiroNummer" ).ToString,
Eval("TenNameVan" ).ToString ) %>'></asp:Label>
<pflr:pflr ID="pflr1" runat="server" />
</ItemTemplate>
<ItemStyle Wrap="False" />
</asp:TemplateField>

The register tag needs to be present in the aspx where the grid is.
So the page knows of the control.
TYPE the control like i did, otherwise you can not see it in visual design.
(it's not in the toolsbox)
Now mess wit the UC's properties you design.
 
E

Edwin Knoppert

If you look close:
<pflr:pflr ID="pflr1" runat="server" />

This also means you can use the UC's custom properties(!)
For example a Text property

<pflr:pflr ID="pflr1" runat="server" Text=<%# eval.... %> />

ON text you can modify the UC completely.
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top