次のコードは、いくつかのチェックボックスを示しており、それらのいずれかを選択するとページにリストされます。"LinkButton"
問題は、リンクをクリックするとckeckboxが表示されるページで使用したいということです。で使用するOnLoad="Page_Edit"
と正常"asp:LinkButton"
にcheckboxlist
動作しますが、常に表示したくないのでcheckboxlist
、「クリックして作業する」チェックボックスをクリックして表示したいです。リンク。を使用するOnClick="Page_Edit"
と、チェックボックスのいずれかを選択して、がcheckboxlist
消えます。どんな助けでも大歓迎です。
<h3> CheckBoxList Constructor Example </h3>
<asp:LinkButton id="myid" runat="server" Text="Click to work with checkbox!" OnLoad="Page_Edit" OnClick="Page_Edit" /><br />
Select items from the CheckBoxList.
<br /><br />
<asp:PlaceHolder id="Place" runat="server"/>
<br /><br />
<asp:label id="Message" runat="server"/>
void Check_Clicked(オブジェクト送信者, EventArgs e) {
// Retrieve the CheckBoxList control from the Controls collection
// of the PlaceHolder control.
CheckBoxList checklist = (CheckBoxList)Place.FindControl("checkboxlist1");
// Make sure a control was found.
if(checklist != null)
{
Message.Text = "Selected Item(s):<br /><br />";
// Iterate through the Items collection of the CheckBoxList
// control and display the selected items.
for (int i=0; i<checklist.Items.Count; i++)
{
if (checklist.Items[i].Selected)
{
Message.Text += checklist.Items[i].Text + "<br />";
}
}
}
else
{
// Display an error message.
Message.Text = "Unable to find CheckBoxList control.";
}
}
void Page_Edit(Object sender, EventArgs e)
{
// Create a new CheckBoxList control.
CheckBoxList checklist = new CheckBoxList();
// Set the properties of the control.
checklist.ID = "checkboxlist1";
checklist.AutoPostBack = true;
checklist.CellPadding = 5;
checklist.CellSpacing = 5;
checklist.RepeatColumns = 2;
checklist.RepeatDirection = RepeatDirection.Vertical;
checklist.RepeatLayout = RepeatLayout.Flow;
checklist.TextAlign = TextAlign.Right;
// Populate the CheckBoxList control.
checklist.Items.Add(new ListItem("Item 1"));
checklist.Items.Add(new ListItem("Item 2"));
checklist.Items.Add(new ListItem("Item 3"));
checklist.Items.Add(new ListItem("Item 4"));
checklist.Items.Add(new ListItem("Item 5"));
checklist.Items.Add(new ListItem("Item 6"));
// Manually register the event-handling method for the
// SelectedIndexChanged event.
checklist.SelectedIndexChanged += new EventHandler(this.Check_Clicked);
// Add the control to the Controls collection of the
// PlaceHolder control.
Place.Controls.Add(checklist);
}