我有一个GridView表,数据源来自数据库。 GridView的第一列是一个复选框,复选框用户可以选中复选框。我不确定我哪里做错了,我的代码无法获得我勾选的复选框。
<!DOCTYPE html>
我的c#
<div id="UserFrom" class="form-horizontal" runat="server">
<h4>Add Training</h4>
<hr />
<div class="alert alert-info" style="display: none;">
<button data-dismiss="alert" class="close" type="button">×</button>
</div>
<div class="form-group">
<label for="inputCode" class="col-sm-2 control-label">Training Code</label>
<div class="col-sm-3">
<asp:DropDownList ID="ddlRole" runat="server" CssClass="form-control" ValidationGroup="G1" required></asp:DropDownList>
</div>
</div>
<div class="col-md-6">
<asp:GridView ID="GrdRole" runat="server" CssClass="table table-striped table-bordered table-hover" EmptyDataText="No Records Found" DataKeyNames="RoleID"
AllowPaging="true" AutoGenerateColumns="false" AutoGenerateDeleteButton="false" RowStyle-HorizontalAlign="Left" OnPageIndexChanging="GrdRole_PageIndexChanging"
HeaderStyle-HorizontalAlign="Center" GridLines="None" PageSize="10" RowStyle-CssClass="gradeX" AlternatingRowStyle-CssClass="gradeA">
<columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkCtrl" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="EmployeeNo" HeaderText="EmployeeNo" />
</columns>
<PagerStyle HorizontalAlign="Right" CssClass="pagination-ys" />
</asp:GridView>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
<td>
<asp:Button ID="submit_button" Text="Check" CssClass="btn btn-success" runat="server" OnClick="checkOuput" />
</td>
</div>
</div>
</div>e
当我点击检查按钮时,我不确定我在哪里做错了弹出窗口是空的。请指导我,谢谢。
答案 0 :(得分:0)
使用GridView
page_load
!IsPostBack
绑定一次if (!IsPostBack)
{
BindGridView();
}
ViewStateMode="Disabled"
同时检查网页是否有ViewStateMode="Enabled"
,而不是使用public ActionResult Index()
{
ViewBag.menuItem = "DashBoard";
return View(db.jobs.ToList());
}