Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
495 views
in Technique[技术] by (71.8m points)

c# - Disable Gridview row when button click event is fired

I have a Gridview in which suppose there are 4-5 rows and each row has its button.

Now what I want is, I want to disable only those rows whose button click is fired.

Here is my button event code till now

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);
    }
}

Also see the aspx of the gridview

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you want to disable the row of a button that was clicked i'd use this approach:

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

So handle the button-click event for all buttons with the same handler.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...