adding some data from my databind into a javascript function

I have my data list:
<asp:DataList runat="server" ID="dlCabins" RepeatDirection="horizontal" RepeatColumns="10">
                                <HeaderTemplate></HeaderTemplate>
                                <ItemTemplate>
                                    <table border="1" style="text-align:center;">
                                        <tr>
                                            <td>
                                                <i><asp:Label runat="server" ID="lblDisplayCount" Text="<%# Container.ItemIndex + 1 %>"></asp:Label></i><br />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td width="35px">
                                                <asp:Label runat="server" ID="lblCabinNumber" Text="<%# Container.Dataitem().CabinNumber %>"></asp:Label><br />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:CheckBox runat="server" ID="chkCabinSelected" Checked="false" />                                                
                                            </td>
                                        </tr>
                                    </table>
                                </ItemTemplate>
                            </asp:DataList>

In my code behind I have:
Private Sub dlCabins_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlCabins.ItemDataBound
            Select Case e.Item.ItemType
                Case ListItemType.Header
                Case ListItemType.AlternatingItem, ListItemType.Item
                    Select Case _enmMode
                        Case enumScreenMode.modeEditBasket
                            Dim checkbox As CheckBox
                            checkbox = e.Item.FindControl("chkCabinSelected")

                            checkbox.Attributes.Add("onclick", "CheckSingleCheckbox(this)")

                        Case enumScreenMode.modeToursBooking
                            'todo add script to constrain number of selections to _intNoCabinsRequired
                    End Select
            End Select
        End Sub

As you can see I add on the onclick attribute to calling my function passing in the checkbox itself.

What I need to do is also pass in a value from the data that I am binding,

So that whereas in my datalist i use:
<asp:Label runat="server" ID="lblCabinNumber" Text="<%# Container.Dataitem().CabinNumber %>"></asp:Label><br />
for instance.....

I need to pass - <%# Container.Dataitem().CruiseCabin_ID %> into the javascript function.

So how can i do this in the code behind at line:
checkbox.Attributes.Add("onclick", "CheckSingleCheckbox(this)")


scm0smlAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Oliver AmayaEntrepeneurCommented:
Hi, I think this should be what you need:
Private Sub dlCabins_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlCabins.ItemDataBound
 
  Dim drv as DataRowView = CType(e.Item.DataItem, DataRowView) ' <-- Added this '
 
  Select Case e.Item.ItemType
    Case ListItemType.Header
    Case ListItemType.AlternatingItem, ListItemType.Item
      Select Case _enmMode
        Case enumScreenMode.modeEditBasket
          Dim checkbox As CheckBox
          checkbox = e.Item.FindControl("chkCabinSelected")
 
          checkbox.Attributes.Add("onclick", "CheckSingleCheckbox(this, " & drv("CruiseCabin_ID") & ")") ' <-- Added this '
 
        Case enumScreenMode.modeToursBooking
          'todo add script to constrain number of selections to _intNoCabinsRequired '
      End Select
  End Select
End Sub

Open in new window

0
scm0smlAuthor Commented:
I am binding a list of my own objects to the data list.

So I am getting the erro:
System.InvalidCastException: Unable to cast object of type 'Comtec.Travelink82.Libraries.TLDataObjects.ComponentSetUp.Tours.Cruise.CruiseCabinOnToursInd' to type 'System.Data.DataRowView'.
   at Comtec.Travelink82.Application.Booking.TailorMade.Cruise.CharterCruiseCabinSelect.dlCabins_ItemDataBound(Object sender, DataListItemEventArgs e)
   at System.Web.UI.WebControls.DataList.OnItemDataBound(DataListItemEventArgs e)
   at System.Web.UI.WebControls.DataList.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem)
   at System.Web.UI.WebControls.DataList.CreateControlHierarchy(Boolean useDataSource)
   at System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e)
   at System.Web.UI.WebControls.BaseDataList.DataBind()
   at Comtec.Travelink82.Application.Booking.TailorMade.Cruise.CharterCruiseCabinSelect.LoadScreen()"
0
scm0smlAuthor Commented:
any ideas?
0
Oliver AmayaEntrepeneurCommented:
ok, maybe this would work?
Dim drv as CruiseCabinOnToursInd = CType(e.Item.DataItem, CruiseCabinOnToursInd)}
checkbox.Attributes.Add("onclick", "CheckSingleCheckbox(this, " & drv.CruiseCabin_ID & ")") '

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
scm0smlAuthor Commented:
yep worked fine, thanks for that!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.