Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Using a datafield value as a function argument

Reply
Thread Tools

Using a datafield value as a function argument

 
 
Dave
Guest
Posts: n/a
 
      12-01-2004
I'm one baffled newbie. I know this is trivial, but I can't figure it out.

Using inline aspx code, I have a function called dbIntegerToString(i as
Integer, s as String) as String

Down in the html code, I have a datagrid, a stub of which follows:

<asp:TemplateColumn>
<ItemTemplate>
<%# Container.DataItem("Lessons") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText = "Recommendation">
<ItemTemplate>
<%# Container.DataItem("Recommendation") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText = "DOT">
<ItemTemplate>
<%= dbIntegerToString(3, "Category") %>
</ItemTemplate>
</asp:TemplateColumn>

All this works fine.

But my issue is in the last ItemTemplate. What I want to do, instead of
passing '3', is to pass a data value I read in when all the other data
values were read (in another vb procedure). The field is called "DOT", and
is in the same SELECT statement as the other fields you see.

Replacing '3' with 'Container.DataItem("DOT")' doesn't work (Compiler Error
Message: BC30451: Name 'Container' is not declared.), and other feeble
attempts also result in errors.

Is there anybody out there that can set me straight on this?

Thanks in advance,

Dave


 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      12-02-2004
Hi Dave,

It may just be a syntax issue. I took your code and played with it. The code
below *seems* to do something like what you might need.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
Toronto

<%@ Page Language="vb" AutoEventWireup="true" %>
<%@ Import Namespace="System.Data" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>dgcontainer</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="visualbasic" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub
Function dbIntegerToString(ByVal i As Integer, ByVal s As String) As
String
Return "Test" & i.ToString
End Function
Function CreateDataSource() As system.data.DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("Lessons", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("Recommendation", GetType(String)))
dt.Columns.Add(New DataColumn _
("Category", GetType(Double)))
dt.Columns.Add(New DataColumn _
("DOT", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
</script>
</head>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<asp:datagrid id="DataGrid1" runat="server"
AutoGenerateColumns="False">
<columns>
<asp:templatecolumn>
<itemtemplate>
<%# Container.DataItem("Lessons") %>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn HeaderText="Recommendation">
<itemtemplate>
<%# Container.DataItem("Recommendation") %>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn HeaderText="DOT">
<itemtemplate>
<%#
dbIntegerToString(Container.DataItem("Lessons"),Co ntainer.DataItem("Category")
) %>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
</form>
</body>
</html>



"Dave" <(E-Mail Removed)> wrote in message
news:e%23N4HA$(E-Mail Removed)...
> I'm one baffled newbie. I know this is trivial, but I can't figure it out.
>
> Using inline aspx code, I have a function called dbIntegerToString(i as
> Integer, s as String) as String
>
> Down in the html code, I have a datagrid, a stub of which follows:
>
> <asp:TemplateColumn>
> <ItemTemplate>
> <%# Container.DataItem("Lessons") %>
> </ItemTemplate>
> </asp:TemplateColumn>
> <asp:TemplateColumn HeaderText = "Recommendation">
> <ItemTemplate>
> <%# Container.DataItem("Recommendation") %>
> </ItemTemplate>
> </asp:TemplateColumn>
> <asp:TemplateColumn HeaderText = "DOT">
> <ItemTemplate>
> <%= dbIntegerToString(3, "Category") %>
> </ItemTemplate>
> </asp:TemplateColumn>
>
> All this works fine.
>
> But my issue is in the last ItemTemplate. What I want to do, instead of
> passing '3', is to pass a data value I read in when all the other data
> values were read (in another vb procedure). The field is called "DOT", and
> is in the same SELECT statement as the other fields you see.
>
> Replacing '3' with 'Container.DataItem("DOT")' doesn't work (Compiler
> Error
> Message: BC30451: Name 'Container' is not declared.), and other feeble
> attempts also result in errors.
>
> Is there anybody out there that can set me straight on this?
>
> Thanks in advance,
>
> Dave
>
>


 
Reply With Quote
 
 
 
 
Dave
Guest
Posts: n/a
 
      12-02-2004
Ken,

Beeyootiful. Just changing
'<%=dbIntegerToString(Container.DataItem("DOT")... ' to
'<%#dbIntegerToString(Container.DataItem("DOT")... ' fixed it.

If I may explore this a little bit, what does the '#' signify? I read in a
tutorial somewhere that you use a '=' when calling a function. And I just
inferred that the '#' referred to a database value. Perhaps I'm reading the
wrong tutorials?

Dave

"Ken Cox [Microsoft MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Dave,
>
> It may just be a syntax issue. I took your code and played with it. The

code
> below *seems* to do something like what you might need.
>
> Let us know if this helps?
>
> Ken
> Microsoft MVP [ASP.NET]
> Toronto
>

[snip]
> <itemtemplate>
> <%#
>

dbIntegerToString(Container.DataItem("Lessons"),Co ntainer.DataItem("Category
")
> ) %>
> </itemtemplate>
> </asp:templatecolumn>
> </columns>
> </asp:datagrid>
> </form>
> </body>
> </html>
>
>
>
> "Dave" <(E-Mail Removed)> wrote in message
> news:e%23N4HA$(E-Mail Removed)...
> > I'm one baffled newbie. I know this is trivial, but I can't figure it

out.
> >

[snip]


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable argument function as a parameter of a variable argument function AikidoGuy C Programming 11 11-21-2011 10:43 PM
function argument dependent on another function argument? Reckoner Python 11 01-19-2009 03:31 AM
Passing a function as an argument and using the evaluated functionas an argument User1014 Javascript 1 11-30-2006 12:13 PM
How to get DataField value of a cell Dinšer ASP .Net 3 12-09-2004 09:10 AM
get DataField value in UpdateCommand richard ASP .Net 0 12-02-2003 07:35 AM



Advertisments