我試圖在綁定後在我的中繼器中製作特定標籤。 我不希望中繼器中的每個項目的所有標籤都可見。只需點擊按鈕即可。 當我點擊按鈕更新時,我正在更新我的數據庫中的我的錦標賽項目的信息,然後我想顯示一個標籤來表示更改是成功的,但僅限於我更新的項目。在綁定後在中繼器中製作特定標籤
這是後面的代碼。 [...]是我在數據庫中進行更新的位置
protected void repeatTourney_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "btnUpdate_Click")
{
[...]
Label lblSuccess= (Label)e.Item.FindControl("lblUpdateSuccess");
bindRepeater(ddlEvents.Text);
lblSuccess.Visible = true;
}
}
這裏是aspx。 [...]是包含我的數據庫項目信息的文本框和其他內容。
<asp:Repeater ID="repeatTourney" runat="server" OnItemDataBound="repeatTourney_ItemDataBound"
OnItemCommand="repeatTourney_ItemCommand">
<ItemTemplate>
<div class="form">
[...]
<asp:Label ID="lblUpdateSuccess" runat="server" Text="Update success" Visible="false" />
<asp:Button ID="btnUpdate" runat="server" Text="Update" CssClass="button" CommandName="btnUpdate_Click" />
[...]
</div>
</ItemTemplate>
</asp:Repeater>
最後,它應該是這樣的
Item
Info
BtnUpdate
lblSuccess.Visible = false
Item
Info
BtnUpdate <== Clicked
lblSuccess.Visible = true
謝謝你提供的任何幫助。
編輯:這是我bindRepeater代碼
private void bindRepeater(string name)
{
List<Tourney> list = TourneyDAL.GetByNameEvent(name);
[...]
repeatTournois.DataSource = list;
repeatTournois.DataBind();
[...]
}
編輯2: 感謝您的ID告訴哪一個需要結合後是可見的想法。
工作得很好。 :)
這裏我的新代碼
private void bindRepeater(string name, int index)
{
List<Tourney> list = TourneyDAL.GetByNameEvent(name);
[...]
repeatTourney.DataSource = list;
repeatTourney.DataBind();
[...]
if (index != 0)
{
Label lblReussie = (Label)repeatTourney.Items[index].FindControl("lblUpdateSuccess");
lblSuccess.Visible = true;
}
protected void repeatTourney_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "btnUpdate_Click")
{
[...]
Label lblSuccess= (Label)e.Item.FindControl("lblUpdateSuccess");
bindRepeater(ddlEvenements.Text, e.Item.ItemIndex);
lblSuccess.Visible = true;
}
}
}
您還沒有說過發生了什麼問題,您是否會發生異常?你可以使用'ItemDataBound'來設置可見性。但是,因此您必須存儲您上次更新的索引/標識,例如在一個字段中。 – 2013-02-18 15:25:17