[英]Hide Panel in a datalist with Linkbutton and C# and javascript
[英]how to find linkbutton value on clicking checkbox in datalist using c#?
這是我所做的:
<ajaxToolkit:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0">
<ajaxToolkit:TabPanel ID="TabPanel1" runat="server" HeaderText="TabPanel1">
<HeaderTemplate>
Pro
</HeaderTemplate>
<ContentTemplate>
<div style="height: 100px; width: 200px; overflow: Auto">
<asp:DataList ID="DataList1" runat="server" CellPadding="2" CellSpacing="2" ForeColor="Red">
<ItemTemplate>
<asp:CheckBox ID="checkbox" runat="server" AutoPostBack="true" OnCheckedChanged="checkLike_CheckedChanged" />
<asp:LinkButton Text='<%#Eval("UPP")%>' ID="lnkpro" runat="server" CssClass="linkbutton"
OnClick="btn_Click" CommandArgument='<%# Eval("UCode") %>'></asp:LinkButton>
</ItemTemplate>
</asp:DataList>
</div>
</ContentTemplate>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel ID="TabPanel2" runat="server" HeaderText="services">
<HeaderTemplate>
Sets
</HeaderTemplate>
<ContentTemplate>
<div style="height: 100px; width: 200px; overflow: Auto">
<asp:DataList ID="DataList2" runat="server" CellPadding="2" CellSpacing="2">
<ItemTemplate>
<asp:CheckBox ID="checkbox" runat="server" />
<asp:LinkButton Text='<%#Eval("SNA")%>' ID="lnkpro1" runat="server" CssClass="linkbutton"
OnClick="btn_Click1" CommandArgument='<%# Eval("Code") %>'></asp:LinkButton>
</ItemTemplate>
</asp:DataList>
</div>
</ContentTemplate>
</ajaxToolkit:TabPanel>
</ajaxToolkit:TabContainer>
現在我的問題是:此代碼塊會在所有復選框前面顯示一個鏈接按鈕列表。 所以我想要的是在checkchanged復選框上獲取相應的linkbutton值。 可能嗎? 例如[[] linkbtn1 [] linkbtn2,當我在第一個復選框上選中時,應提取id而不是linkbutton1的文本。[[]是checkbox)
每個鏈接按鈕的ID在數據列表的每一行上都將是相同的,每個鏈接按鈕的文本值將是綁定到該鏈接按鈕的SNA
值。 您可以通過使用復選框的CheckChanged
事件來檢索該SNA
值,如下所示:
在DataList
的ItemTemplate
標記中:
<asp:CheckBox ID="checkbox" runat="server"
OnCheckedChanged="checkbox_CheckChanged" />
既然我們已經連接了check change事件,就該實現處理程序了,如下所示:
protected void checkbox_CheckChanged(object sender, EventArgs e)
{
CheckBox theCheckBox = sender as CheckBox;
// Make sure the cast to check box worked before we try to use it
if(theCheckBox != null)
{
LinkButton theLinkButton = theCheckBox.Parent.FindControl("lnkpro1") as LinkButton;
// Verify that the link button was found before we try to use it
if(theLinkButton != null)
{
// Get the text value from the link button in the same row
// as the check box checked changed
string theLinkButtonText = theLinkButton.Text;
// Do something with text value here
}
}
}
嘗試這個
protected void checkbox_CheckedChanged(object sender, EventArgs e)
{
foreach (DataListItem item in DataList1.Items)
{
CheckBox chk = (CheckBox)item.FindControl("checkbox");
LinkButton lnkbtnActivate = (LinkButton)item.FindControl("lnkpro");
if (chk.Checked == true)
{
string Result = lnkbtnActivate.Text;
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.