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

November 7th, 2003, 05:57 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
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
|
|

November 10th, 2003, 11:03 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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.
|
|

November 10th, 2003, 01:35 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
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?
|
|

November 10th, 2003, 03:09 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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.
|
|

November 10th, 2003, 03:45 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
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...
|
|

November 10th, 2003, 04:45 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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.
|
|

November 10th, 2003, 04:58 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
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!!!
|
|

November 10th, 2003, 05:27 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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
|
|

August 31st, 2004, 06:38 PM
|
|
Registered User
|
|
Join Date: Jun 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

September 19th, 2004, 08:48 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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.:)
|
|
 |