如何在GridView中绑定数据列表中的数据 [英] how to bind data in datalist with in gridview

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

问题描述

先生您好,
我想在Gridview中绑定一个数据抛出数据列表.
另一件事是,当使用带有gridview的datalist时,datalist属性完全被隐藏.所以我无法生成dataItemBound事件.
因此,我想知道如何在GridView中生成该dataItemBound属性并抛出数据列表.

Hello sir,
I wand to bind a data throw datalist with in Gridview.
another thing is that when is take datalist with gridview than datalist property is totally hide.So i can not generate dataItemBound event.
so i want to know that how to generate that dataItemBound property throw datalist with in GridView.

推荐答案

       您必须在网格视图的行数据绑定事件中编写代码.
在这种情况下,您必须在网格视图单元格中找到控件,其名称为"datalist1".

               You have to write code in grid-view''s row data bound event.
In that event you have to find the control in the grid view cell by it''s name say "datalist1".


                                 之后,在您拥有数据列表1对象后,便可以对其进行分配.数据源.


               After that type cast the control. once you have the datalist1 object you can assign it a data-source.

      protected void gvRatings_RowDataBound(object sender, GridViewRowEventArgs e)
      {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataList DataList1= ((DataList)e.Row.FindControl("DataList1"));
                DataList1.DataSource=<some data="" source="" object="">;
           //do what ever you want to do here using the value of your label
            }
      }
</some>



                                &meb;         资源.如果要全部绑定它们,则可以使用相同的数据源对象.



               Rememeber you have to bind data-list of each row of grid separately even if they have same data source. you can you same data-source object if you want to bind them all.


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

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