0

How can i only allow the client to insert either of these two fields.Either Textbox (selected Column) or Value from dropdown (selected Column) but only one field is allowed in a gridview.

<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

Preferred Method : using clientside events.

Jayesh Goyani
  • 11,008
  • 11
  • 30
  • 50
Subek Shakya
  • 595
  • 4
  • 10
  • 28
  • You could create a div wrapper around the grid view and target inwards. So give the wrapper an id = 'wrapId' and then in css you can say #wrapId>div or however you like. Either this or use javascript to change the css. – Dane Oct 26 '15 at 09:45

1 Answers1

1

Please try with the below code snippet.

<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>

Let me know if any concern.

Jayesh Goyani
  • 11,008
  • 11
  • 30
  • 50