找不到一个中继器的链接按钮 [英] Can't find a link button in a repeater

查看:143
本文介绍了找不到一个中继器的链接按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一对夫妇数据绑定字段的中继器的链接按钮。我试图让我在哪里可以数据绑定但每次我尝试访问该链接按钮,我不断收到空返回之后设置按钮的OnClientClick。

I have a link button in a repeater with a couple of databound fields. I'm trying to get to where I can set the buttons onClientClick after the databinding however everytime I try to access the link button I keep getting Null returned.

我已经通过涉及中继器和控制这里的每一个问题,看了看,一直没能弄明白。

I've looked through every single question involving repeaters and controls here and haven't been able to figure it out.

在.aspx

    <asp:Repeater ID="DailyRepeater" OnItemCommand="DailyRepeater_ItemCommand" runat="server">
                    <HeaderTemplate>
                        <tr>
                            <td class="coltitle">
                                Time
                            </td>
                            <td class="coltitle">
                                Activity
                            </td>
                            <td class="coltitle">
                                Hours
                            </td>
                        </tr>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <tr class="evenrow">
                            <td>
                                <%# Eval("StartTime","{0:HH:mm}") %>-<%# Eval("EndTime","{0:HH:mm}") %>
                            </td>
                            <td>
                                <%# Eval("Description") %>
                            </td>
                            <td>
                                <%# Eval("Hours","{0:0.0}") %>
                            </td>
                            <td>
                                   <asp:LinkButton runat="server" CausesValidation="false" ID="editbutton" Text="Edit">Edit</asp:LinkButton>
                            </td>
                        </tr>
                    </ItemTemplate>

在.aspx.cs

The .aspx.cs

    protected void DailyRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        LinkButton myButton = (LinkButton)e.Item.FindControl("editbutton");
        myButton.OnClientClick = (popupWindow.GetTargetPopupCode("URL");
    }

从我读过,我应该能够得到使用RepeaterItemEventargs按钮。不过,我似乎无法在这里找到它。我想起了另一件事是不是由这件事发生的时间(这是没有意义是因为这是一个数据绑定的事件)发生的结合,但由于某种原因,e的回来e.Item有一个零和的DataItem的-1的ItemIndex ...

From what I've read, I should have been able to get to the button using the RepeaterItemEventargs. However I can't seem to find it here. The other thing I thought of was that the binding wasn't happening by the time this happened (which made no sense to be as this is a databound event) but for some reason e is coming back e.Item has a dataItem of null and an itemIndex of -1...

我只是真的很困惑,失去了任何帮助将大大AP preciated。

I'm just really confused and lost any help would be greatly appreciated.

谢谢!

推荐答案

这听起来像你还没有对项目类型把守。通常情况下,它触发头,所有的项目,然后页脚。你需要做的是:

It sounds like you haven't guarded against the item type. Typically, it fires the header, all the items, and then the footer. You need to do this:

 if(e.Item.ItemType == ItemType.Item || e.Item.ItemType == ItemType.AlternatingItem)
 {
      LinkButton myButton = (LinkButton)e.Item.FindControl("editbutton");
      myButton.OnClientClick = (popupWindow.GetTargetPopupCode("URL");
 }

这篇关于找不到一个中继器的链接按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆