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

ComboBox in RadGrid issue

2 Answers 35 Views
Grid
This is a migrated thread and some comments may be shown as answers.
El
Top achievements
Rank 1
El asked on 05 Sep 2010, 05:52 PM

I want to update a Label control which is inside the same GridItem (row).

I have added the OnSelectedIndexChanged Event to the combobox but i just cannot get the current row as it's (i assume) not selected when you change the combobox index.

I just want to select a new item in the combobox and make it updates the Label1 in the same ItemTemplate (findControl i guess but as mentioned i cannot find the currently selected index.

I tried something along the following but, i am missing something.

01.Protected Sub cmbSetMarkup(ByVal sender As Object, _
02.                ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)
03.        Dim combo As RadComboBox = DirectCast(sender, RadComboBox)
04.        Dim NewValue As String = combo.SelectedValue
05.  
06.        For Each markupItem As GridItem In RadGrid1.MasterTableView.GetItems( _
07.            New GridItemType() {GridItemType.Item, GridItemType.AlternatingItem})
08.            Dim LblPercent As Label = CType(WHATHERE.FindControl("MyPercent"), Label)
09.            LblPercent.SelectedValue = NewValue
10.        Next
11.  
12.    End Sub

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 06 Sep 2010, 05:00 AM
Hello,

In this event handler you can access the grid dataitem using NamingContainer property of RadComboBox and then access the Label using FindControl() method. Check out the following code below.

ASPX:
<telerik:GridTemplateColumn>
  <ItemTemplate>
    <telerik:RadComboBox ID="RadComboBox1" runat="server" AutoPostBack="true" DataSourceID="SqlDataSource1" DataTextField="FirstName" DataValueField="FirstName" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
    </telerik:RadComboBox>
  </ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn>
  <ItemTemplate>
      <asp:Label ID="MyPercent" runat="server" Text='<%#Eval("FirstName") %>'></asp:Label>
  </ItemTemplate>
</telerik:GridTemplateColumn>

VB.Net
Protected Sub RadComboBox1_SelectedIndexChanged(o As Object, e As RadComboBoxSelectedIndexChangedEventArgs)
    Dim combo As RadComboBox = DirectCast(o, RadComboBox)
    Dim NewValue As String = combo.SelectedValue
    Dim item As GridDataItem = DirectCast(combo.NamingContainer, GridDataItem)
    Dim LblPercent As Label = DirectCast(item.FindControl("MyPercent"), Label)
    LblPercent.Text = NewValue
End Sub

Thanks,
Princy.
0
El
Top achievements
Rank 1
answered on 06 Sep 2010, 10:47 AM

Thanks princy. I will try that and get back to you. By the way i solved it in a bit different way:

1.Dim combo As RadComboBox = DirectCast(sender, RadComboBox)
2.Dim NewValue As String = combo.SelectedValue
3.Dim row As GridItem = DirectCast(DirectCast(sender, Control).Parent.Parent, GridItem)
4.CType(row.FindControl("LblPercentage"), Label).Text = NewValue

Do you think it's right? Maybe your way is more efficient? Thanks again

Tags
Grid
Asked by
El
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
El
Top achievements
Rank 1
Share this question
or