附加下面的代码 - 它是一个简单的代码,只是初始化下拉列表(调用ddl.Clear())并添加一个文本“select”的项目,其值为“-1”。
Filldropdowns(ddl)是获取特定数据并将其填充到下拉方法中的方法。这些方法在普通下拉列表的gridview外单独工作。
对于每个gridview行,会发生多次调用此事件处理程序。作为最终结果,下拉列表包含它们应该包含的值的两倍(完整的值集只会重复)。
有谁知道为什么会这样?关闭appenddatabounditems不是一个选项,因为我需要在“选择”下面添加项目。
奇怪的是,当我调试时,即使第二次调用同一行,它也会显示下拉值包含零项,然后包含所需的项数。但是当我到达grdAccountsMapping_DataBound()处理程序时,它会显示两倍的项目数。
public void grdAccountsMapping_RowCreated(object sender, GridViewRowEventArgs e)
{
GridViewRow row = e.Row;
if (row.RowType == DataControlRowType.DataRow)
{
DropDownList ddlGrdFeeFormat = (DropDownList)row.FindControl("ddlFeeFormat");
DropDownList ddlGrdTransactionMode = (DropDownList)row.FindControl("ddlTransactionMode");
DropDownList ddlGrdFeeParticular = (DropDownList)row.FindControl("ddlFeeParticular");
DropDownList ddlGrdCompany = (DropDownList)row.FindControl("ddlCompany");
DropDownList ddlGrdAccounts = (DropDownList)row.FindControl("ddlAccounts");
DropDownList ddlGrdFeeBook = (DropDownList)row.FindControl("ddlFeeBook");
InitializeDropdown(ddlGrdFeeBook);
InitializeDropdown(ddlGrdFeeFormat);
InitializeDropdown(ddlGrdTransactionMode);
InitializeDropdown(ddlGrdFeeParticular);
InitializeDropdown(ddlGrdCompany);
getDDLValues.FillFeeBooks(ddlGrdFeeBook);
getDDLValues.FillFeeFormats(ddlGrdFeeFormat);
getDDLValues.FillPaymentModes(ddlGrdTransactionMode);
getDDLValues.FillFeeParticulars(ddlGrdFeeParticular);
getDDLValues.FillAccountingCompanies(ddlGrdCompany);
}
}
aspx页面网格定义如下所示
<asp:GridView CssClass="Grid" ID="grdAccountsMapping" runat="server" Width="98%"
EmptyDataText="No records found in this section" EmptyDataRowStyle-Height="40px"
AutoGenerateColumns="False" AccessKey="2" DataKeyNames="FAM_MAP_ID" OnRowCommand="grdAccountsMapping_RowCommand"
OnRowCreated="grdAccountsMapping_RowCreated" OnDataBound="grdAccountsMapping_DataBound"
Visible="false">
<AlternatingRowStyle CssClass="alternateGridItem" HorizontalAlign="Left" />
<RowStyle CssClass="gridItem" HorizontalAlign="Left" />
<EmptyDataRowStyle CssClass="gridItem" HorizontalAlign="Center" Font-Bold="True"
ForeColor="Red" Height="40px" VerticalAlign="Middle" />
<HeaderStyle CssClass="tabledarklabel" />
<FooterStyle CssClass="Grid_Footer" />
<Columns>
<asp:TemplateField HeaderText="Fee Book">
<ItemTemplate>
<asp:DropDownList ID="ddlGrdFeeBook" CssClass="dropdownwidth3" runat="server" AppendDataBoundItems="True">
</asp:DropDownList>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="5%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Fee Format">
<ItemTemplate>
<asp:DropDownList ID="ddlGrdFeeFormat" CssClass="dropdownwidth3" runat="server" AppendDataBoundItems="True">
</asp:DropDownList>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="5%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Transaction Mode">
<ItemTemplate>
<asp:DropDownList ID="ddlGrdTransactionMode" CssClass="dropdownwidth3" runat="server"
AppendDataBoundItems="True" >
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Fee Particulars">
<ItemTemplate>
<asp:DropDownList ID="ddlGrdFeeParticular" CssClass="dropdownwidth3" runat="server"
AppendDataBoundItems="True">
</asp:DropDownList>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="5%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Company">
<ItemTemplate>
<asp:DropDownList ID="ddlGrdCompany" CssClass="dropdownwidth3" runat="server" AppendDataBoundItems="True">
</asp:DropDownList>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="5%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Account">
<ItemTemplate>
<asp:DropDownList ID="ddlGrdAccounts" CssClass="dropdownwidth3" runat="server" AppendDataBoundItems="True">
</asp:DropDownList>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="5%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Active">
<ItemTemplate>
<asp:CheckBox ID="chkActive" runat="server" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="5%" />
</asp:TemplateField>
</Columns>
<PagerSettings Visible="False" />
<PagerStyle BorderStyle="None" />
</asp:GridView>
其他使用的方法只是检索所需数据的数据集,将其分配给下拉列表的数据源,然后将其绑定到下拉列表控件。这些方法在网格外的下拉菜单上运行良好,我已经对它们进行了单元测试 - 所以我确信问题不在那里。
答案 0 :(得分:0)
你如何绑定网格?你是不是偶然多次调用DataBind()和/或Rebind()?
答案 1 :(得分:0)
我们刚刚删除了该文件并再次创建它似乎工作。我们没有太多时间深入研究细节,因为我们处于截止日期,但那个奇怪的问题并没有再次发生!