Gridview有一行,我必须在不覆盖第一行的情况下附加它 [英] Gridview has a row i have to append it without overwirte the 1st one

查看:118
本文介绍了Gridview有一行,我必须在不覆盖第一行的情况下附加它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gridview,其中我动态添加了新行.我创建一个数据表并添加它.当我将数据源绑定到gridview时,以前的一个被替换了.

我希望它被附加.

我该怎么办?

我已经做到了:(grid1是一个全局的arraylist)

I have a gridview in which I add a new row dynamically. I create a datatable and add it. When i bind data source to the gridview the prvious one gets replaced.

I want it to get appended.

how can i do it??

I have done this: (grid1 is a arraylist which is global)

protected void Button4_Click(object sender, EventArgs e)
    {
        DataSet ds2 = (DataSet)Session["forgrid2"];
        DataRow dr = ds2.Tables[0].NewRow();
        ds2.Tables[0].Rows.Add(dr);
        
        dr[0] = TextBox9.Text;
        dr[1] = DropDownList1.SelectedItem.Text;
        dr[2] = TextBox11.Text;
        dr[3] = TextBox12.Text;
        dr[4] = TextBox13.Text;
        dr[5] = DatePicker3.SelectedDate.ToString();
               
        grid1.Add(ds2);
        foreach (DataSet ds in grid1)
        {
             GridView3.DataSource = ds;
             GridView3.DataBind();
         }

推荐答案

您正在做什么.您正在创建一个新的DataSet ,而不是添加到现有的DataSet .

首先,不要将数据集放入会话中.这是非常不好的做法.而是根据需要填充数据网格.

所以只做
What are you doing. You are creating a new DataSet rather than adding to the existing one.

First of all dont put Dataset into session. It is very bad practice. Rather populate the datagrid on demand.

So only doing
gridView3.DataSource = ds2;
gridView3.DataBind();



对你会没事的.无需使用For循环.

另外,我建议您阅读一些基础书籍.:cool:



will be fine for you. No need to use For loop.

Also I recommend you to read some basic books.:cool:


这篇关于Gridview有一行,我必须在不覆盖第一行的情况下附加它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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