views:

385

answers:

1

I have a datalist like this:

 <asp:DataList ID="dl" runat="server" Width="301px" onitemcommand="dl_ItemCommand">
     <ItemTemplate>
      <table style="border:solid 1 #CCCCCC" >
             <tr align="left">
               <td align="left">
              <img id="imgPhoto" runat="server"
               alt="Company Logo"
               border="0" 
               align="middle"
               style="border:solid 5px #CCCCCC;height:10px"src='<%#GetImage(Eval("ImageName")) %>'
                                                            />
   <asp:HiddenField id="hdnImg" runat="server" Value='<%#Eval("ImageName") %>'/>
        </td>
         </tr>
     <tr align="center">
       <td align="center">


 <asp:LinkButton ID="lnkChangeLogo" runat="server"                                                                    Text="ChangeLogo" OnClientClick="javascript:showLayerUpLoad();return  false;">       </asp:LinkButton>
    <br />
    <asp:LinkButton ID="lnkRemoveLogo" runat="server"                                                               Text="RemoveLogo"  OnClientClick="javascript:ConfirmChoice();return false;"/>
                                        </td>
                                </tr>
                            </table>                   
                    </ItemTemplate>

                </asp:DataList>

I want to pass src of imagePhoto to function showLayerUpLoad().How can i do that.Can i do this in ItemCreated event.Can anybody help?showLayerUpLoad() is fn in javascript to show popup.

+1  A: 

Hi. One thing you can do this modify the javascript function a bit. Let it take one argument.

function showLayerUpLoad(ctrlid)
{
myctrl = document.getElementById(ctrlid); //now you have a reference to your control

alert(myctrl.value); //assuming its a hidden field  control with some value in it.
}

In your code behind handle the datalist's item databound event:

 Sub Item_Bound(sender As Object, e As DataListItemEventArgs) Handles DataList1.ItemDataBound

     If e.Item.ItemType = ListItemType.Item Or _
         e.Item.ItemType = ListItemType.AlternatingItem Then


        'Retrieve the hidden control in the current DataListItem.
        Dim hf As HiddenField = _
            CType(e.Item.FindControl("YourHiddenFieldID"), HiddenField)

   'Retrieve the link button in the current DataListItem.
        Dim lb As Hidden Field = _
            CType(e.Item.FindControl("YourLinkButtonID"), LinkButton)

        lb.OnClientClick = string.Format("javascript:ShowLayerUpLoad('{0}')", hf.ClientID)


     End If

  End Sub

Hope this helps.

deostroll