Click here to Skip to main content
15,914,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

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();
 
Share this answer
 
It might help you,

GridView.SelectedRow Property[^]

:)
 
Share this answer
 
Comments
kami124 26-Jul-11 8:22am    
i use it like this but there is a problem
taht no extension method select row accepted
textBoxUserId.Text = dataGridViewUser.SelectedRows.Cell[1].Text;
Mohammad A Rahman 26-Jul-11 8:25am    
Sorry I did not understand, could you please explain a bit more :)
kami124 26-Jul-11 8:31am    
string s1 = dataGridViewUser.SelectedRows.Cell[1].Text;

i do it like this
but here is one problem that
no extension method Cells accepting the first argument
Mohammad A Rahman 26-Jul-11 8:37am    
Sorry, I am not sure what would you mean by "no extension method Cells accepting the first argument" :)
kami124 26-Jul-11 8:41am    
string s1 = dataGridViewUser.SelectedRows.Cell[1].Text;

i am saying that in my above statement there is error
and is not executing
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;
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900