如何为动态创建的行分配和绑定gridview [英] How to assign and bind gridview for dynamically created rows

查看:72
本文介绍了如何为动态创建的行分配和绑定gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[Gridviewlink]



我使用上面的链接创建了gridview。当我保存数据时,值将传递给DB。然后我必须从DB重新绑定值,我必须显示。任何人都可以给我一些提示。我不是要求任何代码。谢谢

[Gridviewlink]

I created gridview using above link .When I save the data the values are passing to DB. Then I have to rebind the values from DB and I have to display. Can any one please give me the hint. I am not asking any code.Thanks

推荐答案

一旦保存数据页面将回发。您可以在那里调用绑定数据方法。您查询数据库并获取数据表中的数据并将表绑定到gridview。
once you save the data the page will postback. You can call the bind data method there.you query the database and get the data in datatable and bind the table to gridview.


您可以重新绑定数据库中的值并使用linq显示它们to sql:



you can rebind the values from DB and display them by using linq to sql:

public void RefreshGrid()
       {
           OrdersDataContext contex = DataContextSingleton.Instance;

           var query = (from o in _readyToSave
                        join pr in contex.Products on o.prod_id equals pr.id
                        join d in contex.Discounts on o.discoun_id equals d.id
                        join r in contex.Registrations on d.id_reg equals r.id
                        select new
                        {
                            Article = pr.article,
                            Description = pr.description,
                            Quantity = o.quant,
                            Price = o.price,
                            Discount = d.discounts,
                            TotalPrice = o.totalprice
                        }).OrderBy(x => x.Article);

           OrderGridView.DataSource = query.ToList();
           OrderGridView.DataBind();

       }





这里有一个示例,我从数据库中检索数据然后在某处在我的代码后面会询问RefreshGrid(),然后datagridview将检索并显示来自DB的数据。



here is a sample, i retrieve tha data from DB and then somewhere in my code behind RefreshGrid() would be asked, then the datagridview will retrieve and show the data from DB.


这篇关于如何为动态创建的行分配和绑定gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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