启用texbox或下拉值以插入javascript

时间:2015-10-26 09:43:00

标签: javascript asp.net telerik radcombobox radtextbox

我怎样才能允许客户端插入这两个字段中的任何一个。文本框(选定列)或下拉值(选定列),但网格视图中只允许一个字段。

<asp:GridView ID="gvMedia" DataSourceID ="dsMedia" SkinID="GridviewSkin" runat="server" AutoGenerateColumns="false" AllowSorting="true"  GridLines="Vertical" Width="700px" CellPadding="2" PageSize="50">
  <Columns>
   <asp:TemplateField HeaderText="Selected">
      <ItemTemplate>
         <telerik:RadTextBox runat="server" ID="txtSelected" Width="80px" MaxLength="10" onkeypress="return NumberOnly(this)">
          </telerik:RadTextBox>
         <asp:Label ID="lblOr" runat="server" Text='or'></asp:Label>
         <telerik:RadComboBox ID="cmbSelected" CssClass="ComboBox" runat="server" Width ="50px" Height="100px">
           <Items>
             <telerik:RadComboBoxItem runat="server" Text="" Value="" />
             <telerik:RadComboBoxItem runat="server" Text="100%" Value="100%" />
             <telerik:RadComboBoxItem runat="server" Text="50%" Value="50%" />
           </Items>
         </telerik:RadComboBox>
       </ItemTemplate>
  </asp:TemplateField>
 </Columns>
<EditRowStyle BackColor="#99FF66" />
<SelectedRowStyle BackColor="#FFFF99" />
</asp:GridView>

enter image description here

首选方法:使用客户端事件。

1 个答案:

答案 0 :(得分:1)

请尝试使用以下代码段。

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        function ValueChanged(obj, eve) {
            var id = obj.get_id();
            var tarid = obj.get_id().replace("txtSelected", "cmbSelected");
            var combo = $telerik.findComboBox(tarid);
            if (obj.get_value() != "")
                combo.clearSelection();
        }
        function ClientSelectedIndexChanged(obj, eve) {
            var id = obj.get_id();
            var tarid = obj.get_id().replace("cmbSelected", "txtSelected");
            var txt = $telerik.findTextBox(tarid);
            txt.set_value("");
        }
    </script>
</telerik:RadCodeBlock>
<asp:GridView ID="gvMedia"
    runat="server" AutoGenerateColumns="false" AllowSorting="true" GridLines="Vertical" Width="700px" CellPadding="2" PageSize="50">
    <Columns>
        <asp:TemplateField HeaderText="Selected">
            <ItemTemplate>
                <telerik:RadTextBox runat="server" ID="txtSelected" Width="80px" MaxLength="10">
                    <ClientEvents OnValueChanged="ValueChanged" />
                </telerik:RadTextBox>
                <asp:Label ID="lblOr" runat="server" Text='or'></asp:Label>
                <telerik:RadComboBox ID="cmbSelected" CssClass="ComboBox" runat="server" Width="50px" Height="100px"
                    OnClientSelectedIndexChanged="ClientSelectedIndexChanged">
                    <Items>
                        <telerik:RadComboBoxItem runat="server" Text="" Value="" />
                        <telerik:RadComboBoxItem runat="server" Text="100%" Value="100%" />
                        <telerik:RadComboBoxItem runat="server" Text="50%" Value="50%" />
                    </Items>
                </telerik:RadComboBox>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
    <EditRowStyle BackColor="#99FF66" />
    <SelectedRowStyle BackColor="#FFFF99" />
</asp:GridView>

如果有任何疑虑,请告诉我。