Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Getting Text from DataGridItem object directly

Reply
Thread Tools

Getting Text from DataGridItem object directly

 
 
tshad
Guest
Posts: n/a
 
      02-23-2005
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


 
Reply With Quote
 
 
 
 
MasterGaurav
Guest
Posts: n/a
 
      02-24-2005
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
--------------------------------

 
Reply With Quote
 
 
 
 
MasterGaurav
Guest
Posts: n/a
 
      02-24-2005
Wait a sec... Partial Classes, I think, is a C# language feature.

So, the best way is to declare a protected control with the same name
as in ASPX page.

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

 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      02-24-2005
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

"tshad" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Malik Asif Joyia
Guest
Posts: n/a
 
      02-24-2005
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
"tshad" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting text to the Clipboard directly tshad ASP .Net 0 10-31-2009 07:41 AM
Getting a method object directly from a module Daniel Berger Ruby 1 06-09-2005 07:02 PM
Preview image directly on PC, save directly to HD Patrick M. Digital Photography 3 01-07-2004 08:29 PM
DataGrid Built In Paging and DataGridItem Problem Paul Perot ASP .Net 0 12-12-2003 01:17 AM
Problems with casting DataGridItem.findcontrol and DataGridItem.cells(0).control(1) to checkbox Samuel Chowdhuri ASP .Net Datagrid Control 1 10-20-2003 07:02 PM



Advertisments