如何将数据列表中的控件值传递给 JavaScript?

发布于 2024-08-01 22:40:51 字数 1632 浏览 5 评论 0原文

我有一个像这样的数据列表:

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

我想将 imagePhoto 的 src 传递给函数 showLayerUpLoad()。我该怎么做。我可以在 ItemCreated 事件中执行此操作吗?有人可以帮忙吗?showLayerUpLoad() 在 javascript 中是 fn 以显示弹出窗口。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴意少年 2024-08-08 22:40:51

你可以做的一件事是稍微修改一下 javascript 函数。 让它进行一个论证。

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

在后面的代码中处理数据列表的项目数据绑定事件:

 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

希望这有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文