将文本框值添加到gridview [英] adding textbox values to gridview

查看:76
本文介绍了将文本框值添加到gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过单击添加按钮将文本框值添加到网格视图,此后如果单击保存按钮,则网格视图中的值必须存储在sql server数据库中

步骤1:点击添加按钮后,文本框值必须进入网格视图
步骤2:如果单击此按钮,则会保存另一个按钮,网格视图中的值应存储在数据库中

How to add text box values to grid view by clicking on a add button and after that if we click a save button then the values from grid view must store in sql server database

step1:text box values must go into grid view after clicking a add button
step2: there is another button save if we click on this the values from grid view should store in database

推荐答案

Hello,
为此
1st:创建数据表
第二个:将行添加到数据表
第三步:绑定到gridview并将其存储在viewate中,然后从第1步开始重复(通过将viewstate值转换回datatable)


第一步:
按照以下方式创建数据表...
DataTable表=新的DataTable();
添加所需的列数,并提供要绑定到gridvieww的名称.

table.Columns.Add("Ename",typeof(int));
table.Columns.Add("Sname",typeof(string));
table.Columns.Add(部门",typeof(字符串));
table.Columns.Add("DateOfJoin",typeof(string));

第二步:
按钮的onclick会取在文本框中输入的值,然后添加到数据表的列中.

table.Rows.Add(txtname.text.trim(),txtsname.text.trim(),txtDptName.text.trim(),txtdate.text.trim());

最后将此表绑定到gridview
grdEmpdetails.datasource = table;

并将此表存储在viewstate
viewstate ["dtTable"] = talbe;
再次
第三:单击按钮后,您必须将viewstate值转换回datatable并添加新行,然后再次将其绑定到gridview ..

完成
Hello,
To Do this
1st:create datatable
2nd:add row to datatable
3rd: bind to gridview and store that talbe in viewsate and repeat from step 1(by converting viewstate value back to datatable)


1st step:
create data table following way...
DataTable table = new DataTable();
add columns how many you want and give the names which you are binding to the gridvieww

table.Columns.Add("Ename", typeof(int));
table.Columns.Add("Sname", typeof(string));
table.Columns.Add("Department", typeof(string));
table.Columns.Add("DateOfJoin", typeof(string));

2nd step:
onclick of the button take the values entered in the textbox and add to the columns of the datatable.

table.Rows.Add(txtname.text.trim(),txtsname.text.trim() ,txtDptName.text.trim(),txtdate.text.trim() );

at the end bind this table to the gridview
grdEmpdetails.datasource=table;

and store this table in the viewstate
viewstate["dtTable"]=talbe;
again
3rd:onlcick of the button you have to convert viewstate value back to datatable and add the new row and again bind that to gridview..

Its Done


这篇关于将文本框值添加到gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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