本文介绍了动态控件不会在回发中生成。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在点击列表视图项目时有一个radlistview我正在创建动态控件。现在我有两个控件文本框和下拉菜单。文本框控件在列表视图的每次单击时都能正常工作,但下拉列表只生成一次。在每次点击我想生成一个控件,但没有这样做。有人可以建议我在我的代码中做错了吗。



我尝试过:



I have a radlistview on click of list view items i am creating dynamic controls. Present i have two controls text box and drop down. Text box control works fine on every click of list view but drop down is generating only once. On every click i want to generate a control, but fail to do so. Can some suggest me what i have done wrong in my code.

What I have tried:

protected void Page_Load(object sender, EventArgs e)
       {
           if (!IsPostBack)
           {
               RadListView1.DataSource = GetDatatable();
               RadListView1.DataBind();
           }

           else
           {
               RecreateControls("rtb", "RadTextBox");
               RecreateControls("rddl", "RadDropDownList");
           }
      }
      public DataTable GetDatatable()
      {
           DataTable dt = new DataTable();
           dt.Columns.Add("Label");
           dt.Rows.Add("RadTextBox");
           dt.Rows.Add("RadDropDownList");
           return dt;
       }
       protected void RadAjaxManager1_AjaxRequest(object sender,
       Telerik.Web.UI.AjaxRequestEventArgs e)
       {
           string commandText = e.Argument.ToString().Trim();
           string[] splitdata = commandText.Split('&');
           commandText = splitdata[0];
           string controlName = splitdata[1];
           switch (controlName)
           {
               case "RadTextBox":
                   int cnt1 = FindOccurence("rtb") + 1;
                   DynamicControls dcTextBox = new DynamicControls();
                   TableCell txtlblRad = dcTextBox.Controlscreation("RadLabel", "", cnt1, cnt1, "Text Box:", "", 0);
                   TableCell txtRad = dcTextBox.Controlscreation("RadTextBox", "", cnt1, cnt1, "", "", 0);
                   TableRow txtRow = new TableRow();
                   txtRow.Cells.Add(txtlblRad);
                   txtRow.Cells.Add(txtRad);
                   Table1.Rows.Add(txtRow);
                   break;
           case "RadDropDownList":
                   int cnt4 = FindOccurence("rddl") + 1;
                   DynamicControls dcRadDropDown = new DynamicControls();
                   TableCell radDropDownlbl = dcRadDropDown.Controlscreation("RadLabel", "", cnt4, cnt4, "RDDL:", "", 0);
                   TableCell radDropDown = dcRadDropDown.Controlscreation("RadDropDownList", "", cnt4, cnt4, "", "", 0);
                   TableRow dropdownRow = new TableRow();
                   dropdownRow.Cells.Add(radDropDownlbl);
                   dropdownRow.Cells.Add(radDropDown);
                   Table1.Rows.Add(dropdownRow);
                   break;
             }
        }
       private void RecreateControls(string ctrlPrefix, string ctrlType)
       {
           string[] ctrls = Request.Form.ToString().Split('&');
           int cnt = FindOccurence(ctrlPrefix);
           if (cnt > 0)
           {
               for (int k = 1; k <= cnt; k++)
               {
                   for (int i = 0; i < ctrls.Length; i++)
                   {
                       if (ctrls[i].Contains(ctrlPrefix + "_" + k.ToString()))
                       {
                            if (ctrlType == "RadTextBox")
                           {
                               DynamicControls dcTextBox = new DynamicControls();
                               TableCell txtlblRad = dcTextBox.Controlscreation("RadLabel", "", k, k, "TextBox:", "", 0);
                               TableCell txtRad = dcTextBox.Controlscreation("RadTextBox", "", k, k, "", "", 0);
                               TableRow txtRow = new TableRow();
                               txtRow.Cells.Add(txtlblRad);
                               txtRow.Cells.Add(txtRad);
                               Table1.Rows.Add(txtRow);
                           }
                           if (ctrlType == "RadDropDownList")
                            {
                                DynamicControls dcRadDropDown = new DynamicControls();
                                TableCell radDropDownlbl = dcRadDropDown.Controlscreation("RadLabel", "", k, k, "RDDL :", "", 0);
                                TableCell radDropDown = dcRadDropDown.Controlscreation("RadDropDownList", "", k, k, "", "", 0);
                                TableRow dropdownRow = new TableRow();
                                dropdownRow.Cells.Add(radDropDownlbl);
                                dropdownRow.Cells.Add(radDropDown);
                                Table1.Rows.Add(dropdownRow);
                            }
                            break;
                       }
                   }
               }
           }
       }
        private int FindOccurence(string substr)
       {
           string reqstr = Request.Form.ToString();
           return (((reqstr.Length - reqstr.Replace(substr, "").Length) / substr.Length) / 2);
       }





加价:





Markup:

  <telerik:RadListView ID="RadListView1" runat="server" RenderMode="Lightweight" DataKeyNames="Label" ClientDataKeyNames="Label" ItemPlaceholderID="ListViewPlaceHolder1" EnableViewState="false" Width="50%">
   <EmptyDataTemplate>
   </EmptyDataTemplate>
      <LayoutTemplate>
        <div class="RadListView RadListView_Silk">
           <table id="orgcharttable" class="layoutTable" width="100%">
            <tr>
              <td colspan="3" class="nopadding">
                <asp:PlaceHolder ID="ListViewPlaceHolder1" runat="server"></asp:PlaceHolder>
               </td>
             </tr>
           </table>
         </div>
       </LayoutTemplate>
       <ItemTemplate>
        <div id="divHighlight" class="ListViewStyle" onclick="SelectControl(this,event);">
       <div style="vertical-align: top; width: 100%">
         <table>
            <tr id="tr1">
             <td colspan="2" class="tdnormal">
               <telerik:RadLabel ID="lbl1" runat="server" Text='<%# Bind("Label")%>' Font-Bold="true" CssClass="ItemHeaderStyle"></telerik:RadLabel>
             </td>
            </tr>
            <tr id="tr2">
              <td rowspan="2" colspan="1" style="width: 5%">
               <telerik:RadBinaryImage ID="rbimgWizard" runat="server" Width="80px" Height="80px" ResizeMode="Fit" CssClass="image" ImageUrl="../../Images/SCREEN.png" />
              </td>
            </tr>
        </table>
      </ItemTemplate>
     </telerik:RadListView>


  <asp:UpdatePanel ID="Panel1" runat="server" UpdateMode="Conditional" EnableViewState="false">
    <ContentTemplate>
     <asp:UpdatePanel ID="Panel2" runat="server" UpdateMode="Conditional" EnableViewState="false">
      <ContentTemplate>
        <asp:Table ID="Table1" runat="server"></asp:Table>
      </ContentTemplate>
    </asp:UpdatePanel>
  </ContentTemplate>
</asp:UpdatePanel>

推荐答案


这篇关于动态控件不会在回发中生成。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 18:51