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

RadGrid Finding Problem in Underlying Control

1 Answer 25 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Muhammad
Top achievements
Rank 1
Muhammad asked on 21 Aug 2012, 01:10 PM
Hi,

I am using radgrid and in itemtempalte I have a dropdownlist and a label control. OnItemDatabound event I am passing the ids of dropdownlist and a label control to a javascript function. The functions finds the client ids of the dropdownlist and a label control but when I use document.getElementbyId for label control it gives me null.

Any help would be really appreciated.

Thanks



function OnSelectedIndexChange(ddlTopic, lblTopic) {
 
       alert(ddlTopic);
       alert(lblTopic);
       var ddl = document.getElementById(ddlTopic);
       var lbl = document.getElementById(lblTopic); // The problem occurs here 
       alert(lbl);  
       ddl.style.display = "none";       
        
 
   }
 
 
 
 
<telerik:RadGrid ID="gvTopics" runat="server" Font-Names="Verdana" Font-Size="XX-Small"
                   Skin="Outlook" EnableEmbeddedSkins="true" GridLines="Vertical" AllowSorting="true"
                   AllowPaging="true" Width="99%" CellPadding="2" AutoGenerateColumns="False">
                   <MasterTableView CommandItemDisplay="Top">
                       <CommandItemSettings ShowAddNewRecordButton="false" />
                       <Columns>
<telerik:GridTemplateColumn SortExpression="Topic" HeaderText="Topic">
                               <ItemTemplate>
                                   <asp:LinkButton ID="lnkTopic" Text='<%# Bind("Topic") %>' runat="server"></asp:LinkButton>
                                   <telerik:RadToolTip ID="rttpTopics" Width="350" Height="100" HideEvent="ManualClose"
                                       TargetControlID="lnkTopic" RelativeTo="Element" Skin="Windows7" Position="TopRight"
                                       ManualClose="true" ShowEvent="OnClick" runat="server">
                                       <table width="100%">
                                           <tr>
                                               <td width="40%">
                                                   select topic :
                                               </td>
                                               <td>
                                                   <asp:DropDownList ID="ddlTopic" runat="server" Font-Names="Verdana" Font-Size="XX-Small"
                                                       ValidationGroup="selecttopic" AutoPostBack="false" />
                                                    <asp:RequiredFieldValidator ID="rfvTopic" runat="server" ErrorMessage="## please select a topic"
                                                       InitialValue="- please select -" ControlToValidate="ddlTopic" Font-Bold="True"
                                                       Font-Names="Arial" Font-Size="X-Small" SetFocusOnError="True" ValidationGroup="selecttopic" />
                                                   <telerik:RadTextBox ID="rtbTopicName" EmptyMessage="please enter topic name"
                                                       runat="server">
                                                   </telerik:RadTextBox>
                                                   <asp:Label ID="lblTopicName" Text="TopicName" Visible="false" runat="server"></asp:Label>
                                               </td>
                                           </tr>
                                           <tr>
                                               <td>
                                               </td>
                                               <td>
                                                   <asp:Button ID="btnSaveTopic" CommandArgument='<%# Container.DataItem("id")%>' ValidationGroup="selecttopic"
                                                       CausesValidation="true" OnClick="btnSaveTopic_Click" Text="Save" runat="server" />
                                               </td>
                                           </tr>
                                       </table>
                                   </telerik:RadToolTip>
                               </ItemTemplate>
                           </telerik:GridTemplateColumn>
</Columns>
                       <NoRecordsTemplate>
                           <asp:Label ID="Label5" runat="server" Text="no topics found"></asp:Label>
                       </NoRecordsTemplate>
                   </MasterTableView>
               </telerik:RadGrid>
 
 
 
Protected Sub gvTopics_OnItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles gvTopics.ItemDataBound
 
       If TypeOf (e.Item) Is GridDataItem Then
 
           Dim ddlTopic As DropDownList = e.Item.FindControl("ddlTopic")
           Dim lblTopicName As Label = e.Item.FindControl("lblTopicName")
           ddlTopic.Attributes.Add("onChange", "return OnSelectedIndexChange('" & ddlTopic.ClientID & "','" & lblTopicName.ClientID & "');")
 
   End Sub

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 Aug 2012, 04:47 AM
Hi Muhammad,

You got null for the Label in client side because you have set the Visible property of the Label to false.One suggestion is to set the Visible property to true and and make the Label 'display' to 'none' in the CSS.

ASPX:
<asp:Label ID="lblTopicName" CssClass="LabelDisplay" Text="TopicName" Visible="true" runat="server"></asp:Label>

CSS:
<style>
    .LabelDisplay
    {
        display:none;
    }
</style>

Thanks,
Shinu.
Tags
Grid
Asked by
Muhammad
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or