Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

databound grid: Converting textbox to checkbox

Status
Not open for further replies.

vituja123

Programmer
Jun 16, 2005
110
0
0
US
Hi All,

For one filed in my databound grid, I need to convert it from a textbox to a checkbox. But I cannot figure out the exact coding. I tried this but it doesn't work. It bombs out on the DIM statement below:

Sub LoadItemData(ByVal sender As Object, ByVal e As DataGridItemEventArgs)

If e.Item.DataItem("DataType") = "Checkbox" Then
Dim ChkBox As CheckBox = CType(e.Item.Cells(1).Controls(1), CheckBox)
If e.Item.DataItem("ValueData") = "0" Or e.Item.DataItem("ValueData") = "N" Then
CType(e.Item.Cells(1).Controls(1), CheckBox).Checked = False
Else
CType(e.Item.Cells(1).Controls(1), CheckBox).Checked = True
End If
end if

end sub
 
You can't convert a control from one type to another. What are you trying to do?

Jim
 
it WILL bomb out at the dim statement unless you actually have added a chkbox to your grid. you can't declare something that's not there.

 
I have a datagrid with two columns, Label and textbox. When the data is being read and the fieldname is, lets say, "Testfield", i need to represent that as a checkbox instead of a textbox.
 
That's possible, but converting a TextBox to a CheckBox simply isn't - they are two completely different objects with different properties and methods.

All you need to do is get a reference to the relevant checkbox, and if the value of the label is "Testfield", then set the CheckBox's Checked property to True.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I think you are a little confused. If you want a checkbox, then you need to create the column as a template column and add a checkbox into it.

Jim
 
Thanks everyone. I just implemented something simular to jshurst example on 4guysfromrolla.

I think I got it to work.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top