简体   繁体   中英

how to get value of row in gridview and display in textbox?

How to get value of row in Gridview and display in Textbox ?

Don't work this code. And I don't want to use this code:

protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) {
        LinkButton lnkButton = sender as LinkButton;
        GridViewRow row = (GridViewRow) lnkButton.NamingContainer;
        lblSender.Text = row.Cells[2].Text;
        lblSubject.Text = row.Cells[5].Text;
        txtReadMsg.Text = row.Cells[6].Text;

Are you sure your GridView's cells don't have controls inside it.

maybe this helps you

To get the row, do:

var row = GridView1.Rows[e.NewSelectedIndex];

And then the rest of the code should work for you. You can then remove the first two lines. Also, note Text only works if you are using BoundColumn column definitions; it won't work if you are using a different type of column.

If you are getting a different error, then it's related to something else; please add a comment and we can help work through it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM