为什么OnRowEditing是必需的,即使它没有逻辑?

时间:2015-08-24 10:42:17

标签: c# asp.net gridview

使用命令EDIT的按钮区域在我输入

之前不起作用
OnRowEditing="grdviewContractorTypes_RowEditing"

问题:

我写了这段代码

<asp:GridView runat="server" ID="grdviewContractorTypes" OnRowEditing="grdviewContractorTypes_RowEditing" OnRowCommand="grdviewContractorTypes_RowCommand" DataKeyNames="pk_ContractorTypes_ContractorTypeID" AutoGenerateColumns="false" CssClass="table table-condensed table-bordered table-striped table-responsive">
                                        <Columns>
                                            <asp:BoundField DataField="pk_ContractorTypes_ContractorTypeID" HeaderText="ID" />
                                            <asp:BoundField DataField="ContractorTypeName" HeaderText="Contractor Type" />
                                            <asp:ButtonField CommandName="edit" ImageUrl="~/assets/global/images/shopping/edit.png" ButtonType="Image" ControlStyle-Width="25px" ControlStyle-Height="25px" />


                                        </Columns>
                                    </asp:GridView>

的.cs

protected void grdviewContractorTypes_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "edit")
            {
                byte ContractorTypeID = Convert.ToByte(grdviewContractorTypes.DataKeys[Convert.ToInt32(e.CommandArgument)].Value);

                //HFActID.Value = ID.ToString();

                btnAddContractorType.Visible = false;
                btnUpdated.Visible = true;

                DataTable dt = MngContractorTypes.SelectContractorTypesByContractorTypeID(ContractorTypeID);
                DataRow r = dt.Rows[0];

                txtBoxContractorTypeName.Text = r["ContractorTypeName"].ToString();
                HdnFieldContractorTypeID.Value = r["pk_ContractorTypes_ContractorTypeID"].ToString();
                //txtSearch.Text = "Testing...";
                //Response.Write("DONE");

            }
        }
        catch (Exception ex)
        {
            Response.Write(Convert.ToString(ex.Message));
        }
    }

当我在DEBUGGER中使用'edit'命令单击按钮字段但在实际屏幕上没有做任何事情时,上面的代码会运行,直到我把它放到这里。

protected void grdviewContractorTypes_RowEditing(object sender, GridViewEditEventArgs e)
{

}

0 个答案:

没有答案