触发按钮单击事件时禁用Gridview行

时间:2017-02-21 10:20:04

标签: c# asp.net gridview

我有一个Gridview,其中假设有4-5行,每行都有button

现在我想要的是,我想disable只触发点击按钮的那些行。

这是我的button事件代码,直到现在

protected void GetRowDataPay(object sender, CommandEventArgs e)
{
    int rowIndex = int.Parse(e.CommandArgument.ToString());

    Hashtable dataItemPay = GridPayInfo.Rows[rowIndex].ToHashtable() as Hashtable;

    if (ObjPriCon.State != ConnectionState.Open)
    {
        ObjPriCon.Open();
        OracleCommand cmdMkeyPay = new OracleCommand("select XXCUS.XXACL_LAND_PURC_INV_VIEW_MKEY.nextval from dual", ObjPriCon);
        string MkeyPay = Convert.ToString(cmdMkeyPay.ExecuteOracleScalar());

        OracleCommand cmdORGID = new OracleCommand("select XXCUS.XXACL_LAND_PURC_INV_VIEW_MKEY.nextval from dual", ObjPriCon);
        string ORG_IDKEY = CF.ExecuteScaler2("select ORGANIZATION_ID,ORGANIZATION_NAME from apps.xxacl_company_mst where ORGANIZATION_NAME = '" + txtCompName.Value + "'");

        string strExpQuery = "insert into XXCUS.XXACL_LAND_PURC_INVOICE_VIEW (MKEY,REF_PURCHASE_ID,REF_SR_NO, " +
                         "REF_PURHCASE_TYPE,ORG_ID,PROJECT_ID,TALUKA_ID,VILLAGE_ID,SURVEY_AREA_7_12,DOC_NO,INVOICE_ID,INVOICE_NUM,VENDOR_ID, " +
                         "VENDOR_NAME,INVOICE_AMT,BATCH_ID,BATCH_NAME,EXP_ID,EXP_TYPE,REMARKS,CREATED_BY, " +
                         "CREATION_DATE,LAST_UPDATE_DATE,LAST_UPDATED_BY, EXP_ORG_ID, EXP_ORG_NAME) values (" + MkeyPay + "," + StrMkey + "," +
                         "" + dataItemPay["SR_NO"] + ", '" + dataItemPay["ATTRIBUTE1"] + "'," + ORG_IDKEY + "," + ddlProject.SelectedValue + "," +
                         "" + ddlTaluka.SelectedValue + "," + ddlVillage.SelectedValue + ", '" + txt712.Text + "', '" + txtdocno.Value + "'," + "NULL" + "," + "NULL" + "," +
                         "" + dataItemPay["ORACLE_VEND_ID"] + ", '" + dataItemPay["ORACLE_VEND_NAME"] + "', " + dataItemPay["PAID_AMT"] + "," + dataItemPay["BATCH_ID"] + "," +
                         "'" + dataItemPay["BATCH_NAME"] + "', " + dataItemPay["EXP_ID"] + ", '" + dataItemPay["EXP_TYPE"] + "', '" + dataItemPay["REMARKS"] + "', " +
                         "" + Request.QueryString["userid"].ToString() + ", sysdate, sysdate, " +
                         "'" + Request.QueryString["userid"].ToString() + "', " + dataItemPay["EXP_ORG_ID"] + ", '" + dataItemPay["EXP_ORG_NAME"] + "')";

        OracleCommand cmdQuery = new OracleCommand(strExpQuery, ObjPriCon);
        cmdQuery.ExecuteNonQuery();
        ObjPriCon.Close();
        ScriptManager.RegisterStartupScript(this, this.GetType(), "Success", "alert('Payment Invoice inserted into table successfully');", true);
    }
}

另见gridview的aspx

<cc1:Grid ID="GridPayInfo" runat="server" FolderStyle="../Styles/Grid/style_12" AllowAddingRecords="true"
                        AutoGenerateColumns="false" Width="100%" ShowFooter="true" ShowHeader="true"
                        PageSize="50" OnInsertCommand="GridPayInfo_InsertCommand" OnRebind="GridPayInfo_Rebind"
                        OnRowDataBound="GridPayInfo_RowDataBound" OnUpdateCommand="GridPayInfo_UpdateCommand"
                        OnDeleteCommand="GridPayInfo_DeleteCommand">
                        <ClientSideEvents OnClientAdd="GridPayInfo_ClientAdd" OnClientEdit="GridPayInfo_OnClientEdit"
                            OnClientDblClick="GridPayInfo_OnClientDblClick" OnClientInsert="GridPayInfo_ClientInsert"
                            OnClientUpdate="GridPayInfo_ClientUpdate" OnBeforeClientInsert="GridPayInfo_BeforeClientInsert" />
                        <TemplateSettings RowEditTemplateId="tplRowEdit2" />
                        <Columns>
                            <cc1:Column ID="Column37" DataField="MKEY" ReadOnly="true" Width="0%" runat="server"
                                Visible="false">
                                <TemplateSettings TemplateId="gtchkConfirm" HeaderTemplateId="HTConfirm" />
                            </cc1:Column>
                            <cc1:Column Wrap="true" DataField="SR_NO" ReadOnly="true" HeaderText="Sr No" Width="4%"
                                ID="Column9">
                                <TemplateSettings RowEditTemplateControlId="txtsrnopay" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column Wrap="true" DataField="TYPE_ID" HeaderText="Type" Width="0%" ID="Column42"
                                Visible="false">
                            </cc1:Column>
                            <cc1:Column Wrap="true" DataField="TYPE" HeaderText="Type" Width="6%" ID="Column10">
                                <TemplateSettings RowEditTemplateControlId="cmbExpTypePay" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column Wrap="true" DataField="STAGE" HeaderText="Stage" Width="7%" ID="Column6">
                                <TemplateSettings RowEditTemplateControlId="ddlStageTypePayment" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column Wrap="true" DataField="VENDOR_NAME" HeaderText="Party Name" Width="9%"
                                ID="Column11">
                                <TemplateSettings RowEditTemplateControlId="txtPartynamePay" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column Wrap="true" DataField="AGRMT_AMT" HeaderText="Agreement Amt" Width="7%"
                                ID="Column12">
                                <TemplateSettings RowEditTemplateControlId="txtAggamt" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column Wrap="true" DataField="PAYABLE_AMT" HeaderText="Payable Amt" Width="7%"
                                ID="Column14">
                                <TemplateSettings RowEditTemplateControlId="txtPayamt" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column Wrap="true" DataField="PAID_AMT" HeaderText="Paid Amt" Width="6%" ID="Column16"
                                Visible="true">
                                <TemplateSettings RowEditTemplateControlId="txtpaidAmt" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column Wrap="true" DataField="REMARKS" HeaderText="Remarks" Width="7%" ID="Column38">
                                <TemplateSettings RowEditTemplateControlId="txtRempay" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column Wrap="true" DataField="EXP_TYPE_E_ID" HeaderText="Expense Type" Width="0%"
                                ID="Column13" Visible="false">
                            </cc1:Column>
                            <cc1:Column Wrap="true" DataField="EXP_ID" HeaderText="Expense Type" Width="0%" ID="Column65"
                                Visible="false">
                            </cc1:Column>
                            <cc1:Column Wrap="true" DataField="EXP_TYPE" HeaderText="Expense Type" Width="10%"
                                ID="Column15">
                                <TemplateSettings RowEditTemplateControlId="ddlExpTypePay" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column Wrap="true" DataField="CHQ_FAV_NAME" HeaderText="Chq in Favor Name" Width="8%"
                                ID="Column40" Visible="false">
                                <TemplateSettings RowEditTemplateControlId="txtChqinFavname" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column Wrap="true" DataField="VOUCHER_NO" HeaderText="Voucher No" Width="7%"
                                ID="Column17">
                                <TemplateSettings RowEditTemplateControlId="txtVoucherno" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column Wrap="true" DataField="ORACLE_VEND_NAME" HeaderText="Oracle Vendor Name"
                                Width="9%" ID="Column55">
                                <TemplateSettings RowEditTemplateControlId="ddlOralceVendorName" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column Wrap="true" DataField="ORACLE_VENDOR_ID" Width="0%" Visible="false" ID="Column57">
                            </cc1:Column>
                            <cc1:Column Wrap="true" DataField="INVOICE_STATUS" HeaderText="Invoice Status" Width="6%"
                                ID="Column56">
                                <TemplateSettings RowEditTemplateControlId="txtInvoStat" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column Wrap="true" DataField="BATCH_NAME" HeaderText="Batch Name" Width="6%"
                                ID="Column61">
                                <TemplateSettings RowEditTemplateControlId="ddlBatchName" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column Wrap="true" DataField="BATCH_ID" Width="0%" Visible="false" ID="Column62">
                            </cc1:Column>
                            <cc1:Column Wrap="true" DataField="EXP_ORG_ID" Width="0%" Visible="false" ID="Column68">
                            </cc1:Column>
                            <cc1:Column Wrap="true" DataField="EXP_ORG_NAME" Visible="false" HeaderText="Exp Org Name"
                                Width="0%" ID="Column69">
                                <TemplateSettings RowEditTemplateControlId="ddlPayExpOrgName" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column Wrap="true" DataField="CHEQUE_NO" HeaderText="Chq No" Width="6%" ID="Column39"
                                Visible="false">
                                <TemplateSettings RowEditTemplateControlId="txtchqno" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column Wrap="true" DataField="CHEQUE_DT" DataFormatString="{0:dd-MM-yyyy}" HeaderText="Chq Date"
                                Width="5%" ID="Column18" Visible="false">
                                <TemplateSettings RowEditTemplateControlId="txtchqdate" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <%--<cc1:Column Wrap="true" Visible="false" DataField="ATTACHMENT" HeaderText="Attachment"
                                Width="9%" ID="Column16">
                                <TemplateSettings RowEditTemplateControlId="flPayattach" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>--%>
                            <cc1:Column Wrap="true" HeaderText="Generate Invoice" Width="12%" ID="Column45">
                                <TemplateSettings TemplateId="btnPayInvoice" />
                            </cc1:Column>
                            <cc1:Column AllowDelete="true" Width="70px">
                            </cc1:Column>
                        </Columns>
                        <Templates>
                            <cc1:GridTemplate runat="server" ID="tplRowEdit2">
                                <Template>
                                    <table class="rowEditTable">
                                        <tr>
                                            <td valign="top">
                                                <fieldset style="width: 800px; height: 310px;">
                                                    <legend>Payment Information</legend>
                                                    <table cellpadding="2" cellspacing="2" border="0">
                                                        <tr>
                                                            <td style="display: none;">
                                                                Sr No:
                                                            </td>
                                                            <td>
                                                                <input type="text" id="txtsrnopay" style="width: 150px; display: none;" class="ob_gEC" />
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>
                                                                Type:
                                                            </td>
                                                            <td>
                                                                <asp:DropDownList ID="cmbExpTypePay" runat="server" DataSourceID="sd_Type_2" DataTextField="TYPE_DESC"
                                                                    DataValueField="TYPE_DESC" Width="200px">
                                                                    <asp:ListItem Value="--Select--">--Select--</asp:ListItem>
                                                                </asp:DropDownList>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>
                                                                Party Name:
                                                            </td>
                                                            <td>
                                                                <%--<input type="text" id="txtPartynamePay" style="width: 250px; height: 18px; font-size: 11px;"
                                                                    class="ob_gEC" />--%>
                                                                <%--<asp:DropDownList ID="txtPartynamePay" runat="server" Width="200px" Height="18px"
                                                                    CssClass="ob_gEC">
                                                                </asp:DropDownList>--%>
                                                                <select id="txtPartynamePay" runat="server" style="width: 200px; height: 18px;" />
                                                            </td>
                                                            <td>
                                                                Stage :
                                                            </td>
                                                            <td>
                                                                <asp:DropDownList ID="ddlStageTypePayment" runat="server" DataSourceID="sd_Type_Stage"
                                                                    DataTextField="STAGE" DataValueField="STAGE" Width="250px">
                                                                </asp:DropDownList>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>
                                                                Agreement Amt:
                                                            </td>
                                                            <td>
                                                                <input type="text" id="txtAggamt" style="width: 150px; height: 18px; font-size: 11px;"
                                                                    class="ob_gEC" onblur="return validatefunAgrment(this);" onkeypress='return NumeralsOnly(event);' />
                                                                <%--onchange="validatefun(this);"--%>
                                                            </td>
                                                            <td>
                                                                Payable Amt:
                                                            </td>
                                                            <td>
                                                                <input type="text" id="txtPayamt" name="amountPay" style="width: 150px; height: 18px;
                                                                    font-size: 11px;" class="ob_gEC" onkeypress='return NumeralsOnly(event);' />
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>
                                                                Paid Amount :
                                                            </td>
                                                            <td>
                                                                <input type="text" id="txtpaidAmt" name="amountPay" style="width: 150px; height: 18px;
                                                                    font-size: 11px;" class="ob_gEC" onblur="return validatefunPaid(this);" onkeypress='return NumeralsOnly(event);' />
                                                                <%--onblur="return validatefunPaid(this);"--%>
                                                            </td>
                                                            <td>
                                                                Remarks:
                                                            </td>
                                                            <td>
                                                                <asp:TextBox ID="txtRempay" runat="server" Width="200" Height="50" Style="font-size: 11px;"
                                                                    CssClass="ob_gEC" TextMode="MultiLine"></asp:TextBox>
                                                            </td>
                                                        </tr>
                                                        <tr style="display: none;">
                                                            <td>
                                                                Chq in Favor name:
                                                            </td>
                                                            <td>
                                                                <input type="text" id="txtChqinFavname" style="width: 250px; height: 18px; font-size: 11px;"
                                                                    class="ob_gEC" />
                                                            </td>
                                                        </tr>
                                                        <%--<td>
                                                                Attachment:
                                                            </td>
                                                            <td>
                                                                <input type="file" id="flPayattach" style="width: 300px; height: 18px; font-size: 11px;"
                                                                    class="ob_gEC" />--%>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                Expense Type:
                                            </td>
                                            <td>
                                                <asp:DropDownList ID="ddlExpTypePay" runat="server" DataSourceID="sd_Type_EXP" DataTextField="DESCRIPTION"
                                                    DataValueField="DESCRIPTION" Width="250px">
                                                    <asp:ListItem Value="--Select--">--Select--</asp:ListItem>
                                                </asp:DropDownList>
                                            </td>
                                        </tr>
                                        <%--<tr style="border: solid; border-width: 1px 0; width:100%;">
                                                                </tr>--%>
                                        <tr>
                                            <td>
                                                Voucher No:
                                            </td>
                                            <td>
                                                <input type="text" id="txtVoucherno" style="width: 150px; height: 18px; font-size: 11px;"
                                                    class="ob_gEC" />
                                            </td>
                                        </tr>
                                        <tr style="display: none;">
                                            <td>
                                                Chq No:
                                            </td>
                                            <td>
                                                <input type="text" id="txtchqno" style="width: 150px; height: 18px; font-size: 11px;"
                                                    class="ob_gEC" />
                                            </td>
                                            <td>
                                                Chq date:
                                            </td>
                                            <td>
                                                <input type="text" id="txtchqdate" style="width: 150px; height: 18px; font-size: 11px;"
                                                    class="ob_gEC" />
                                                (dd/MM/yyyy)
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                Oracle Vendor Name:
                                            </td>
                                            <td>
                                                <asp:DropDownList ID="ddlOralceVendorName" runat="server" DataSourceID="sd_Type_Vendor_Name"
                                                    DataTextField="vendor_name" DataValueField="vendor_name" Width="250px">
                                                    <asp:ListItem Value="--Select--">--Select--</asp:ListItem>
                                                </asp:DropDownList>
                                            </td>
                                            <td>
                                                Invoice Status:
                                            </td>
                                            <td>
                                                <input type="text" id="txtInvoStat" style="width: 150px; height: 18px; font-size: 11px;"
                                                    class="ob_gEC" readonly="readonly" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                Batch Name:
                                            </td>
                                            <td>
                                                <asp:DropDownList ID="ddlBatchName" runat="server" DataSourceID="sd_Type_Batch_Name"
                                                    DataTextField="BATCH_NAME" DataValueField="BATCH_NAME" Width="200px">
                                                    <asp:ListItem Value="--Select--">--Select--</asp:ListItem>
                                                </asp:DropDownList>
                                            </td>
                                        </tr>
                                        <tr style="display: none;">
                                            <td>
                                                Exp Org Name:
                                            </td>
                                            <td>
                                                <asp:DropDownList ID="ddlPayExpOrgName" runat="server" DataSourceID="sd_Type_ORG_Name"
                                                    DataTextField="NAME" DataValueField="NAME" Width="200px">
                                                    <asp:ListItem Value="--Select--">--Select--</asp:ListItem>
                                                </asp:DropDownList>
                                            </td>
                                        </tr>
                                    </table>
                                    </fieldset> </td> </tr>
                                    <tr>
                                        <td colspan="2" align="center">
                                            <input type="button" value="Save" onclick="GridPayInfo.save()" class="button" />
                                            <input type="button" value="Cancel" onclick="GridPayInfo.cancel()" class="button" />
                                        </td>
                                    </tr>
                                    </table>
                                </Template>
                            </cc1:GridTemplate>
                        </Templates>
                        <Templates>
                            <cc1:GridTemplate runat="server" ID="btnPayInvoice">
                                <Template>
                                    <%--<input id="btnPayGenInvoice" type="button" runat="server" value="Invoice" style="width: 80px;" />--%>
                                    <asp:Button ID="btnPayGenInvoice" runat="server" Text="Invoice" Width="80px" OnCommand="GetRowDataPay"
                                        CommandArgument='<%# Container.PageRecordIndex %>' />
                                </Template>
                            </cc1:GridTemplate>
                        </Templates>
                        <%-- <Templates>
                            <cc1:GridTemplate runat="server" ID="tplNumbering2">
                                <Template>
                                    <b>
                                        <%# (Container.RecordIndex + 1) %></b>
                                </Template>
                            </cc1:GridTemplate>
                        </Templates>--%>
                    </cc1:Grid>

2 个答案:

答案 0 :(得分:2)

如果要禁用单击按钮的行,我将使用此方法:

protected void btnPayGenInvoice_Click(object sender, EventArgs e)
{
    GridViewRow row = (GridViewRow)((Button) sender).NamingContainer;
    row.Enabled = false;
}

因此,使用相同的处理程序处理所有按钮的按钮单击事件。

答案 1 :(得分:0)

您的java脚本代码应如下所示:

<script language="javascript">
    function selectMe(obj)
        {
        obj.style.backgroundColor="beige";
        obj.style.disabled=true;
        obj.style.cursor='default';
        }
</script>

然后在网格视图中添加RowDataBound事件。

<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound"
        OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
    </asp:GridView>

在代码背后,你必须在事件上编写以下代码。

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        GridViewRow tr = e.Row;
        tr.Attributes.Add("onClick", "javascript:selectMe(this);");
        tr.Attributes.Add("style", "cursor:hand;");
    }
}