views:

2101

answers:

4

Hi I have a List which returns an array of "Question". My question is how can I bind this to a grid view? When I try to call Question.Ordinal I get that it does not exist in the data source. I am using the following code:

GridView1.DataSource = myList.GetQ();
GrdiView1.DataBind();

myList.GetQ() returns a List which is an array of "Question".

When I set the column DataField to "!" I get the object Question. My question is how can I get the objects property? I tried "!.Ordinal" does not work. I was reading this post for reference, here, any help is greatly appreciated, thanks.

A: 

Try using the following syntax:

<%# ((MyObject)Container.DataItem).MyField %>
Rob
I get a parse error:Databinding expressions are only supported on objects that have a DataBinding event. System.Web.UI.WebControls.BoundField does not have a DataBinding event.
A: 

Hi I found my solution for anyone else having a problem refer to:

http://weblogs.asp.net/scottgu/archive/2003/11/03/35645.aspx

I am not saying that is wrong, but you don't need to go all the way to the datasource solution OliverS. I am glad you cleared up any confusion you had.
eglasius
+1  A: 

Just set it directly to Ordinal, as the first examples in the post you just linked to:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
   <asp:BoundField HeaderText="ID" DataField="CustId" />
   <asp:BoundField HeaderText="Name" DataField="Name" />
   <asp:BoundField HeaderText="City" DataField="City" />
</Columns>
</asp:GridView>

Say:

<asp:BoundField HeaderText="A Header" DataField="APropertyOfQuestion" />
eglasius
A: 

Really Good answer... I solve my problem with the last comment. but Still a little problem... I want to make one of the field an object... like Button or Link... how can I do that????

Jaider