我有一个gridview。我试图计算一些数值,但是,我的问题是gridview
回发了。我想避免这种情况。
合同期限*合同单位费率=合同总额
问题在于gridview
的第1行。它不应该刷新或回发,它应该保留在我正在计算的第10行。
假设我正在计算gridview
的第10行,那么计算是正确的。
我的代码如下:
protected void txtContractUnitRate_TextChanged(object sender, EventArgs e)
{
successMsg.InnerHtml = string.Empty;
errorMsg.InnerHtml = string.Empty;
GridViewRow grow = (GridViewRow)((DataControlFieldCell)((TextBox)sender).Parent).Parent; /*Find Gridview Row Index*/
TextBox txtContractDuration = (TextBox)grow.FindControl("txtContractDuration");
TextBox txtContractUnitRate = (TextBox)grow.FindControl("txtContractUnitRate");
TextBox txtContractTotal = (TextBox)grow.FindControl("txtContractTotal");
if (txtContractDuration.Text.Trim() == "" || txtContractUnitRate.Text.Trim() == "")
{
successMsg.InnerHtml = string.Empty;
errorMsg.InnerHtml = "<div class=\"errorMsg\">Please fill some digit or 0.</div>";
return;
}
else if (!string.IsNullOrEmpty(txtContractDuration.Text.Trim()) && !Regex.IsMatch(txtContractDuration.Text.Trim(), "^\\d+(\\.\\d{1,2})?$"))
{
successMsg.InnerHtml = string.Empty;
errorMsg.InnerHtml = "<div class=\"errorMsg\">Please enter contractduration and contract unit rate only neumaric with after decimal two digit format like(34.45 or 30) </div>";
return;
}
totalContractAmount = (Convert.ToDecimal(txtContractDuration.Text)) * (Convert.ToDecimal(txtContractUnitRate.Text));
txtContractTotal.Text = totalContractAmount.ToString();
}
我的aspx代码如下:
<div style="overflow: auto;width:800px">
<asp:UpdatePanel runat="server" ID="UpdatePanel1">
<ContentTemplate>
<asp:GridView ID="GridView2" runat="server" ShowFooter="true"
CssClass="tblHeader" Width="100%"
AutoGenerateColumns="false" BorderWidth="0" BorderColor="Transparent"
onrowdatabound="Gridview1_RowDataBound" onrowcommand="Gridview1_RowCommand" >
<Columns>
<%-- Remove row number field later --%>
<asp:TemplateField Visible="false">
<HeaderTemplate>
<asp:CheckBox ID="cbSelectAll" runat="server" Text="AllEdit" />
</HeaderTemplate>
<ItemStyle HorizontalAlign="Left" />
<HeaderStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" CssClass="chkbox" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Duration" >
<ItemTemplate>
<asp:TextBox ID="txtContractDuration" runat="server" Width="40px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Unit Rate" >
<ItemTemplate>
<asp:TextBox ID="txtContractUnitRate" runat="server" Width="70px" AutoPostBack="True" ontextchanged="txtContractUnitRate_TextChanged" >
</asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total" >
<ItemTemplate>
<asp:TextBox ID="txtContractTotal" runat="server" Enabled="false" Width="70px" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete" Visible="false">
<ItemTemplate>
<asp:LinkButton ID="Delete" runat="server"
CommandName="DeletePMC" OnClientClick="return confirm('Are you sure you want to delete this PMC details?');" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" Text="Delete" >
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="White" />
<RowStyle BackColor="#E9E9E9" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
答案 0 :(得分:0)
尝试使用Ajax更新面板并在其中添加更改事件 像这样的事情
<asp:UpdatePanel ID="UPxxxxxx" runat="server">
<ContentTemplate>
<asp:GridView ID="GVyyyyyy" runat="server">
-- your code --
-- your code --
-- your code --
</asp:gridView>
</ContentTemplate>
<trigger>
<asyn...... controlid=.... />
</trigger>
</asp:updatePanel>