修改时Gridview行不保存
本文关键字:保存 Gridview 修改 | 更新日期: 2023-09-27 18:13:40
我有一个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>
在这里,根据评论中的讨论,EXP_TYPE_ID
不存在作为列。
所以改成
newRow["EXP_TYPE_ID"] = Convert.ToString(e.Record["EXP_TYPE"]);
newRow["EXP_TYPE"] = Convert.ToString(e.Record["EXP_TYPE"]);