Get value from gridview to formview in insert mode
Is there a way to get the value from gridview and then paste it in a textbox in formview? I'm trying开发者_JAVA技巧 to get the selected datakeys like ID, firstname, lastname and insert it on a textbox in formview (i've set the defaultmode to 'insert'). I've tried it with a textbox by using the SelectedIndexMethod but how can I do it in formview textbox while in 'insert' mode?
Help would be much appreciated! Thanks in advance!
The GridView1.SelectedDataKey.Value will give you what you are looking for.
In your formView, it will be like:
<asp:TextBox Text='<%#GridView1.SelectedDataKey.Value %>'></asp:TextBox>
Edit:
<asp:TextBox Text='<%#GridView1.Rows[GridView1.SelectedIndex].Cells[0].Text %>'></asp:TextBox>
// Cells[0] column index of your Gridview
To get values from different cells you can try this:
string fn = GridView1.SelectedRow.Cells[0].Text; //assuming first column is FirstName
string ln = GridView1.SelectedRow.Cells[1].Text
Note that I assume Select Command Button is clicked i.e. SelectedRow is not null.
加载中,请稍侯......
精彩评论