3

My class structure is

public class Listings
{
    public string id { get; set; }
    public string title { get; set; }

    public ListingsImages[] images;
}

public class ListingsImages
{ 
    public string src { get; set; }
    public string width { get; set; }
    public string height { get; set; }
    public string alt { get; set; }
    public string num { get; set; }
    public string size { get; set; }
}

I want to bind my grid view and i m binding as

List<Listings> p = getData(); //returns list of Listings
gv.DataSource = p;
gv.DataBind();

My grid view code is

<asp:GridView ID="gv" runat="server" AutoGenerateColumns=false>
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <%# Eval("id") %>
                        &nbsp&nbsp&nbsp&nbsp&nbsp
                        <%# Eval("title") %>
                        &nbsp&nbsp&nbsp&nbsp&nbsp
                        <%# Eval(?????)%>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

One Listings object containts 10 images ! Now the problem is I want to display 6th pic of all Listings object then ?? I have tried

 <%# Eval("images[5].src")%>

But it gives me error ! Kindly answer me what should be solution ? ( Just only with one gridview and one datasource)

Chintan
  • 2,768
  • 4
  • 27
  • 43
  • @PranayRana I have not tried this 'Cz I found another solution so I choose that one btw thanks for answer ! I will use in future ! – Chintan Feb 07 '12 at 09:52

1 Answers1

1

Yes you can do it by making use of RowDataBound() event of grid to do that............

protected GridView_RowDataBound(object sender,
  GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
            //e.row.DataItem -- points to data / object which is going to be bind with the row 
     }
}
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
  • Brief Explaination please or any link – Chintan Feb 06 '12 at 13:18
  • 1
    I don't think this helps. The datasource itself is the Listings class, which is not a collection. It is the images property that is the collection and that is not what is bound as the datasource. – Rob Levine Feb 06 '12 at 13:20
  • @Rob Levine - in the rowdatabound you can query as well as can access the dataitme easily acc to me in this event he can able to do d task he want – Pranay Rana Feb 06 '12 at 13:23