This is a migrated thread and some comments may be shown as answers.

GridBoundColumn

1 Answer 20 Views
Grid
This is a migrated thread and some comments may be shown as answers.
New User
Top achievements
Rank 1
New User asked on 08 Dec 2010, 12:16 AM
I have a column in my grid that needs to change from either a dropdownbox or textbox based on the previous columns dropdown value.
Is this possible?

If you have any suggestions would be helpful.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 08 Dec 2010, 06:46 AM
Hello,

One easy method is using GridTemplateColumn with DropDownList and TextBox inside EditItemTemplate. Then based on the selected value of DropDownColumn set the visibility of controls (DropDownList and TextBox) accordingly. Sample code is given below.

ASPX:
<telerik:GridTemplateColumn>
    <EditItemTemplate>
        <asp:DropDownList ID="DropDownList1" runat="server">
        </asp:DropDownList>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </EditItemTemplate>
</telerik:GridTemplateColumn>

C#:(Try the following code in SelectedIndexChanged event of DropDownColumn.)
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
  {
      DropDownList list = (DropDownList)sender;
      GridEditableItem editItem = (GridEditableItem)list.NamingContainer;
      DropDownList drlist = (DropDownList)editItem.FindControl("DropDownList1");
      TextBox txtbox = (TextBox)editItem.FindControl("TextBox1");
      if (list.SelectedValue == "Davic")// your condition
      {
          drlist.Visible = false;
          txtbox.Visible = true;
      }
      else
      {
          txtbox.Visible = false;
          drlist.Visible = true;
      }
  }

Thanks,
Princy.
Tags
Grid
Asked by
New User
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or