DetailsView Problem

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

In ASP.NET, I've created a DetailsView control, unbound. There are a
few textboxes in it, and I want to be able to enumerate through all
the rows, and get the values of the textboxes in those rows. Any
ideas how I should go about doing this?
 
Chris said:
In ASP.NET, I've created a DetailsView control, unbound. There are a
few textboxes in it, and I want to be able to enumerate through all
the rows, and get the values of the textboxes in those rows. Any
ideas how I should go about doing this?

When (what event) does you want to be able to enumerate controls in row ?
For example: I can enumerate controls in ItemDataBound event

[Design]

<asp:detailview onitemdatabound="OnItemDataBound">
<itemTemplate>
<asp:textbox id="txtName" text='<%# Eval("Name") %>'>
<Br /><asp:textbox id="txtAge" text='<%# Eval("Age") %>'>
<Br /><asp:textbox id="txtPosition" text='<%# Eval("Position") %>'>
</itemTemplate>
</asp:detailview>

[code behind]

protected void OnItemDataBound(object sender,DataListItemEventArgs e) {
if( e.Item.ItemType == ListItemType.AlternativeItem || e.Item.ItemType
== ListItemType.Item ) {
Textbox txt1 = e.Item.FindControl("txtName") as Textbox;
Textbox txt2 = e.Item.FindControl("txtAge") as Textbox;
Textbox txt3 = e.Item.FindControl("txtPosition") as Textbox;
// do anything you want to these textbox
txt1.Text = "Mr. "+txt.Text;
}
}

Hope this help
 
Back
Top