数据表,Gridview [英] Data table,Gridview

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

问题描述

嘿,

我有一个数据表dtValues,它在单击按钮(添加)时从ddl,label,文本框中获取值.此按钮将这些值添加到网格中.我已将数据表dtValues用作gridview的数据源.

现在,当这些值填充到数据表/网格中时,在按钮上单击添加
它将先前的值一次又一次地放入网格中.

我的btnAdd代码是:-

Hey there,

I have a datatable dtValues which takes values from ddl,label,textbox on a button(Add) click.this button adds these values to the grid. I have used data table dtValues as datasource to gridview.

Now when these values are filled in data table/grid,On button click Add
it takes the previous values again and again into the grid.

My code for btnAdd is :-

protected void btnAdd_Click(object sender, EventArgs e)
       {
           if (ddlSearchItems.SelectedIndex > 0)
           {
               DataRow drValues = dtValues.NewRow();
               drValues["Id"] = ddlSearchItems.SelectedItem.Value;
               drValues["Item"] = ddlSearchItems.SelectedItem.Text;
               drValues["Rate"] = lblActualPrice.Text;
               drValues["Qty"] = txtQuantity.Text;
               drValues["Amount"] = Convert.ToInt32(lblActualPrice.Text) * Convert.ToInt32(txtQuantity.Text);
               dtValues.Rows.Add(drValues);
               dtValues.AcceptChanges();
               gvOrders.DataSource = dtValues;
               gvOrders.DataBind();
               //gvOrders.Columns[0].Visible = false;
               gvOrders.Visible = true;
           }
       }


这些值将保留在网格中,直到通过单击按钮(btnSubmit)提交它们为止,在该按钮上我重置了数据表.

如何避免该用户无法在btnAdd_click上的数据库中下相同的先前订单?

我正在使用它来将记录保存到数据库中-


The values stays in the grid until they are submitted by a button click(btnSubmit) on which i resets the data table.

How can i avoid that user is not able to put the same previous order in database on btnAdd_click?

I am using this to save the records into database--

private void InsertOrder(int productId, int quantity)
       {
           
           objSqlHelper.InsertOrderInDB(txtName.Text, txtAddress.Text, Convert.ToInt32(txtPhone.Text), DateTime.Now, productId, quantity);
       }

;

推荐答案

我不太清楚您想要在这里实现什么,请您多说明一点. :doh:

如果您不想在btnAdd click上的GridView中看到以前的记录,则需要在分配新行之前清除DataTable.
I am not too clear what you want to achieve here, can you please explain a bit more. :doh:

If you don''t want to see previous records in GridView on btnAdd click, then you need to clear DataTable before assigning a new row to it.


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

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