我有一个带有选项复选框的 GridView 。当我选择带有选中复选框的行然后按下按钮 已选中使用参数选项复选框发送以更新数据。然后我的问题是 如何通过单击操作按钮在 gridview 中选中(真)填充复选框。
这是我的看法。
<asp:GridView runat="server" ID="gvInquiryDocument">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkAll" runat="server" onclick="checkAll(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="ChkSelect" runat="server" onclick="Check_Click(this)" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID" Visible="false">
<ItemTemplate>
<asp:TextBox ID="hdGetId" runat="server" Text='<%# Eval("ANO") %>'
Visible="false"></asp:TextBox>
<asp:TextBox ID="txtDeliveryBy" Visible="false" runat="server" Text='<%# Eval("DeliveryBy") %>'></asp:TextBox>
<asp:TextBox ID="txtPolicyNo" Visible="false" runat="server" Text='<%# Eval("PolicyNo") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
这是我的.cs
protected void btnSend_Click(object sender, EventArgs e)
{
DMSStatus dmsStatus = new DMSStatus();
foreach (GridViewRow di in gvInquiryDocument.Rows)
{
CheckBox chk = (CheckBox)di.FindControl("ChkSelect");
if (chk.Checked)
{
TextBox tx = (TextBox)di.FindControl("hdGetId");
var Ano = Server.HtmlDecode(tx.Text.Trim());
TextBox txtPolicyNo = (TextBox)di.FindControl("txtPolicyNo");
var PolicyNo = Server.HtmlDecode(txtPolicyNo.Text.Trim());
dmsStatus.ANO = Convert.ToInt16(Ano);
dmsStatus.PolicyNo = PolicyNo;
dmsStatus.UpdateData();
bindData();
//i want to set code after binddata....
}
}
}
private void bindData()
{
DMSStatus dmsStatus = new DMSStatus();
DataSet ds = dmsStatus.GetData();
gvInquiryDocument.DataSource = ds;
gvInquiryDocument.DataBind();
}
请给我解决方案。 谢谢。
最佳答案
对于您正在从事的工作,这可能不是最佳答案,但这是一个可用的解决方案。如果您能够在您的网站上使用 AJAX 调用,并且如果您想使用下面的一些 JQuery 是一种从已检查的 GridView 行中保存值列表的方法,在 java 脚本中,然后使用 AJAX 将这些 ID 发送到您的网站对集合做一些事情。
<script type="text/javascript">
function btnSend(sender, args){
var idCollection = new Array();
$('#<%=gvInquiryDocument.ClientID%>').find("input:checkbox").each(function () {
if (this.checked) {
//Find the ID value in the row by cell index
idCollection.push(this.parentElement.cells[3].innerHTML )
}
}
myWebServiceInterfaceClass.MyWebsiteServiceProxy.UpdateIdCollection(idCollection, SaveResults , ProxyCallFailed);
}
function SaveResults(results){
//If you want to send anything back to the site and do something after updating the ids
//Or just refresh the page and let the onload event repopulate your grid on postback
}
function ProxyCallFailed(){
//Something bad happened on your ajax call
}
关于c# - 如何通过单击操作按钮在 gridview 中设置填充复选框被选中(真),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34251728/