在Array List中添加值并在Gridview中显示 [英] Add value in Array List and display in Gridview

查看:111
本文介绍了在Array List中添加值并在Gridview中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public void  DVD()
        {
           // ListItem ltim = new ListItem();
            List<string> lts = new List<string>();
 
            lts.Add("Name");
            lts.Add("Size");
            lts.Add("brand Name");
            lts.Insert(1, "SONY");
            lts.Insert(1, "Moserber");
            lts.Insert(1, "DVD");
            lts.Insert(2, "10MB");
            lts.Insert(2, "20MB");
            lts.Insert(2, "50MB");
 
            Griddata.DataSource = lts;
            Griddata.DataBind();
             
          
 

            
        
            }

朋友,



我试过像上面那样,



但我希望将下面的列表值显示在网格视图中。



名称尺寸品牌

索尼10MB qw

moserb 50MB e3

DVD 20MB qw3

Hi Friend ,

I tried like Above,

But i want display the list values like below into grid view.

Name Size brand
Sony 10MB qw
moserb 50MB e3
DVD 20MB qw3

推荐答案

不,我们不会给你解决方案..我们不能这样为你工作..你应该自己尝试..如果你卡在某处,你当然可以来这里..但不要直接问代码..

-Krunal R。
No, we won''t give you solution.. We can''t work out for you like this.. You should try it by yourself.. If you got stuck somewhere, you can certainly come here.. But don''t ask directly for code..
-Krunal R.


自己想一想你的问题。您有3列,然后您需要以3列格式存储数据。您可以尝试:



Think yourself about your problem. You have 3 columns, then you need to store the data in 3 column format. You can try:

DataTable dt = new DataTable();
dt.Columns.Add("Name",typeof(string));
dt.Columns.Add("Size",typeof(string));
dt.Columns.Add("Brand",typeof(string));





现在添加任意数量的行:





Now add as many rows as you like:

//Add the data in Name,Size,Brand Name format to the DataTable
dt.Rows.Add("1","10MB","SONY");
dt.Rows.Add("2","20MB","MOSERBAER");
dt.Rows.Add("3","30MB","HP");





然后绑定gridview:





Then bind the gridview:

Griddata.DataSource = dt.DefaultView;
Griddata.DataBind();


这篇关于在Array List中添加值并在Gridview中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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