Is there a way to get the DetailsView control to display its title in the <th> cell?
Since the DetailsView uses <td> cells for both header text and data, I was wondering if it is possible to override the control's behavior to display the header of the header of each row in a <th> cell?
@Joel Coehoorn Thanks for the quick response, but I kind of hoped I didn't have to go that route.
I was wondering if it is possible to override one of the control's render methods to achieve this?
Someone seems to have rendered the success of the <th> cell , but did not seem to reveal the details - any other suggestions would be greatly appreciated.
source to share
I managed to find a way around this by using the ItemCreaed event handler and replacing the <td> cell for the <th> cell:
if (view.Rows.Count > 0) {
// swap each header <td> cell for a <th> cell
foreach (DetailsViewRow row in view.Rows) {
if (row.RowType == DataControlRowType.DataRow) {
DataControlFieldCell td = row.Cells[0] as DataControlFieldCell;
// skip the last row that contains our command controls
if (td.Controls.Count > 0) {
continue;
}
DataControlFieldHeaderCell th = new DataControlFieldHeaderCell(td.ContainingField);
th.Text = td.Text;
th.Attributes.Add("scope", "row");
// add the new th and remove the old td
row.Cells.RemoveAt(0);
row.Cells.AddAt(0, th);
}
}
}
source to share
There is no inline parameter in the control itself. However, you can completely override the rendering behavior for any control, including the DetailsView, using the Control Adapter .
source to share