C# 从gridview行命令在更新面板中设置文本框文本
我正在尝试通过gridview的row命令更新更新面板中文本框的值,也在更新面板中。row命令启动更新面板并运行onrow命令代码,但是文本框的值根本没有被更新 我没有收到任何错误,并且我已经检查过,我不是简单地通过跟踪我提供值的类的值来输入空白字符串 这是我的密码: ASPXC# 从gridview行命令在更新面板中设置文本框文本,c#,asp.net,gridview,textbox,updatepanel,C#,Asp.net,Gridview,Textbox,Updatepanel,我正在尝试通过gridview的row命令更新更新面板中文本框的值,也在更新面板中。row命令启动更新面板并运行onrow命令代码,但是文本框的值根本没有被更新 我没有收到任何错误,并且我已经检查过,我不是简单地通过跟踪我提供值的类的值来输入空白字符串 这是我的密码: ASPX <asp:Panel ID="pnlInspectorExpenses" CssClass="expenses" runat="server" Visible="false"> <asp:Hid
<asp:Panel ID="pnlInspectorExpenses" CssClass="expenses" runat="server" Visible="false">
<asp:HiddenField ID="hdnInsExpID" runat="server" />
<asp:UpdatePanel ID="uPnlInspectorExpenses" runat="server">
<ContentTemplate>
<table>
<tr>
<td class="tableHead tableItem">IMO Number:</td>
<td class="tableField"><asp:Label ID="lblExpensesIMO" runat="server" /></td>
<td></td>
</tr>
<tr>
<td class="tableHead tableItem">Port of Vessel:</td>
<td class="tableField"><asp:Label ID="lblExensesPort" runat="server" /></td>
<td></td>
</tr>
<%--<tr>
<td class="tableHead tableItem">Report No.:</td>
<td class="tableField"><asp:Label ID="lblExpensesReportNo" runat="server" /></td>
<td></td>
</tr>--%>
<tr>
<td class="tableHead tableItem">Client Reference:</td>
<td class="tableField"><asp:Label ID="lblExpensesClientRef" runat="server" /></td>
<td></td>
</tr>
<tr>
<td class="tableHead tableItem">Vessel Type:</td>
<td class="tableField"><asp:Label ID="lblExpensesVesselType" runat="server" /></td>
<td></td>
</tr>
</table>
<table class="tableClass">
<tr>
<th align="left">Date</th>
<th align="left">Expense Description</th>
<th align="left">Type</th>
<th align="left">Currency</th>
<th align="right">Foreign Cost</th>
<th align="right">Exch. Rate</th>
<th align="right">GBP</th>
<th align="left">Receipt No</th>
<th colspan="2"></th>
</tr>
<tr>
<td colspan="10" class="zeroPadding">
<asp:GridView ID="grdInspectorExpenses" runat="server" CssClass="tableClass zeroMargin zeroBorder" DataKeyNames="ExpID" AutoGenerateColumns="false"
OnRowCommand="grdInspectorExpenses_RowCommand">
<Columns>
<asp:BoundField DataField="ExpDate" HeaderStyle-CssClass="invisible" ItemStyle-HorizontalAlign="Left" DataFormatString="{0:d}" ItemStyle-Width="90px" />
<asp:BoundField DataField="ExpDescription" HeaderStyle-CssClass="invisible" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="220px" />
<asp:BoundField DataField="ExpType" HeaderStyle-CssClass="invisible" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="100px" />
<asp:BoundField DataField="ExpCurrency" HeaderStyle-CssClass="invisible" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="75px" />
<asp:BoundField DataField="ExpForeignCost" HeaderStyle-CssClass="invisible" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="75px" />
<asp:BoundField DataField="ExpExchangeRate" HeaderStyle-CssClass="invisible" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="80px" />
<asp:BoundField DataField="ExpLocalCost" HeaderStyle-CssClass="invisible" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="80px" />
<asp:BoundField DataField="ExpReceiptNo" HeaderStyle-CssClass="invisible" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="80px" />
<asp:TemplateField HeaderStyle-CssClass="invisible" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="30px">
<ItemTemplate>
<asp:LinkButton ID="btnEditExpense" runat="server" Text="Edit" CommandName="Edit" CommandArgument="<%# Container.DataItemIndex %>" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-CssClass="invisible" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:LinkButton ID="btnDeleteExpense" runat="server" Text="Delete" OnClientClick="javascript: if (!confirm('Are you sure you want delete?')) return false;"
CommandName="Delete" CommandArgument="<%# Container.DataItemIndex %>" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
No expenses have yet been added
</EmptyDataTemplate>
</asp:GridView>
</td>
</tr>
<tr>
<td><asp:TextBox ID="txtInsExpDate" CssClass="datepicker" runat="server" Width="88px" style="padding: 5px 0px;" /></td>
<td><asp:TextBox ID="txtInsExpDesc" runat="server" Width="218px" style="padding: 5px 0;" /></td>
<td>
<asp:DropDownList ID="ddlExpenseType" runat="server" style="width:100px; padding: 4px 0;">
<asp:ListItem Text="General" Value="General" />
<asp:ListItem Text="Accommodation" Value="Accommodation" />
<asp:ListItem Text="Flight" Value="Flight" />
</asp:DropDownList>
</td>
<td><asp:TextBox ID="txtInsExpCurrency" runat="server" Width="68px" style="padding: 5px 0;" /></td>
<td><asp:TextBox ID="txtInsExpForVal" runat="server" Width="78px" style="text-align: right; padding: 5px 0;" /></td>
<td><asp:TextBox ID="txtInsExpExcRate" runat="server" Width="78px" style="text-align: right; padding: 5px 0;" /></td>
<td><asp:TextBox ID="txtInsExpLocVal" runat="server" Width="78px" style="text-align: right; padding: 5px 0;" /></td>
<td><asp:TextBox ID="txtInsExpRecNo" runat="server" Width="78px" style="padding: 5px 0;" /></td>
<td colspan="2" style="width:100px"></td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress5" runat="server" DynamicLayout="true">
<ProgressTemplate>
<div class="overlay" >
<img src="/Portals/_default/Skins/PMIT/Images/radarLoading.gif" />
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</asp:Panel>
国际海事组织编号:
船港:
客户参考:
船舶类型:
日期
费用说明
类型
通货
国外成本
Exch。比率
英镑
收据编号
还没有增加任何费用
ASPX.CS
protected void grdInspectorExpenses_RowCommand(object sender, GridViewCommandEventArgs e)
{
Trace.Warn("0");
if (e.CommandName == "Edit")
{
Trace.Warn("1");
int rowIndex = int.Parse(e.CommandArgument.ToString());
int ExpID = int.Parse(grdInspectorExpenses.DataKeys[rowIndex].Values[0].ToString());
hdnInsExpID.Value = ExpID.ToString();
List<ExpenseInfo> Expenses = IC.ExpenseSelect(ExpID);
ExpenseInfo Expense = Expenses[0];
txtInsExpDate.Text = Expense.ExpDate.ToString();
txtInsExpDesc.Text = Expense.ExpDescription;
ddlExpenseType.Items.FindByValue(Expense.ExpType).Selected = true;
txtInsExpCurrency.Text = Expense.ExpCurrency;
txtInsExpForVal.Text = Expense.ExpForeignCost.ToString();
txtInsExpExcRate.Text = Expense.ExpExchangeRate.ToString();
txtInsExpLocVal.Text = Expense.ExpLocalCost.ToString();
txtInsExpRecNo.Text = Expense.ExpReceiptNo;
Trace.Warn(Expense.ExpReceiptNo);
}
else if (e.CommandName == "Delete")
{
}
}
protectedvoid grdInspectorExpenses\u row命令(对象发送方,GridViewCommandEventArgs e)
{
Trace.Warn(“0”);
如果(例如,CommandName==“编辑”)
{
Trace.Warn(“1”);
int rowIndex=int.Parse(例如,CommandArgument.ToString());
int ExpID=int.Parse(grdInspectorExpenses.DataKeys[rowIndex].Values[0].ToString());
hdnInsExpID.Value=ExpID.ToString();
列表费用=集成电路费用选择(ExpID);
ExpenseInfo费用=费用[0];
txtInsExpDate.Text=Expense.ExpDate.ToString();
txtInsExpDesc.Text=Expense.ExpDescription;
ddleExpenseType.Items.FindByValue(Expense.ExpType).Selected=true;
txtInsExpCurrency.Text=Expense.ExpCurrency;
txtinexpforval.Text=Expense.ExpForeignCost.ToString();
txtinexchangerate.Text=费用.ExpExchangeRate.ToString();
txtInsExpLocVal.Text=Expense.ExpLocalCost.ToString();
txtInsExpRecNo.Text=Expense.ExpReceiptNo;
Trace.Warn(Expense.ExpReceiptNo);
}
else if(e.CommandName==“删除”)
{
}
}
请将UpdatePanel的UpdateMode设置为“始终”,以查看这是否会产生影响。有关更新UpdatePanel内容时的规则和条件,请参见此处的备注:我最终解决了这个问题。似乎如果您将CommandName命名为“Edit”,它将调用未定义的“OnRowEditing”函数。因此,我只是将CommandName重命名为“EditExpenses”。我也对Delete命令做了同样的操作。谢谢您的回复,我只是尝试了一下,但没有成功。我知道正在调用更新,因为当我单击按钮时,我绑定到它的updateprogress会显示出来。此外,我在rowcommand事件中放置的跟踪语句也出现在跟踪中。