如何使用c#清除asp.net中的数据表值 [英] how to clear datatable value in asp.net using c#

查看:79
本文介绍了如何使用c#清除asp.net中的数据表值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何清除数据表值。



在运行模式下如下



主要代码AMC (Dropdownlist1)次要代码AFF(Dropdownlist2)按钮(添加)

CTF



当我点击添加按钮时,将显示AMC和AFF在gridview中。



在gridview中如下



主要代码次要代码

AMC AFF



添加按钮代码如下



how to clear the datatable value.

in run mode as follows

Major code AMC (Dropdownlist1) Minor code AFF(Dropdownlist2) Button(Add)
CTF

When i click Add button the AMC and AFF will be displayed in the gridview.

In gridview as follows

Major code Minor code
AMC AFF

Add button code as follows

protected void btnadd_Click(object sender, EventArgs e)
     {
     if (Session["MyTable"] == null)
       {
           dt1 = new DataTable("MyTable");
           dt1.Columns.Add("Major Code", typeof(string));
           dt1.Columns.Add("Minor Code", typeof(string));
       }
       else
       {
           dt1 = (DataTable)Session["MyTable"];
       }
       DataRow dt_row;
       dt_row = dt1.NewRow();
       dt_row["Major Code"] = ddlmjrcode.SelectedItem.ToString();
       dt_row["Minor Code"] = ddlminorcode.SelectedItem.ToString();
       dt1.Rows.Add(dt_row);
       Session["MyTable"] = dt1;
       gvmajormaster.DataSource = (DataTable)Session["MyTable"];
       gvmajormaster.DataBind();
   }

  I have one clear button.clear button code as follows.

 protected void btnClear_Click(object sender, EventArgs e)
   {
          gvmajormaster.DataSource = null;
          gvmajormaster.DataBind();
    }





当我点击清除按钮时。 gridview行将为空。



类似当我点击Add按钮时,AMC和CTF将显示在gridview中。



在gridview中如下

主要代码次要代码

AMC AFF

AMC CTF



但是网格视图中显示了前一行AMC和AFF。当我点击添加按钮时,我不想在网格视图中使用AMC和AFF仅在网格视图中显示AMC和CTF。



问候,

Narasiman P.



When i click the clear button. gridview rows will be empty.

similarily When i click Add button the AMC and CTF will be displayed in the gridview.

In gridview as follows
Major code Minor code
AMC AFF
AMC CTF

But previouse row AMC and AFF is displayed in the gridview. i dont want the AMC and AFF in gridview when i click the add button only AMC and CTF only to be displayed in the gridview.

Regards,
Narasiman P.

推荐答案

以下链接对您有所帮助

http://www.c-sharpcorner.com/UploadFile/77a82c/data-binding-control-using-listview- and-gridview / [ ^ ]
below link is helpful to you
http://www.c-sharpcorner.com/UploadFile/77a82c/data-binding-control-using-listview-and-gridview/[^]


这篇关于如何使用c#清除asp.net中的数据表值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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