Gridview选择数据 [英] Gridview select data

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

问题描述

hi ..
在gridview中有4个条目,在表中有4个类似的条目.我想使用表格记录在gridview中显示的条目来更新我的表格.表示使用表中的第一个条目来更新gridview第一行的目录,依此类推..但是这一切都必须自动完成..请帮助我..

解决方案

如果您实现视图模型,则非常容易做到.您使用绑定到gridview和表中的视图模型的方式绑定到要显示的字段的相同数据.

首先从gridview中选择第一行详细信息,然后将其用于循环以将表格插入到具有其他信息的新表中.


for(int i = 0; i< gridview1.rows.count; i ++)>
{
字符串staff_name = GridView1.Rows [i] .Cells [1] .Text;
字符串staff_dept = GridView1.Rows [i] .Cells [2] .Text;
字符串str =插入intrmarks(VTUNO,ROLLNO,NAME,DEPARTMENT,SEM,IA1,IA2,IA3,FINAL_MARKS,mobile,email,Staff_Name,SUBJECT_NAME)values(""+ txtvtu.Text +"'',""+ Convert.ToInt32(txtrno.Text)+"'',''"+ txtsname.Text +"'',''"+ ddldes.Text +"'',''"+ Convert.ToInt32(ddlsem.Text )+'',0,0,0,0,''" + txtmob.Text +'',''" + txteml.Text +'',""+ staff_name +"''," + staff_dept +'')";
SqlCommand strCmd =新的SqlCommand(str,con);
strCmd.ExecuteNonQuery();

}


hi..
I ve 4 entries in a gridview and i ve 4 similar entries in a table. I want to update my table with the entries present in the gridview with the table records. means gridview 1st row shold be updated with the 1st entry in the table and so on.. but it all has to be done automatically..kindly help me..

解决方案

If you implement a view model then it is very easy to do. You using bindings to the viewmodel in gridview and table to the same data binding to the fields you want to display. This handles changing the grid when you change your table or vise versa.


1st select the 1st row details from gridview den use for loop to insert the into new table with additional information.


for(int i=0;i<gridview1.rows.count;i++)>
{
string staff_name = GridView1.Rows[i].Cells[1].Text;
string staff_dept = GridView1.Rows[i].Cells[2].Text;
string str = "insert into intrmarks(VTUNO,ROLLNO,NAME,DEPARTMENT,SEM,IA1,IA2,IA3,FINAL_MARKS,mobile,email,Staff_Name,SUBJECT_NAME)values(''" + txtvtu.Text + "'',''" + Convert.ToInt32(txtrno.Text) + "'',''" + txtsname.Text + "'',''" + ddldes.Text + "'',''" + Convert.ToInt32(ddlsem.Text) + "'',0,0,0,0,''" + txtmob.Text + "'',''" + txteml.Text + "'',''"+staff_name+"'',''"+staff_dept+"'')";
SqlCommand strCmd = new SqlCommand(str, con);
strCmd.ExecuteNonQuery();

}


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

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