这是我发布的有点重复的问题 Stop DropDownList SelectedIndexChanged Event firing on FormView command。现在我遇到了这些不同的问题。
在这里,我从Listbox(我更愿意拥有)更改为editItemTemplate中的Combobox。当我第一次选择一个项目(百分比)时,Combobox onSelectedIndexChanged事件会像我想要的那样触发。但是当我去选择原始物品(吨)时它不会发射。我正在尝试重新创建一个切换。
我切换到组合框以使用SelectionChangeCommitted事件。但是,它并没有出现在我的智能感知中。我尝试手动输入它,当然它根本不起作用。
我的目标是让用户输入值作为实际吨数的总数或实际值的百分比,然后来回切换。将插入数据库的最终值将以吨为单位。
我想要: a)使用列表框并修复在提交表单时不会触发“onSelectedIndexChanged”事件的问题 b)使这个组合框正确点火。我猜它不会,除非我可以让SelectionChangeCommitted事件显示出来 c)一种我不知道的更好的解决方法。
的.aspx:
<asp:Panel ID="pnlRecycledMaterialsReceivedForm" runat="server" Visible="false">
<asp:FormView ID="fvAddRecycledMaterialsReceived" runat="server" SkinID="annualReportFormview" EnableViewState="false"
HeaderText="Selected Recycled Materials Received Detail" DataKeyNames="RecycleDetailId" DefaultMode="Insert"
DataSourceID="odsRecycledMaterialsReceivedDetail" OnDataBound="fvAddRecycledMaterialsReceived_DataBound"
OnItemCommand="fvAddRecycledMaterialsReceived_ItemCommand" OnItemInserted="fvAddRecycledMaterialsReceived_ItemInserted"
OnItemUpdated="fvAddRecycledMaterialsReceived_ItemUpdated" OnItemDeleted="fvAddRecycledMaterialsReceived_ItemDeleted">
<EditItemTemplate>
<asp:TextBox ID="tbxRecycledTotalWasteQuantity" runat="server" Text='<%# Bind("TotalWasteQuantity") %>' Width="64px"></asp:TextBox>
<asp:TextBox ID="tbxRecycledWasteCommercialQuantity" runat="server" Text='<%# Bind("CommercialQuantity") %>' Width="64px"></asp:TextBox>
<asp:TextBox ID="tbxRecycledWasteResidentialQuantity" runat="server" Text='<%# Bind("ResidentialQuantity") %>' Width="64px"></asp:TextBox>
<asp:ComboBox ID="cmb_Units" runat="server" AutoPostBack="true" EnableViewState="true" OnSelectedIndexChanged="cmb_Units_SelectedIndexChanged">
<asp:ListItem Text="Tons" Value="1" Selected />
<asp:ListItem Text="Percent" Value="9" />
</asp:ComboBox>
<asp:LinkButton ID="lbtnWasteReceivedUpdate" runat="server" Text="Update" CommandName="Update"
ValidationGroup="RecycledWasteReceivedDetail" Font-Bold="True" />
<asp:LinkButton ID="lbtnWasteReceivedInsertCancel" runat="server" Text="Cancel" CausesValidation="False" CommandName="Cancel" />
</EditItemTemplate>
</asp:FormView>
</asp:Panel>
的.cs:
protected void cmb_Units_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox tbxRecycledTotalWasteQuantity = (TextBox)fvAddRecycledMaterialsReceived.FindControl("tbxRecycledTotalWasteQuantity");
TextBox tbxRecycledWasteResidentialQuantity = (TextBox)fvAddRecycledMaterialsReceived.FindControl("tbxRecycledWasteResidentialQuantity");
var d_TotalWasteQuantity = Convert.ToDecimal(tbxRecycledTotalWasteQuantity.Text);
ResidentialQuantity = Convert.ToDecimal(tbxRecycledWasteResidentialQuantity.Text);
AjaxControlToolkit.ComboBox cmb_units = (AjaxControlToolkit.ComboBox)fvAddRecycledMaterialsReceived.FindControl("cmb_units");
if (cmb_units.SelectedIndex.ToString() == "1")
{
//2 = percent
//Take tb value and convert to percent
//300/700 * 100
tbxRecycledWasteResidentialQuantity.Text = ((ResidentialQuantity / d_TotalWasteQuantity) * 100).ToString();
//ResidentialQuantity = ResidentialQuantity * (d_TotalWasteQuantity / 100);
}
else
{
//Else 'tons' was chosen. Convert value(%) to tons.
//700 * (43/100) = 301
ResidentialQuantity = d_TotalWasteQuantity * (ResidentialQuantity / 100);
tbxRecycledWasteResidentialQuantity.Text = ResidentialQuantity.ToString();
//tbxRecycledWasteResidentialQuantity.Text = "Tons";
}
}