473,466 Members | 1,565 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Accessing Collection works

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
2 1441
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is...
4
by: John Holmes | last post by:
I'm using data to rename some web controls on a form that uses a repeater contol and so it can have mulitple instances of the same control set. The controls get renamed (thanks to Steven Cheng's...
2
by: kermit | last post by:
I have an .net aspx page MyPage.aspx (client side), with code behind MyPage.aspx.vb (server side) I use the pages server On_Load event (.aspx.vb) to create a collection using classes. ...
6
by: Steve | last post by:
I have a folder object whose associated files collection I can iterate through using a "for each / next" loop to retrieve all the file names individually. I cannot however directly access the n'th...
4
by: Tom | last post by:
Hi, I have a DLL written in VB 6.0. The DLL has some properties which can be set and a collection of Names. Here is the code in VB which i am using to access this DLL. Public Sub Form_Load()...
7
by: Chuck Anderson | last post by:
I'm pretty much a JavaScript novice. I'm good at learning by example and changing those examples to suit my needs. That said .... ..... I have some select fields in a form I created for a...
7
by: =?Utf-8?B?Li46OiBLZXZpbiA6Oi4u?= | last post by:
I have a problem with accessing controls that I have loaded dynamically and added to a web page. The scenario: I have a webpage that displays multiple instances of a user control on the page. ...
9
by: JohnR | last post by:
I have the name of a control in a string variable and I want to change one of the controls properties. Right now I recursively scan all the controls on the form until I get one whose name matches...
8
by: GaryDean | last post by:
I have a Wizard page and need to affect the next and previous buttons from my code-behind. I've googled around and found two solutions, and neither appear to work. I can access the SideBarList...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.