Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > ASP.NET 1.x and 2.0 Application Design
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 6th, 2003, 12:22 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default Template Columns in DataGrids

Hello All,

  This is my problem. I have a datagrid with some columns
the first being and ID column, the next column is text, a
question, the third is a template column(ItemTemplate) This is an unbound
column.
The template is a radiobuttonlist with 3 values, 1)Yes, 2)
No, 3)N/A.
This is what I need to accomplish.
1.) Collect the value of the radiobutton selected for each
row in the grid along with it's corresponding ID(column 1).
2.) If the useser selects "Yes" in the template column,
pop_up another window with more questions and collect
answers to then and their ID value.

The problem is that I can't get an event to fire when the
radio button is clicked. I tried the "ItemCommand"
eventbut that only works for buttons, linked buttons and
hyperlinks. Is there a way to do what I want to do?
Please help!!!!! Thanks...... Jim
  #2 (permalink)  
Old November 7th, 2003, 11:36 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

How are you binding the datagrid? Are you only binding it on the initial hit to the page? If not, then your events most likely won't fire.

Peter
------------------------------------------------------
Work smarter, not harder.
  #3 (permalink)  
Old November 7th, 2003, 11:49 AM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I post on page_load and if they choose another radio button outside of the datagrid. The problem seems to be that you cannot access an object placed in a Template column unless you select the row or edit it. However I do not want to do either.

  #4 (permalink)  
Old November 7th, 2003, 01:13 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What do you mean by "post on page_load"? Do you mean you bind on page_load? If that's what you mean, remember that page_load runs every time you hit the page. So you need to make the binding conditional based on "Not IsPostback".

If Not IsPostback Then
    'do data bind here
End If

This will prevent the binding for any postback page hit.

Peter
------------------------------------------------------
Work smarter, not harder.
  #5 (permalink)  
Old November 7th, 2003, 01:19 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Yes I meant bind on page load

but you are missing the whole problem

the question is.... How do I get a vaule out of a template column?
  #6 (permalink)  
Old November 7th, 2003, 01:34 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Here's what I use to access a control in a template column...

datagriditem.Cells(i).Controls(0)

where i is the template column index

Alternatively, I beleive this will work:

datagriditem.Cells(i).FindControl("optMyRadioButto n")

You'll need to convert the object to the appropriate type so you can get at the necessary properties:

objMyRadioButton = CType(datagriditem.Cells(i).FindControl("optMyRadi oButton"), RadioButton)

With regards to the original post and getting an event to fire, you need to set up the handler for the radio button. You still need to check that you aren't binding every time you hit the page, cause that will negate any events that *would* happen when the controls are redrawn.

Peter
------------------------------------------------------
Work smarter, not harder.
  #7 (permalink)  
Old November 7th, 2003, 01:48 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I can drill down to the control .. dg1.control(0) .. but you cannot get the value .. there is just now way I can see

Also I have tried using the findcontrol("").. but it never seems to find the control
dg1.findcontrol(rblAnswers) .. always returns NOTHING ...

Your suggestion dg1.control().value will work if the row is in edit mode... but not when just viewing .. to me this is very strange... try it and you will see what I mean.

thanks
  #8 (permalink)  
Old November 7th, 2003, 04:26 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Are you doing a postback on each radio button click so that you can pop up the additional questions page on each "Yes" answer?

Peter
------------------------------------------------------
Work smarter, not harder.
  #9 (permalink)  
Old November 7th, 2003, 04:34 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Just figured this out...

<asp:templatecolumn>
    <itemtemplate>
        <asp:radiobuttonlist OnSelectedIndexChanged="checkBoxHandler" autopostback="True" runat="server">
            <asp:listitem value="1">No</asp:listitem>
            <asp:listitem value="2">Yes</asp:listitem>
            <asp:listitem value="3">N/A</asp:listitem>
        </asp:radiobuttonlist>
    </itemtemplate>
</asp:templatecolumn>

Public Sub checkBoxHandler(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim objRadioList As RadioButtonList = CType(sender, RadioButtonList)
    Dim objDataGridItem As DataGridItem = CType(objRadioList.Parent.Parent, DataGridItem)
End Sub

You can reference the control's ancestors so you can eventually work your way back to the datagriditem that the radio button lives in. Then you can do what you need with the datagriditem.

Peter
------------------------------------------------------
Work smarter, not harder.
  #10 (permalink)  
Old November 7th, 2003, 05:12 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I will have to look at your code in more depth to fully understand it, but if it works GREAT!!!!!! Thank you forall of your time spent on this... I will try this out shortly and let you know how this goes
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Filtering Template columns in Detailsview shashipandey ASP.NET 2.0 Professional 0 September 20th, 2007 04:58 AM
getting values from template columns itemtemplate Laxmikant_it ASP.NET 1.0 and 1.1 Professional 4 February 6th, 2007 04:19 PM
Need to get value of gridview template columns for kmh030 ASP.NET 2.0 Professional 1 January 6th, 2007 11:10 PM
Template Columns in a Datagrid Greg Griffiths ASP.NET 1.0 and 1.1 Basics 1 October 28th, 2004 08:02 AM
Template Columns in DataGrids jbenson001 ASP.NET 1.x and 2.0 Application Design 3 March 12th, 2004 11:01 AM



All times are GMT -4. The time now is 12:41 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.