在C#
ASP.NET
我有html
页面,其中有buttons
(Button1,Button2 .. 。Button30)我想用循环禁用所有这些按钮,
喜欢Button [i] .enable = false
我该怎么做?
我从我的数据库中读取了buttons
的列表,我想要禁用那些(false)值。
protected void Page_Load(object sender, EventArgs e) {
DataSet.seatsDataTable seatDT = new DataSet.seatsDataTable();
DataSetTableAdapters.seatsTableAdapter seatTA = new DataSetTableAdapters.seatsTableAdapter();
seatTA.FillByAllSeatID(seatDT);
for(int i = 1; i < 29; i++) {
seatTA.FillBySeatIDfromUser(seatDT, i);
if (seatDT[0].SeatStatus == false) {
reserved.Text += ( seatDT[0].SeatID.ToString() + ",") ;
//Here i want to change button disable/enable status.
//like Button[i].enabled=false
}
}
}
HTML CODE:
<section id="banner">
<table class="auto-style1" style="align-self: center">
<tr>
<td>
<input id="Button1" type="button" runat="server" value="1" onclick="disable(1)" /></td>
<td>
<input id="Button2" type="button" runat="server" value="2" onclick="disable(2)" /></td>
<td>
<input id="Button3" type="button" value="3" runat="server" onclick="disable(3)" /></td>
<td>
<input id="Button4" type="button" value="4" runat="server" onclick="disable(4)" /></td>
<td> </td>
<td>
<input id="Button5" type="button" value="5" runat="server" onclick="disable(5)" /></td>
<td>
<input id="Button6" type="button" value="6" runat="server" onclick="disable(6)" /></td>
<td>
<input id="Button7" type="button" value="7" runat="server" onclick="disable(7)" /></td>
<td>
<input id="Button8" type="button" value="8" runat="server" onclick="disable(8)" /></td>
<td>
<input id="Button9" type="button" value="9" runat="server" onclick="disable(9)" /></td>
</tr>
<tr>
<td>
<input id="Button10" type="button" value="10" runat="server" onclick="disable(10)" /></td>
<td>
<input id="Button11" type="button" value="11" runat="server" onclick="disable(11)" /></td>
<td>
<input id="Button12" type="button" value="12" runat="server" onclick="disable(12)" /></td>
<td>
<input id="Button13" type="button" value="13" runat="server" onclick="disable(13)" /></td>
<td>
<input id="Button14" type="button" value="14" runat="server" onclick="disable(14)" /></td>
<td>
<input id="Button15" type="button" value="15" runat="server" onclick="disable(15)" /></td>
<td>
<input id="Button16" type="button" value="16" runat="server" onclick="disable(16)" /></td>
<td>
<input id="Button17" type="button" value="17" runat="server" onclick="disable(17)" /></td>
<td>
<input id="Button18" type="button" value="18" runat="server" onclick="disable(18)" /></td>
<td>
<input id="Button19" type="button" value="19" runat="server" onclick="disable(19)" /></td>
</tr>
<tr>
<td>
<input id="Button20" type="button" value="20" runat="server" onclick="disable(20)" /></td>
<td>
<input id="Button21" type="button" value="21" runat="server" onclick="disable(21)" /></td>
<td>
<input id="Button22" type="button" value="22" runat="server" onclick="disable(22)" /></td>
<td>
<input id="Button23" type="button" value="23" runat="server" onclick="disable(23)" /></td>
<td>
<input id="Button24" type="button" value="24" runat="server" onclick="disable(24)" /></td>
<td>
<input id="Button25" type="button" value="25" runat="server" onclick="disable(25)" /></td>
<td>
<input id="Button26" type="button" value="26" runat="server" onclick="disable(26)" /></td>
<td>
<input id="Button27" type="button" value="27" runat="server" onclick="disable(27)" /></td>
<td>
<input id="Button28" type="button" value="28" runat="server" onclick="disable(28)" /></td>
<td>
<input id="Button29" type="button" value="29" runat="server" onclick="disable(29)" /></td>
</tr>
</table>
答案 0 :(得分:0)
for (int i = 1; i < 10; i++)
{
Button b = this.FindControl("button" + i) as Button;
if (b != null)
b.Enabled = false;
}
。
using System.Web.UI.HtmlControls;
用于Html输入控件的Fix1和runat =&#34;服务器&#34;。
for (int i = 1; i < 10; i++)
{
HtmlInputButton b = this.FindControl("button" + i) as HtmlInputButton;
if (b != null)
b.Disabled = !b.Disabled;
}
SELECT concat('TRUNCATE TABLE ', TABLE_NAME, ';')
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME in ('table1','table2','table3')
答案 1 :(得分:0)
似乎所有按钮都在桌子内。
好的,我们禁用该表中的所有按钮。
首先在您的桌面上放置一个特定的ID,如下所示:
<table id="buttons-tbl" class="auto-style1" style="align-self: center">
然后,将此脚本放在表格的底部
<script type="text/javascript">
$("#buttons-tbl input[type=button]").prop("disabled", true);
</script>
当然,您需要在html中包含jquery库