Gridview行不会保存在Modification上

时间:2016-10-18 04:56:42

标签: c# asp.net gridview

我有一个gridview,我第一次插入一行并保存。直到这个它按预期正常工作。

但是当我看到保存的数据,并想要修改/添加一个数据时,我收到错误

  

列' EXP_TYPE_ID'不属于桌子。

我不知道为什么它会给我这个错误,因为每当我添加新记录时它都会正确保存。

这是我的插入代码。

 protected void GrdPartyInfo_InsertCommand(object sender, GridRecordEventArgs e)
{
    int iRowCount = 0;

    if (Session["partyInfo"] != null)
    {
        dtPartyInfo = (DataTable)Session["partyInfo"];
    }
    else
    {
        BindDataTable();
    }

    iRowCount = dtPartyInfo.Rows.Count;
    DataRow newRow = dtPartyInfo.NewRow();
    newRow["SR_NO"] = iRowCount + 1;
    newRow["EXP_TYPE_ID"] = Convert.ToString(e.Record["EXP_TYPE"]);
    newRow["EXP_TYPE"] = CF.ExecuteScaler2("Select Type_desc from type_mst where Type_Code = 'PAR' and Type_Abbr ='" + Convert.ToString(e.Record["EXP_TYPE"]) + "'").ToString();
    newRow["TITLE"] = Convert.ToString(e.Record["TITLE"]);
    newRow["F_NAME"] = Convert.ToString(e.Record["F_NAME"]);
    newRow["M_NAME"] = Convert.ToString(e.Record["M_NAME"]);
    newRow["L_NAME"] = Convert.ToString(e.Record["L_NAME"]);
    newRow["GENDER"] = Convert.ToString(e.Record["GENDER"]);
    newRow["EMAIL_ID"] = Convert.ToString(e.Record["EMAIL_ID"]);       

    newRow["MOB_NUM"] = Convert.ToString(e.Record["MOB_NUM"]);

    newRow["PAN_NO"] = Convert.ToString(e.Record["PAN_NO"]);
    newRow["ADHAAR_NO"] = Convert.ToString(e.Record["ADHAAR_NO"]);
    newRow["ADDRESS"] = Convert.ToString(e.Record["ADDRESS"]);

    dtPartyInfo.Rows.Add(newRow);
    GrdPartyInfo.DataSource = dtPartyInfo;
    GrdPartyInfo.DataBind();
    AddToViewState("GrdPartyInfo");
}

和gridview的Aspx

<cc1:Grid ID="GrdPartyInfo" AllowDataAccessOnServer="true" runat="server" CallbackMode="true"
                        Serialize="true" FolderStyle="../Styles/Grid/style_12" AllowAddingRecords="true"
                        AutoGenerateColumns="false" Width="100%" ShowFooter="true" ShowHeader="true"
                        OnInsertCommand="GrdPartyInfo_InsertCommand" OnRebind="GrdPartyInfo_Rebind" OnRowDataBound="GrdPartyInfo_RowDataBound"
                        OnUpdateCommand="GrdPartyInfo_UpdateCommand">
                        <ClientSideEvents OnClientEdit="GrdPartyInfo_OnClientEdit" OnClientDblClick="GrdPartyInfo_OnClientDblClick" />
                        <TemplateSettings RowEditTemplateId="tplRowEdit" />
                        <Columns>
                            <cc1:Column ID="Column1" DataField="MKEY" ReadOnly="true" Width="0%" runat="server"
                                Visible="false">
                                <TemplateSettings TemplateId="gtchkConfirm" HeaderTemplateId="HTConfirm" />
                            </cc1:Column>
                            <cc1:Column ID="Column2" DataField="SR_NO" HeaderText="Sr No" Visible="true" Width="5%">
                                <TemplateSettings TemplateId="tplNumbering1" />
                            </cc1:Column>
                            <cc1:Column ID="Column41" DataField="EXP_TYPE_ID" HeaderText="Expense Type" Visible="false"
                                Width="10%">
                            </cc1:Column>
                            <cc1:Column ID="Column3" DataField="EXP_TYPE" HeaderText="Expense Type" Visible="true"
                                Width="10%">
                                <TemplateSettings RowEditTemplateControlId="cmbExpType" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column ID="Column4" DataField="TITLE" HeaderText="Title" Visible="true" Width="6%">
                                <TemplateSettings RowEditTemplateControlId="cmbTitle" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column ID="Column5" DataField="F_NAME" HeaderText="First Name" Visible="true"
                                Width="8%">
                                <TemplateSettings RowEditTemplateControlId="txtFname" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column ID="Column6" DataField="M_NAME" HeaderText="Middle Name" Visible="true"
                                Width="9%">
                                <TemplateSettings RowEditTemplateControlId="txtMname" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column ID="Column7" DataField="L_NAME" HeaderText="Last Name" Visible="true"
                                Width="8%">
                                <TemplateSettings RowEditTemplateControlId="txtLName" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column ID="Column8" DataField="GENDER" HeaderText="Gender" Visible="true" Width="7%">
                                <TemplateSettings RowEditTemplateControlId="cmbGender" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column ID="Column22" DataField="EMAIL_ID" HeaderText="Email Id" Visible="true"
                                Width="10%">
                                <TemplateSettings RowEditTemplateControlId="txtEmailid" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column ID="Column23" DataField="MOB_NUM" HeaderText="Mob No" Visible="true"
                                Width="8%">
                                <TemplateSettings RowEditTemplateControlId="txtMobNo" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column ID="Column33" DataField="PAN_NO" HeaderText="Pan No" Visible="true" Width="8%">
                                <TemplateSettings RowEditTemplateControlId="txtPanno" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column ID="Column34" DataField="ADHAAR_NO" HeaderText="Adhaar No" Visible="true"
                                Width="9%">
                                <TemplateSettings RowEditTemplateControlId="txtAdhaar" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column ID="Column35" DataField="ADDRESS" HeaderText="Address" Visible="true"
                                Width="12%">
                                <TemplateSettings RowEditTemplateControlId="txtAddress" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                            <cc1:Column ID="Column36" DataField="ATTACHMENT" HeaderText="Attachment" Visible="true"
                                Width="8%">
                                <TemplateSettings RowEditTemplateControlId="FlAttach" RowEditTemplateControlPropertyName="value" />
                            </cc1:Column>
                        </Columns>
                        <Templates>
                            <cc1:GridTemplate runat="server" ID="tplRowEdit">
                                <Template>
                                    <table class="rowEditTable">
                                        <tr>
                                            <td valign="top">
                                                <fieldset style="width: 900px; height: 250px;">
                                                    <legend>Party Information</legend>
                                                    <table cellpadding="2" cellspacing="2" border="0">
                                                        <tr>
                                                            <%--<td>
                                                                        Sr No:
                                                                    </td>
                                                                    <td>
                                                                        <input type="text" id="txtsrno" disabled="disabled" style="width: 150px;" class="ob_gEC" />
                                                                    </td>--%>
                                                            <td>
                                                                Type:
                                                            </td>
                                                            <td>
                                                                <asp:DropDownList ID="cmbExpType" runat="server" DataSourceID="sd_Type" DataTextField="TYPE_DESC"
                                                                    DataValueField="TYPE_ABBR" Width="150px">
                                                                    <asp:ListItem Value="--Select--">--Select--</asp:ListItem>
                                                                </asp:DropDownList>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>
                                                                Title:
                                                            </td>
                                                            <td>
                                                                <asp:DropDownList ID="cmbTitle" runat="server" DataSourceID="sd_Type_Title" DataTextField="TITLE"
                                                                    DataValueField="TITLE_CODE" Width="150px">
                                                                    <asp:ListItem Value="--Select--">--Select--</asp:ListItem>
                                                                </asp:DropDownList>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>
                                                                First Name:
                                                            </td>
                                                            <td>
                                                                <input type="text" id="txtFname" style="width: 150px; height: 18px; font-size: 11px;"
                                                                    class="ob_gEC" />
                                                            </td>
                                                            <td>
                                                                Middle Name:
                                                            </td>
                                                            <td>
                                                                <input type="text" id="txtMname" style="width: 150px; height: 18px; font-size: 11px;"
                                                                    class="ob_gEC" />
                                                            </td>
                                                            <td>
                                                                Last Name:
                                                            </td>
                                                            <td>
                                                                <input type="text" id="txtLName" style="width: 150px; height: 18px; font-size: 11px;"
                                                                    class="ob_gEC" />
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>
                                                                Gender:
                                                            </td>
                                                            <td>
                                                                <select id="cmbGender">
                                                                    <option value="0" selected="selected">--Select--</option>
                                                                    <option value="Male">Male</option>
                                                                    <option value="Female">Female</option>
                                                                </select>
                                                            </td>
                                                            <td>
                                                                Email Id:
                                                            </td>
                                                            <td>
                                                                <input type="text" id="txtEmailid" style="width: 150px; height: 18px; font-size: 11px;"
                                                                    class="ob_gEC" />
                                                            </td>
                                                            <td>
                                                                Mobile No:
                                                            </td>
                                                            <td>
                                                                <input type="text" id="txtMobNo" style="width: 150px; height: 18px; font-size: 11px;"
                                                                    class="ob_gEC" />
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>
                                                                Pan No:
                                                            </td>
                                                            <td>
                                                                <input type="text" id="txtPanno" style="width: 150px; height: 18px; font-size: 11px;"
                                                                    class="ob_gEC" />
                                                            </td>
                                                            <td>
                                                                Adhaar No:
                                                            </td>
                                                            <td>
                                                                <input type="text" id="txtAdhaar" style="width: 150px; height: 18px; font-size: 11px;"
                                                                    class="ob_gEC" />
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>
                                                                Address:
                                                            </td>
                                                            <td>
                                                                <%--<input type="text" id="txtAddress" style="width: 150px;" class="ob_gEC"  />--%>
                                                                <asp:TextBox ID="txtAddress" CssClass="ob_gEC" runat="server" Style="width: 240px;
                                                                    height: 50px; font-size: 11px;" TextMode="MultiLine"></asp:TextBox>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>
                                                                Attachment:
                                                            </td>
                                                            <td>
                                                                <input type="file" id="FlAttach" style="width: 250px; height: 18px;" class="ob_gEC" />
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </fieldset>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="2" align="center">
                                                <input type="button" value="Save" onclick="GrdPartyInfo.save()" class="tdText" />
                                                <input type="button" value="Cancel" onclick="GrdPartyInfo.cancel()" class="tdText" />
                                            </td>
                                        </tr>
                                    </table>
                                </Template>
                            </cc1:GridTemplate>
                        </Templates>
                        <Templates>
                            <cc1:GridTemplate runat="server" ID="tplNumbering1">
                                <Template>
                                    <b>
                                        <%# (Container.RecordIndex + 1) %></b>
                                </Template>
                            </cc1:GridTemplate>
                        </Templates>
                    </cc1:Grid>

1 个答案:

答案 0 :(得分:1)

此处根据评论中的讨论,EXP_TYPE_ID不作为列存在。

所以改变它:

newRow["EXP_TYPE_ID"] = Convert.ToString(e.Record["EXP_TYPE"]); 

newRow["EXP_TYPE"] = Convert.ToString(e.Record["EXP_TYPE"]);