?
Solved

adding some data from my databind into a javascript function

Posted on 2008-01-25
5
Medium Priority
?
417 Views
Last Modified: 2012-06-21
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)")


0
Comment
Question by:scm0sml
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:Oliver Amaya
ID: 20745418
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
 

Author Comment

by:scm0sml
ID: 20746091
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
 

Author Comment

by:scm0sml
ID: 20746095
any ideas?
0
 
LVL 10

Accepted Solution

by:
Oliver Amaya earned 2000 total points
ID: 20746140
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
 

Author Comment

by:scm0sml
ID: 20746652
yep worked fine, thanks for that!!
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…
Get the source code for a fully functional Access application shell with several popular security features that Access VBA application developers desire, but find difficult or impossible to figure out how to code. You get the source code for managi…

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question