如何从网格视图复制数据 [英] how to copy data from grid view

查看:138
本文介绍了如何从网格视图复制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用两个文本框创建一个表单
t1和t2
和一个网格视图
g1

在g1中,我有两列
c1和c2

现在,如果我单击c1,则数据应显示为t1
如果我单击c2,则数据应显示为t2

我通过调用当前单元格实现了什么
现在我有两列怎么办

解决方案

这是最终解决方案


如果(dataGridViewUser.CurrentRow!= null& amp; amp; dataGridViewUser.CurrentRow.Cells [0]!= null)textBoxUserId.Text = dataGridViewUser.CurrentRow.Cells [0] .Value.ToString();


如果(dataGridViewUser.CurrentRow!= null& amp; amp; dataGridViewUser.CurrentRow.Cells [1]!= null)textBoxUserName.Text = dataGridViewUser.CurrentRow.Cells [1] .Value.ToString();

它可能对您有帮助,

GridView.SelectedRow属性 [ {
Gridview1.SelectedIndex = dr.RowIndex;
按钮btn =
((Button)Gridview1.Rows [Gridview1.SelectedRow.RowIndex] .FindControl("btnt1");
T1.Text = btn.Text;
}
if(e.CommandName =="C2")
{
Gridview1.SelectedIndex = dr.RowIndex;
按钮btnc =
((Button)Gridview1.Rows [Gridview1.SelectedRow.RowIndex] .FindControl("btnt2");
T1.Text = btnc.Text;
}
}


i create one form with two text boxes
t1 and t2
and one grid view
g1

in g1 i have two columns
c1 and c2

now if i click on c1 data should be display to t1
and if i click on c2 data should be display to t2

what i make it by calling current cell
now i have two column how to do

here is the final solution


if (dataGridViewUser.CurrentRow != null && dataGridViewUser.CurrentRow.Cells[0] != null) textBoxUserId.Text = dataGridViewUser.CurrentRow.Cells[0].Value.ToString();


if (dataGridViewUser.CurrentRow != null && dataGridViewUser.CurrentRow.Cells[1] != null) textBoxUserName.Text = dataGridViewUser.CurrentRow.Cells[1].Value.ToString();


It might help you,

GridView.SelectedRow Property[^]

:)


1) Set gridview columns c1,c2 as template field.Inside it place two button named as btnt1 and btnT2.

2) Set command name for c1 as C1 and command name for c2 as c2

3)In .cs code

//on gridview''s rowcommand function


foreach(GridviewRow dr in Gridview1.Rows)
{
if(e.CommandName=="C1")
{
Gridview1.SelectedIndex=dr.RowIndex;
Button btn=
((Button)Gridview1.Rows[Gridview1.SelectedRow.RowIndex].FindControl("btnt1 ");
T1.Text=btn.Text;
}
if(e.CommandName=="C2")
{
Gridview1.SelectedIndex=dr.RowIndex;
Button btnc=
((Button)Gridview1.Rows[Gridview1.SelectedRow.RowIndex].FindControl("btnt2 ");
T1.Text=btnc.Text;
}
}


这篇关于如何从网格视图复制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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