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

Handle dropdownlist selected index changed event in Radgrid.

5 Answers 1431 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Omkar
Top achievements
Rank 1
Omkar asked on 27 May 2013, 10:34 AM
Hello all,


I am new user in telerik control. in my scenario situation is in radgrid
I have 4 diff column in which first is for serial number second is status dropdown and third for remark.

so in this situation i i have to make functionality is in dropdown i have 4 list item. in which if selected first three list item then have to hide textbox from fourth column. other wise have to show with fourth item

I tried a lot. googling for this. but din't get idea.

So please help me to solve this problem.


Thanks in advance,
Omi...........

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 May 2013, 01:20 PM
Hello Omkar,

Try the following code snippet.

C#:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
 DropDownList dropdownlist1 = (DropDownList)sender;
 GridDataItem item = (GridDataItem)dropdownlist1.NamingContainer;
 TextBox textbox1= (TextBox)item.FindControl("textbox1");
 if (dropdownlist1 .SelectedItem.Text == "item1" || dropdownlist1 .SelectedItem.Text == "item2" || dropdownlist1.SelectedItem.Text == "item3")
 {
   textbox1.Visible = false;
 }
 else
 {
   textbox1.Visible = true;
   textbox1.Text = dropdownlist1.SelectedItem.Text;
 }
}
Note: Set AutoPostBack of dropdownlist as true.

Thanks,
Princy.
0
Jay
Top achievements
Rank 1
answered on 19 Dec 2013, 04:55 PM
How to achieve the same if it was a radcombobox and not dropdownlist? the Naming container is of PanelNamingContainer there.
0
Princy
Top achievements
Rank 2
answered on 20 Dec 2013, 05:47 AM
Hi Jay,

Please try the following code snippet to access a RadComboBox in the

ASPX:
<telerik:GridTemplateColumn HeaderText="RadComboBox">
    <ItemTemplate>
        <telerik:RadComboBox ID="RadComboBox1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
            <Items>
                <telerik:RadComboBoxItem Text="1" Value="1" />
                <telerik:RadComboBoxItem Text="2" Value="2" />
                <telerik:RadComboBoxItem Text="3" Value="3" />
                <telerik:RadComboBoxItem Text="4" Value="4" />
            </Items>
        </telerik:RadComboBox>
    </ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="TextBox">
    <ItemTemplate>
        <asp:TextBox ID="TextBox1" runat="server" Visible="false"></asp:TextBox>
    </ItemTemplate>
</telerik:GridTemplateColumn>


C#:
protected void RadComboBox1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
    RadComboBox combo = (RadComboBox)sender;
    GridDataItem item = (GridDataItem)combo.NamingContainer;
    TextBox textbox1 = (TextBox)item.FindControl("TextBox1");
    if (combo.SelectedItem.Text == "4")
    {
        textbox1.Visible = true;
        textbox1.Text = combo.SelectedItem.Text;
    }
    else
    {
        textbox1.Visible = false;
    }       
}

Thanks,
Princy
0
Jay
Top achievements
Rank 1
answered on 20 Dec 2013, 02:13 PM

Does not work for me.

PS: My grid is in batch editing mode.

0
Konstantin Dikov
Telerik team
answered on 24 Dec 2013, 11:38 AM
Hi Jay,

For achieving such functionality you could handle the client-side OnBatchEditOpened event of the grid and the client-side OnClientItemSelected event of the RadDropDownList. On those two event you can retrieve the current value of the RadDropDownList and show or hide a RadTextBox control in the last column, depending on the retrieved value.

For your convenience I have prepared a sample page with the requested functionality. Please refer to the attached files and see if this works for you.


Regards,
Konstantin Dikov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Omkar
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jay
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or