Getting Text from DataGridItem object directly

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

Is there a way to get the text from control, without actually defining it?

For example, I have a DataGrid that has fields that are either Labels or
Textboxes, depending on whether they are in edit mode or not.

Dim answer as String
Dim lblAnswer as Label = CType(oDataGridItem.FindControl("Answer"),Label)
if lblAnswer = nothing then
Dim txtAnswer as TextBox =
CType(oDataGridItem.FindControl("Answer"),TextBox)
answer = txtAnswer.text
else
answer = lblAnswer.text
end if
' use answer for something

Is there a way to get the text from an object in a DataGridItem, without
having to set it to an object first?

Thanks,

Tom
 
Are you using ASP.Net 1.1? If so, the best idea is to definte a
Protected control:

Protected Dim Answer as Label
' The name, Answer, should match what is given in the ASPX file.

Then, directly use:

Answer.Text


In ASP.Net 2.0, you can make use of Partial Classes.



--
Cheers,
Gaurav Vaish
http://www.mastergaurav.org
http://mastergaurav.blogspot.com
--------------------------------
 
Tom,

Define both of them but make only one visible at the time. On entering/exit
editing mode, toggle visibility and copy text between the controls.

Eliyahu
 
Hello
you also need the index of data Grid item in which you are going to find
that control .
you dont have need to declare the control any where
just assign it an id and use it to finding control ,

Regards
Malik Asif
 
Back
Top