我有一个添加按钮外的Repeater控制。当ADD IS点击一个新行插入到数据库和数据绑定到中继器。 点击添加按钮我想要一个链接按钮显示在中继器的新行中。中继器按钮点击
在此先感谢您的帮助。
DirectCast(e.Item.FindControl("lnksave"), LinkButton).Visible = True
此代码我不能放置在我的ADD按钮的单击事件。我应该做什么来显示新创建的行中的链接按钮。
我有一个添加按钮外的Repeater控制。当ADD IS点击一个新行插入到数据库和数据绑定到中继器。 点击添加按钮我想要一个链接按钮显示在中继器的新行中。中继器按钮点击
在此先感谢您的帮助。
DirectCast(e.Item.FindControl("lnksave"), LinkButton).Visible = True
此代码我不能放置在我的ADD按钮的单击事件。我应该做什么来显示新创建的行中的链接按钮。
我会成立的LinkButton的财产Visible="false"
在标记:
<asp:Repeater ...
... ... ...
<ItemTemplate>
<asp:LinkButton ID="lnksave" runat="server" Visible="false">LinkButton</asp:LinkButton>
</ItemTemplate>
在代码的网页水平落后声明标志:
Dim btnClicked As Boolean = False
在添加按钮的事件方法设置该标志为true。然后绑定数据中继:
Protected Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
btnClicked = True
BindRepeater() 'your method to data bind repeater
End Sub
在直放站的项目数据绑定事件方法检查标志,并设置相应的链接按钮的Visible属性:
Protected Sub Repeater1_ItemDataBound(sender As Object, e As RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim lnksave As LinkButton = DirectCast(e.Item.FindControl("lnksave"), LinkButton)
lnksave.Visible = btnClicked
End If
End Sub
谢谢。当我点击添加我可以在新创建的行中显示保存链接按钮[但它显示给所有其他行]。我希望它在新创建的行只有 – user2797643
感谢你afzalulh。 – user2797643
它工作正常 – user2797643
还有,你试过这么远吗? StackOverflow不是一个神奇的代码工厂,你需要表明你已经付出了一些努力来解决你自己的问题,并向我们强调你使用该解决方案时遇到的具体问题。关于[如何提问](http://stackoverflow.com/questions/how-to-ask)上的文章通常是一个很好的指南。 – Adrian
阿德里安,这是我试过。谢谢 – user2797643