绑定的DataItem在GridView的列 [英] binding dataitem to columns in gridview

查看:119
本文介绍了绑定的DataItem在GridView的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<%# ((DataRowView)Container.DataItem)["SomeProperty"] %>
<%# DataBinder.Eval(Container.DataItem, "SomeProperty")%>

从谷歌我想通了,这些可以被用来在 GridView控件列绑定到的ArrayList 。但什么是一些财产?

From Google i figured out these can be used to bind the columns in GridView to ArrayList. But what is "some property" ?

例如我.aspx.cs有一个的ArrayList

For example i have a ArrayList in .aspx.cs as

static ArrayList componentSelectionArray = new ArrayList();

所以我只是在网格视图写入到一个数组列表绑定到网格视图的列:

so can i just write in grid view to bind a arraylist to grid view columns as:

<asp:GridView ID= "GridView1" runat="server" AutoGenerateColumns="true">
  <Columns>    
    <asp:TemplateField HeaderText="ComponentName">
      <ItemTemplate>
         <asp:Label ID="" text= "<%# DataBinder.Eval(Container.DataItem, "componentSelectionArray")%>" ></asp:Label>
      </ItemTemplate>
    </asp:TemplateField>
</asp:GridView>

请帮我

感谢您在期待

推荐答案

要绑定到的ArrayList 你只需要拿到底层的DataItem

To bind to an ArrayList you just have to get the the underlying DataItem.

假设你的的ArrayList 是存储字符串你只需要做的:

Assuming your ArrayList is storing a string you just have to do:

<asp:Label ID="" Text="<%# GetDataItem().ToString() %>"></asp:Label>

GetDataItem():在数据绑定上下文堆栈顶部获取数据项

GetDataItem(): Gets the data item at the top of the data-binding context stack.

MSDN 更多信息

这篇关于绑定的DataItem在GridView的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆