By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,847 Members | 2,402 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,847 IT Pros & Developers. It's quick & easy.

Accessing Collection works

P: n/a
Accessing Items in a Collection works with the [] as suggested by Kevin and
Chris (thx)
But when i tried to use the same technic with databinding within the aspx
file, it doesn't seem to work.
This is the aspx part that i am talking about

<asp:DataGrid id="dgThreads" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn HeaderText="Databases">
<ItemTemplate>
<%# Container.DataItem["author_id"] %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

Compiler Error Message: CS0021: Cannot apply indexing with [] to an
expression of type 'object'

I've tried to look up what functions and properties that are available with
DataItem with no success.

Alternatively i could have changed the TemplateColumn to a BoundColumn and
simply specify the datafield I want, this approach works, but this lacks
flexibility when i want to create customized columns. So What i want to do
is know how I can bind data explicitly to a TemplateColumn explicitly using
<%# ......................%>

Please help again.
Cheers

j

Hi all

I have been developing some web apps using VB.NET for a coupla month.

Until recently I have tried to use C# instead of VB. What i find is that in VB.NET, Collections can be accessed using the dictionary approach for
example ds.Tables("Threads") as below

Dim DBConnection As New OleDbConnection = "blah .. .. . .. "
Dim DBCommand As New OleDbCommand(DBQueryString, DBConnection)
Dim DBAdapter As New OleDbDataAdapter(DBCommand)
Dim DSThreads As New DataSet()
DBConnection.Open()
DBAdapter.Fill(DSThreads, "Threads")
DBConnection.Close()
--> dgThreads.DataSource = ds.Tables("Threads")
dgThreads.DataBind()

What I want to know is how I would do the same thing ds.Tables("Threads")
using C#. I want to retrieve the table "Threads" that is store in the
dataset. ds.Tables is a a property that returns a DataTableColletion. There seem to be no straight forward way to access the DataTable that is contained in the collection.

Please help, any suggestion is much appreciated.

Cheer

J

Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I found a solution to my own problem, simply use

<%# DataBinder.Eval(Container.DataItem, "DATABASE_NAME") %>
in place of
<%# Container.DataItem["author_id"] %>

Cheer and Thanx again for the help

J

"James Zhuo" <na**************@optusnet.com.au> wrote in message
news:e%****************@tk2msftngp13.phx.gbl...
Accessing Items in a Collection works with the [] as suggested by Kevin and Chris (thx)
But when i tried to use the same technic with databinding within the aspx
file, it doesn't seem to work.
This is the aspx part that i am talking about

<asp:DataGrid id="dgThreads" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn HeaderText="Databases">
<ItemTemplate>
<%# Container.DataItem["author_id"] %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

Compiler Error Message: CS0021: Cannot apply indexing with [] to an
expression of type 'object'

I've tried to look up what functions and properties that are available with DataItem with no success.

Alternatively i could have changed the TemplateColumn to a BoundColumn and
simply specify the datafield I want, this approach works, but this lacks
flexibility when i want to create customized columns. So What i want to do
is know how I can bind data explicitly to a TemplateColumn explicitly using <%# ......................%>

Please help again.
Cheers

j

Hi all

I have been developing some web apps using VB.NET for a coupla month.

Until recently I have tried to use C# instead of VB. What i find is that

in
VB.NET, Collections can be accessed using the dictionary approach for
example ds.Tables("Threads") as below

Dim DBConnection As New OleDbConnection = "blah .. .. . .. "
Dim DBCommand As New OleDbCommand(DBQueryString, DBConnection)
Dim DBAdapter As New OleDbDataAdapter(DBCommand)
Dim DSThreads As New DataSet()
DBConnection.Open()
DBAdapter.Fill(DSThreads, "Threads")
DBConnection.Close()
--> dgThreads.DataSource = ds.Tables("Threads")
dgThreads.DataBind()

What I want to know is how I would do the same thing ds.Tables("Threads") using C#. I want to retrieve the table "Threads" that is store in the
dataset. ds.Tables is a a property that returns a DataTableColletion.

There
seem to be no straight forward way to access the DataTable that is

contained
in the collection.

Please help, any suggestion is much appreciated.

Cheer

J


Nov 17 '05 #2

P: n/a
Even though i found a solution for the problem
I would still like to know how i might be able to do the equivalent of
<%# Container.DataItem("author_id")%>
using C#

Cheers

J

"James Zhuo" <na**************@optusnet.com.au> wrote in message
news:e%****************@tk2msftngp13.phx.gbl...
Accessing Items in a Collection works with the [] as suggested by Kevin and Chris (thx)
But when i tried to use the same technic with databinding within the aspx
file, it doesn't seem to work.
This is the aspx part that i am talking about

<asp:DataGrid id="dgThreads" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn HeaderText="Databases">
<ItemTemplate>
<%# Container.DataItem["author_id"] %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

Compiler Error Message: CS0021: Cannot apply indexing with [] to an
expression of type 'object'

I've tried to look up what functions and properties that are available with DataItem with no success.

Alternatively i could have changed the TemplateColumn to a BoundColumn and
simply specify the datafield I want, this approach works, but this lacks
flexibility when i want to create customized columns. So What i want to do
is know how I can bind data explicitly to a TemplateColumn explicitly using <%# ......................%>

Please help again.
Cheers

j

Hi all

I have been developing some web apps using VB.NET for a coupla month.

Until recently I have tried to use C# instead of VB. What i find is that

in
VB.NET, Collections can be accessed using the dictionary approach for
example ds.Tables("Threads") as below

Dim DBConnection As New OleDbConnection = "blah .. .. . .. "
Dim DBCommand As New OleDbCommand(DBQueryString, DBConnection)
Dim DBAdapter As New OleDbDataAdapter(DBCommand)
Dim DSThreads As New DataSet()
DBConnection.Open()
DBAdapter.Fill(DSThreads, "Threads")
DBConnection.Close()
--> dgThreads.DataSource = ds.Tables("Threads")
dgThreads.DataBind()

What I want to know is how I would do the same thing ds.Tables("Threads") using C#. I want to retrieve the table "Threads" that is store in the
dataset. ds.Tables is a a property that returns a DataTableColletion.

There
seem to be no straight forward way to access the DataTable that is

contained
in the collection.

Please help, any suggestion is much appreciated.

Cheer

J


Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.