Getting Text from DataGridItem object directly

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
 
M

MasterGaurav

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
--------------------------------
 
E

Eliyahu Goldin

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
 
M

Malik Asif Joyia

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top