Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 7th, 2003, 05:57 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Ok I have to bug you one more time .. I have put your code in .... now the question is how do I get the value now?
I tried this:
   Label1.Text = objDataGridItem.Cells(3).Controls(1).
BUT there is no Value property or Text proerty to get the value.
Is there something I am doing wrong or missing?

Thanks again .. !!!!!
Jim
 
Old November 10th, 2003, 11:03 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Remember that objDataGridItem.Cells(3).Controls(1) returns you a control. You need to ask for a specific property of the control. Usually you just want to ask for the Text property of that control...

    Label1.Text = objDataGridItem.Cells(3).Controls(1).Text

Otherwise, you might want access to the checked state...for example:

If objDataGridItem.Cells(3).Controls(1).Checked Then
    'Do something here
End If

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old November 10th, 2003, 01:35 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Hello and thanks again...

I have tried what you suggested, however I do not have access to those properties( do no show on intellsense)
I can do something like this:
Label1.Text = objDataGridItem.Cells(3).Controls(1).UniqueID.ToSt ring

not sure why I cannot get the text or value?????

Any Ideas?
 
Old November 10th, 2003, 03:09 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The Controls() collection returns a "Control". Control doesn't have the specific properties that you are looking for so you always need to convert the Control to the specific control type that you expect to find:

Label1.Text = CType(objDataGridItem.Cells(3).Controls(1), RadioButton).UniqueID.ToString

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old November 10th, 2003, 03:45 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Thank you!!!! That works!!!!

One last question I hope, now that I have the radio button selected, I need the ID of the row that I just clicked or I can use the DataKeys collection. How can I send the row index and get the value of the ID column (the first column) or use it to use the datakeys collection .. dg1.DataKeys.Item(x) ?

Thank you so much...
 
Old November 10th, 2003, 04:45 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Here's the trick from before....

If you built your handler like I had posted earlier in the thread, you have something like this...

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

Once you have the DataGridItem object, you can get whatever you need with regards to the datagrid or that particular item.

Gets the datagrid row index of this item:
    objDataGridItem.ItemIndex

Gets you the value from the first column:
    objDataGridItem.Cells(0).Text
Change 0 to whatever the column index is for your "ID" column.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old November 10th, 2003, 04:58 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Peter,

THANK YOU VERY VERY VERY MUCH!!!!! Seriously, I cannot thank you enough. This works great, and I think it will solve what I need to do. I have been trying for days. I have learned a lot and appreciate it very much. YOu really have no idea. I hope I can e-mail you in the future if I have questions, I don't mean to be a pest, but you really know what you are doing. Mine is [email protected]

Again Thank You!!!
 
Old November 10th, 2003, 05:27 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Ah shucks...

Glad I could help. Working with non standard elements in a datagrid is a bit tricky. Believe me, it took some time to figure that out on my own.

Peter
 
Old August 31st, 2004, 06:38 PM
Registered User
 
Join Date: Jun 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ah you ripper planoie! That code works a treat! I dont completely understand it! But I will play around with it a bit more and get a better understanding of it.

But! The best bit is it works for me perfectly! Thank you very much for your post!

Regards,
Euan

 
Old September 19th, 2004, 08:48 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hello!,
I tried on tree different objects within ItemTemplate,including a Button,a DropDownList,a CheckBox,I figured out that only Buttons Object could fire off DataGrid_ItemCommand event but others cant!!!??
so for a CheckBox(RadioButtonList) we have to declare a method as peter mentioned ,like below
(the disadvantage of this way is that it should not be declared as private)

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

but for Button objects we can use DataGrid_ItemCommand event simply

//C# syntax
//this not work,I just want to represent my meaning
private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGridItem objDataGridItem=e.Item;
//instead of Dim objDataGridItem As DataGridItem = CType(objRadioList.Parent.Parent, DataGridItem)
((ourDesiredWebControl)e.Item.FindControl("I D of ourDesiredWebControl"))
//instead of Dim objRadioList As RadioButtonList = CType(sender, RadioButtonList)
}

I'm looking for a way could solve this problem ....
(I dont know why a CheckBox cant fire off DataGrid1_ItemCommand but a Button can????!!!!)

--------------------------------------------
Mehdi.:)





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





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