Writing data to template columns (ddl and txt box)

3 posts, 0 answers
  1. Michael
    Michael avatar
    2 posts
    Member since:
    Jan 2014

    Posted 01 Feb 2014 Link to this post

    Having a heck of a time setting one template field based on the choice in another:

    See attached image:

    When I select a "Worker", it that worker is bBrown I want to set the "On TimeCard" to "Yes" for any other user set it to "No"

    Seems simple enough.

    Template field for dropdown looks like this:

    <telerik:GridTemplateColumn FilterControlAltText="Filter TemplWorker column"
    HeaderText="Worker" UniqueName="TemplWorker">
    <EditItemTemplate>
    <telerik:RadDropDownList ID="RadDropDownList5" runat="server"
    DataSourceID="sqlWorkers" DataTextField="EmployeeNumber"
    DataValueField="EmployeeID" DropDownHeight="300px"
    DropDownWidth="150px" ExpandDirection="Up" Width="110px"
    SelectedText='<%# Bind("LaborPerformedBy") %>' CausesValidation="False"
    OnSelectedIndexChanged ="RadDropDownList5_SelectedIndexChanged"
    AutoPostback="False"
    >

    </telerik:RadDropDownList>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
    ControlToValidate="RadDropDownList5" ErrorMessage="Worker is required."
    Font-Size="XX-Small" ForeColor="Red" SetFocusOnError="True">*</asp:RequiredFieldValidator>
    </EditItemTemplate>

    <ItemTemplate>
    <asp:Label ID="Label4" runat="server"
    Text='<%# Eval("LaborPerformedBy") %>' Width="75px"></asp:Label>
    </ItemTemplate>
    <HeaderStyle Width="145px" />
    </telerik:GridTemplateColumn>

    I have tried so many different things not even sure what is what anymore or which event to hook   :-)


    I was able to get the value of the dropdown in itemdatabound but I still cannot set the "On Timecard" field.

    Any direction is appreciated.



  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 02 Feb 2014 in reply to Michael Link to this post

    Hi Michael,

    Please try the following code snippet to set a column text based on dropdownlist select:

    ASPX:
    <telerik:GridTemplateColumn HeaderText="Worker" UniqueName="TemplWorker">
        <EditItemTemplate>
          <telerik:RadDropDownList ID="RadDropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadDropDownList1_SelectedIndexChanged". . .>
          </telerik:RadDropDownList>  
        </EditItemTemplate>  
    </telerik:GridTemplateColumn>
    <telerik:GridTemplateColumn HeaderText="On Timecard">
        <EditItemTemplate>
            <asp:Label ID="Label1" runat="server" Text="No"></asp:Label>
        </EditItemTemplate>
    </telerik:GridTemplateColumn>

    C#:
    protected void RadDropDownList1_SelectedIndexChanged(object sender, DropDownListEventArgs e)
    {
      RadDropDownList droplist = (RadDropDownList)sender;
      GridEditableItem edit = (GridEditableItem)droplist.NamingContainer;
      Label lbl = (Label)edit.FindControl("Label1");
      if (droplist.SelectedText == "bBrown")
      {
       lbl.Text = "Yes";
      }
      else
      {
       lbl.Text = "No";
      }       
    }

    Thanks,
    Princy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 02 Feb 2014 in reply to Michael Link to this post

    Hello,

    Client Side.
    <telerik:GridTemplateColumn>
                               <ItemTemplate>
                                   <asp:DropDownList ID="DropDownList1" runat="server" onChange="DropDownList1Click(this);">
                                       <asp:ListItem Value="0" Text="--Select--"></asp:ListItem>
                                       <asp:ListItem Value="1" Text="1"></asp:ListItem>
                                       <asp:ListItem Value="2" Text="2"></asp:ListItem>
                                   </asp:DropDownList>
                               </ItemTemplate>
                           </telerik:GridTemplateColumn>
                           <telerik:GridTemplateColumn>
                               <ItemTemplate>
                                   <asp:Label ID="Label1" runat="server"></asp:Label>
                               </ItemTemplate>
                           </telerik:GridTemplateColumn>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script>
                function DropDownList1Click(obj) {
                    $("#" + obj.id.replace("DropDownList1", "Label1")).html($(obj).val());
                }
            </script>
        </telerik:RadCodeBlock>

    Server Side

    <telerik:GridTemplateColumn>
                              <ItemTemplate>
                                  <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" CausesValidation="false" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                                      <asp:ListItem Value="0" Text="--Select--"></asp:ListItem>
                                      <asp:ListItem Value="1" Text="1"></asp:ListItem>
                                      <asp:ListItem Value="2" Text="2"></asp:ListItem>
                                  </asp:DropDownList>
                              </ItemTemplate>
                          </telerik:GridTemplateColumn>
                          <telerik:GridTemplateColumn>
                              <ItemTemplate>
                                  <asp:Label ID="Label1" runat="server"></asp:Label>
                              </ItemTemplate>
                          </telerik:GridTemplateColumn>
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddl = (sender as DropDownList);
        GridDataItem item = ddl.NamingContainer as GridDataItem;
        (item.FindControl("Label1") as Label).Text = ddl.SelectedValue;
     
    }


    Thanks,
    Jayesh Goyani
Back to Top