RadGrid,dropDown SelectedIndexChanged事件无法在asp FormView

时间:2015-07-27 05:56:27

标签: c# asp.net radgrid

我的网页中有一个RadGrid,其中有4个字段:
1)公司名单(DropDown List)
2)金额(文本框)
3)备注(文本框)

公司下拉列表中的数据如下:
TX - 需要缴税0% GRE - 需要11%的税 EP - 需要缴税0% BL - 需要征收6%的税 TL - 需要缴税0%

要求1:

在更改下拉列值时,“添加新记录” 当“编辑”记录时,“金额”和“备注”文本框变为空。

为此,我尝试将“DropDown_SelectedIndexChanged”事件代码 但由于我的RadGrid在asp:FormView中,所以我的页面永远不会回发 我从RadGrid重新选择项目,代码不起作用

要求2:

如果Dropdown在所选项目中有0%(文本),则“Amount”文本框应该为 在文本框中禁用0.00值。

为此,我尝试了以下代码:

protected void rggst_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
                GridEditableItem item = e.Item as GridEditableItem;

                DropDownList list = item.FindControl("ddlCompany") as DropDownList;
                list.DataTextField = "TaxDescription";
                list.DataValueField = "TaxId";
                list.DataSource = IPRRequest.DLTaxCode(CorporateGroupId);
                list.DataBind();

                if (list.Items.FindByValue("0%"))
                {
                    if (e.Item is GridEditFormInsertItem)
                    {
                        GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item;
                        TextBox txt = (TextBox)insertItem["Amount"].Controls[0];
                        txt.Text = "0.00";
                        txt.Enabled = false;
                    }
                }

        }
    }

但每次我得到以下错误:
无法将类型'System.Web.UI.WebControls.ListItem'隐式转换为'bool'

下面是我用于RadGrid的HTML和C#代码:

<asp:FormView ID="fvIPRForm" runat="server" DefaultMode="Insert" DataKeyNames="RequestID" DataSourceID="odsIPRForm" EnableModelValidation="True" OnItemInserting="fvIPRForm_ItemInserting" OnDataBound="fvIPRForm_DataBound" OnItemUpdating="fvIPRForm_Updating" OnItemCommand="fvIPRForm_ItemCommand">
 <InsertItemTemplate>
   <asp:Panel ID="pnlApprover" runat="server" Visible="true">
   <telerik:RadMultiPage ID="RadMultiPage3" runat="server" SelectedIndex="0" Width="100%">
   <telerik:RadPageView ID="RadPageView1" runat="server" Width="100%">
   <telerik:RadAjaxPanel ID="Main" runat="server">                                                                                       
      <telerik:RadGrid ID="RGGST" runat="server" AutoGenerateColumns="false"
        ShowStatusBar="true" EnableEmbeddedSkins="true" Skin="Outlook" ShowFooter="True"
        OnItemDataBound="rggst_ItemDataBound"
        OnInsertCommand="rggst_InsertCommand" OnUpdateCommand="rggst_UpdateCommand"
        OnDeleteCommand="rggst_DeleteCommand" OnNeedDataSource= "rggst_NeedDataSource">
      <mastertableview commanditemdisplay="Top" autogeneratecolumns="false" datakeynames="Amount" 
        insertitempageindexaction="ShowItemOnCurrentPage" ShowFooter="True" >                                                                                           
         <CommandItemSettings AddNewRecordText="New" />
           <Columns>
              <telerik:GridEditCommandColumn UniqueName="imagebutton1" ButtonType="ImageButton"></telerik:GridEditCommandColumn>  
              <telerik:GridTemplateColumn UniqueName="Company" HeaderText="Company">
                 <ItemTemplate>
                   <asp:Label ID="lblCompany" Text='<%# Eval("Company") %>' runat="server"></asp:Label>
                 </ItemTemplate>
                 <EditItemTemplate>
                   <asp:DropDownList ID="ddlCompany" runat="server"/>                                                
                 </EditItemTemplate>
              </telerik:GridTemplateColumn>
              <telerik:GridBoundColumn aggregate="SUM" DataField="Amount" HeaderText="Amount" FooterAggregateFormatString="Total : {0:###,##0.00}" 
              UniqueName="Amount" SortExpression="Amount" DataFormatString="{0:n}"></telerik:GridBoundColumn>                                                                                                                        
              <telerik:GridBoundColumn DataField="Remark" HeaderText="Remark"
              UniqueName="Remark" SortExpression="Remark" maxlength ="30"></telerik:GridBoundColumn>                                                                                
              <telerik:GridButtonColumn ConfirmText="Delete this Tax Code?" ConfirmDialogType="RadWindow"
              ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" ConfirmDialogHeight="160px" ConfirmDialogWidth="250px">
              </telerik:GridButtonColumn>
          </Columns>                                    
          <EditFormSettings>
            <EditColumn ButtonType="ImageButton" />
          </EditFormSettings>
          <PagerStyle AlwaysVisible="True" PageSizeControlType="RadComboBox" />
       </mastertableview>
       </telerik:RadGrid>
   </telerik:RadAjaxPanel>
   </telerik:RadPageView>
</telerik:RadMultiPage>
</asp:Panel>
 </InsertItemTemplate>
<EditItemTemplate>
   //same RadGrid in this section
 </EditItemTemplate>
 <ItemTemplate>
   //same RadGrid in this section
 </ItemTemplate>
</asp:FormView>

这是我为要求1尝试的代码:

protected void ddlTaxCodes1_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList taxCodesList = (DropDownList)sender;
        GridEditableItem item = (GridEditableItem)taxCodesList.NamingContainer;

        string grossAmountTxt = (item["LIGrossAmt"].Controls[0] as TextBox).Text;
        string TaxAmt = (item["LITaxAmt"].Controls[0] as TextBox).Text;
        string TaxableAmt = (item["LITaxableAmt"].Controls[0] as TextBox).Text;
        string Description = (item["LIDescription"].Controls[0] as TextBox).Text;

        grossAmountTxt = "";
        TaxAmt = "";
        TaxableAmt = "";
        Description = "";
    }

请让我知道我在代码中犯了什么错误。
请注意我是Telerik的新手。提前谢谢。

1 个答案:

答案 0 :(得分:0)

下面是我为我的要求创建的示例代码,并且对于上述两个要求都正常工作。
另外,asp:FormView不会影响SelectdIndexChanged事件代码,并且工作正常。

protected void ddlTaxCodes1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlAcCode.SelectedValue != null || ddlAcCode.SelectedValue != "")
        {
            ddlAcCode.Enabled = false;

            string selItem = ddlAcCode.SelectedItem.Text;

            if (selItem.Contains("0%"))
            {
                txtAmount.Text = "0.00";
                txtAmount.Enabled = false;

                txtRemark.Text = "";
            }
            else
            {
                txtAmount.Text = "";
                txtRemark.Text = "";
            }
        }
    }