简体   繁体   English

如何设置填充复选框在网格视图中从动作按钮单击选中(true)

[英]how to set populate checkbox is checked(true) in gridview from action button click

I have a gridview with option checkbox. 我有一个带有选项复选框的gridview。 when i choose a row with checked checkbox and then i press button send to update data with parameter option checkbox is checked. 当我选择带有选中复选框的行,然后按按钮发送时,将选中带有参数选项复选框的更新数据。 and then my question is, how to set populate checkbox is checked(true) in gridview from action button click. 然后我的问题是,如何从动作按钮单击在gridview中选中(true)如何设置填充复选框。

this is my view. 这是我的看法。

<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>

this is my .cs 这是我的.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(); 
}

please give me solution. 请给我解决方案。 thanks. 谢谢。

This may not be the best answer for what you are working on, but here is one solution available. 对于您正在做的事情,这可能不是最佳答案,但是这里提供了一种解决方案。 If you are able to use AJAX calls on your website, and if you want to use a little JQuery below is one way to approach saving a list of values from checked grid view rows, in java script, then uses AJAX to send those IDs to your website to do something with the collection. 如果您可以在网站上使用AJAX调用,并且希望在下面使用一些JQuery,则可以使用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 
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM