本文介绍了使用GRID一对一地从Web表单插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在从Web表单中插入值.

从下拉列表中选择第一个项目名称,然后使用文本框中的项目费率和数量.

我希望所有这些值都放入网格中,当我插入所有值时,计算所有值的数量,然后按提交以保存这些数据,然后保存在数据库中.

Hi,

I am inserting value from web form.

First item name selecting from drop down list then using item rate and quantity from text box.

I want all these values to come in a grid and when I have inserted all the values, calculate amount of all value and press submit to save these data and then save in database.

推荐答案



private DataTable CreateDataTable()
        {
            DataTable myDataTable = new DataTable();
            DataColumn myDataColumn;
            myDataColumn = new DataColumn();
            myDataColumn.DataType = Type.GetType("System.String");
            myDataColumn.ColumnName = "ItemName";
            myDataTable.Columns.Add(myDataColumn);
            myDataColumn = new DataColumn();
            myDataColumn.DataType = Type.GetType("System.String");
            myDataColumn.ColumnName = "ItemRate";
            myDataTable.Columns.Add(myDataColumn);
            myDataColumn = new DataColumn();
            myDataColumn.DataType = Type.GetType("System.String");
            myDataColumn.ColumnName = "ItemQty";
            myDataTable.Columns.Add(myDataColumn);
            //add records
            AddDataToTable("ItemName1", "ItemRate1", "ItemQty1", myDataTable);
            // In your case you can comment the above line and go like this
            //AddDataToTable(textBoxItemName.Text,ddlItemRate.SelectedValue, txtItemQty.Text,myDataTable);
            gvItems.DataSource = myDataTable;
            gvItems.DataBind();
            return myDataTable;
        }
        private void AddDataToTable(string strItemName, string strItemRate, string strItemQty, System.Data.DataTable myTable)
        {
            DataRow row;
            row = myTable.NewRow();
            row["ItemName"] = strItemName;
            row["ItemRate"] = strItemRate;
            row["ItemQty"] = strItemQty;
            myTable.Rows.Add(row);
        }


希望这有效:)


Hope this works :)


这篇关于使用GRID一对一地从Web表单插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 04:26