Groups | Blog | Home
all groups > asp.net > january 2004 >

asp.net : What am I doing wrong? (Datagrid)


Michael Ramey
1/30/2004 5:05:16 PM
<asp:table ... RUNAT="SERVER" ... >

:-)

[quoted text, click to view]

Kristoffer Arfvidson
1/30/2004 10:55:11 PM
Im trying to get access to a table in codebehind, because the information in
this table is different depending on what it says in the database...

So, either I have to access it from codebehind, or Ill have to make bit of
code on the aspx page...
However, I would prefere code in the aspx page at the moment, but it seemed
easier to access thecode from codebehind...
However...

When I run the following code, (when I look at the code it generates)
I see that <asp:Table> still is visible in the HTML code, this shouldnt be,
should it?
I mean, it should have been converted to normal HTML, it dosn´t, for some
reason...


In other words, the asp:Table code Dosnt work... It simple wont compile...

Any suggestions?


------
<asp:DataGrid id="DataGrid1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" Font-Names="Verdana, Arial, Helvetica,
sans-serif"
AllowCustomPaging="True" GridLines="None" BorderStyle="None"
BorderWidth="0px">
<HeaderStyle Font-Names="Verdana,Arial,Helvetica,sans-serif"
Font-Bold="True" ForeColor="Black"
BackColor="Transparent"></HeaderStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<table border="0" Cellpadding="0" Cellspacing="0" Width="100%"
style="FONT-SIZE: 11px; FONT-FAMILY: Verdana, Arial, sans-serif">


<tr onMouseOver='mOvr(this,"#9090FF");' onMouseOut='mOut(this,"");'
onClick="jsfuncreadart('<%# Container.DataItem("ID") %>','<%#
Container.DataItem("Type") %>');">
<td width="10" valign="top"><img src="../bilder/tomgif.gif" width="1"
height="8"><br><img src="../bilder/tomgif.gif" width="1" height="1"><img
src="../bilder/link_pil.gif" width="8" height="7"></td><td>

<asp:Table ID="tableItem" width="100%" borderwidth="0"
cellspacing="0" cellpadding="0">
<asp:TableRow><asp:TableCell Horizontalalign="right"><img
src="../bilder/tomgif.gif" width="1" height="3"></asp:tablecell>
</asp:tableRow>



</asp:Table>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle NextPageText="N&#228;sta &amp;gt;" PrevPageText="&amp;lt;
F&#246;reg&#229;ende"
Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
---

Now, there is another question I would like to have answered, when or If I
get this to work, how can I access the container object from codebehind?
Because I want to access this table and build it as I want to depending of
the information on the database, in other words...
I want to do this from the sub:

----
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
If (e.Item.ItemType = ListItemType.Item) Then
Dim i As Integer
For i = 0 To e.Item.Controls.Count - 1
Try
'tableItem

If (e.Item.Controls(i).ID = "tableItem") Then
Dim table As Table
table = e.Item.Controls(i).Controls(1)
Dim row As TableRow
Dim cell As TableCell
row = New TableRow
cell = New TableCell


'<<<---- HERE??? HOW CAN I ACCESS <%# Container.DataItem("smallheadline") %>
?? IN THIS CODE?
'BECAUSE I NEED TO BUILD THE TABLE DEPENDING ON WHAT IT SAYS IN THE
DATABASE!!!

cell.Text = "TJABBALOOOOO!!!"
row.Cells.Add(cell)
table.Rows.Add(row)
End If
Catch

End Try
Next
End If
End Sub
----
Yours: Kristoffer

Kristoffer Arfvidson
1/30/2004 11:20:49 PM
Ahh, ok,thats it, time for me to get some sleep... ;-)
Thanks!
Anyways, how about that second question?
I also, get a problem while trying to add the tablerows to the existing
table...
(see in sub)...

the table.Rows.Add(row) dosnt seem to be enough....

So, I want to be able to add rows to the table, and also access the database
values from this sub...

[quoted text, click to view]

----------
Yours Kristoffer

"Michael Ramey" <raterus@localhost> skrev i meddelandet
news:OOlDm035DHA.1664@TK2MSFTNGP11.phx.gbl...
[quoted text, click to view]

Kristoffer Arfvidson
1/30/2004 11:25:07 PM
I see that the If (e.Item.Controls(i).ID = "tableItem") Then is never met...
Hmm, I just have to figure out another way to identify the table...
but the question about the database???

Yours: Kristoffer


"Kristoffer Arfvidson" <kristoffer@spamtrap.com> skrev i meddelandet
news:OOkGQ935DHA.3664@tk2msftngp13.phx.gbl...
[quoted text, click to view]
Kristoffer Arfvidson
1/30/2004 11:48:50 PM
AHA!!!
Found it, or?
e.Item.DataItem("smallheadline")



Seems to work, ok, thanks!



Yours: Kristoffer



"Kristoffer Arfvidson" <kristoffer@spamtrap.com> skrev i meddelandet
news:uZ756u35DHA.2580@TK2MSFTNGP11.phx.gbl...
[quoted text, click to view]

AddThis Social Bookmark Button