How to retrieve the particular row of detailsview into textbox on page load event if details view defaultmode is readonly
i开发者_高级运维 want to retrieve the email id from detailsview email row in textbox1 on page load event ?
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
TextBox1.Text = DetailsView1.Rows(2).Cells(1).Text
End Sub
Make sure you realize that with a DetailsView, the max "Cells" value is 1. Look at it as if you were pulling and SQL query and these are the rows that are output.
Row = Up and down (starting with 0)
Cells = Column (0 or 1)
One way is to access the DataItem in the RowDataBound like:
DataRowView dr = (DataRowView)DetailsView1.DataItem;
string myfield = (string)dr["YourFieldName"];
Another way is get the item from Rows.Cells like:
DetailsViewRow row = DetailsView1.Rows[youremailrowindex];
String email= row.Cells[youremailcellindex].Text;
精彩评论