What am I doing wrong? (Datagrid)

  • Thread starter Kristoffer Arfvidson
  • Start date
K

Kristoffer Arfvidson

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ästa &amp;gt;" PrevPageText="&amp;lt;
Föregå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
 
M

Michael Ramey

<asp:table ... RUNAT="SERVER" ... >

:)

Kristoffer Arfvidson said:
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ästa &amp;gt;" PrevPageText="&amp;lt;
Föregå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
 
K

Kristoffer Arfvidson

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...
Container.DataItem("smallheadline")

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

Michael Ramey said:
<asp:table ... RUNAT="SERVER" ... >

:)

Kristoffer Arfvidson said:
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ästa &amp;gt;" PrevPageText="&amp;lt;
Föregå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")
 
K

Kristoffer Arfvidson

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 said:
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...
If
depending
of Container.DataItem("smallheadline")

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

Michael Ramey said:
<asp:table ... RUNAT="SERVER" ... >

:)

information
bit
of shouldnt
be,
If
depending
 
K

Kristoffer Arfvidson

AHA!!!
Found it, or?
e.Item.DataItem("smallheadline")



Seems to work, ok, thanks!



Yours: Kristoffer
 

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,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top