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

Access grid item client-side

1 Answer 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
François
Top achievements
Rank 1
François asked on 17 Jul 2008, 07:05 PM

Hello, 

I'm having a hard time trying to make this work.  I have a grid set up with a form template and what I'm trying to accomplish is that when the user clicks on 'lbtEchelle', I want to get the values of one dropdown and one radtextbox to set them as arguments for a radwindow.  So far, I always get an 'undefined' variable in javascript.  I've looked at the example posted here, tried it (it worked flawlessly) and even tried it's javascript in my project... same result.  I'm pretty sure it's a small detail I'm overlooking but I need help.  I'm still quite newbish...

Here's the relevant code.

  Private Sub rgridSimCours_ItemCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgridSimCours.ItemCreated  
 
  'Lors de la création des items, récupérer les clientID de rtxtEtbCode2 et cboCycle pour les ajouter dans le   
  'javascript pour pouvoir les accéder lors du onclientclick de lbtEchelle.  
  If (TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode) Then  
 
  Dim editFormItem As GridEditFormItem = CType(e.Item, GridEditFormItem)  
  Dim rtxt As RadTextBox = editFormItem.FindControl("rtxtEtbCode2")  
  Dim cbo As DropDownList = editFormItem.FindControl("cboCycles")  
 
  rgridSimCours.Controls.Add(New LiteralControl("<script type='text/javascript'>window['rtxt'] = '" & rtxt.ClientID & "';</script>"))  
 
  End If  
 
  End Sub  
 
 
 

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="sim_cours.aspx.vb" Inherits="Simulation._Default" %>  
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>  
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
 
<html xmlns="http://www.w3.org/1999/xhtml" >  
<head runat="server">  
    <title>Untitled Page</title>  
    <link href="style/grid_style.css" rel="stylesheet" type="text/css" />  
    <link href="style/style.css" rel="stylesheet" type="text/css" />  
    <script src="script/dialog.js" type="text/javascript"></script>  
    <script src="script/alert.js" type="text/javascript"></script>  
    <style type="text/css">  
        .style1  
        {  
            width: 92px;  
        }  
        .style2  
        {  
            width: 215px;  
        }  
        .style3  
        {  
            width: 37px;  
        }  
        </style>  
</head>  
<body>  
    <form id="form1" runat="server">  
        <asp:ScriptManager ID="sm" runat="server">  
        </asp:ScriptManager>  
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">  
            <script type="text/javascript">  
            function showetb()  
            {     
              var countryField = document.getElementById(window['rtxt']);  
              alert(window['rtxt']);  
                
              if(!countryField)  
              {  
                alert("no item in edit/insert mode available");  
                return;  
              }   
              else  
              {    
                alert("Title edited value is: " + countryField.value);  
              }    
                
            }  
            </script>  
        </telerik:RadCodeBlock>  
          
        <div style="margin:auto; width: 650px; text-align: left; margin-bottom:1.5em"><asp:Label ID="lblTitrePage" CssClass="txt_titre" runat="server" Text="Gestion des cours simulés"></asp:Label></div>  
        <telerik:RadAjaxPanel EnableAJAX="true" ID="RadAjaxPanel1" runat="server">  
              
        <div style="margin:auto; width: 650px; margin-bottom:1em">  
            <fieldset style="text-align: left">  
                <legend>Recherche</legend>  
                <table id="recherche">  
                    <tr>  
                        <td class="style1"><asp:Label ID="lblSigle" runat="server" Text="Sigle :"   
                                meta:resourcekey="lblSigleResource1"></asp:Label></td>  
                        <td class="style2">  
                            <telerik:RadTextBox ID="rtxtSigle" runat="server" Width="200px"   
                                InvalidStyleDuration="100" LabelCssClass=""   
                                meta:resourcekey="rtxtSigleResource1">  
                            </telerik:RadTextBox></td>  
                        <td align="right" class="style3"><asp:Label ID="lblTitre" runat="server"   
                                Text="Titre :" meta:resourcekey="lblTitreResource1"></asp:Label></td>  
                        <td align="right">  
                            <telerik:RadTextBox ID="rtxtTitre" runat="server" Width="250px"   
                                InvalidStyleDuration="100" LabelCssClass=""   
                                meta:resourcekey="rtxtTitreResource1">  
                            </telerik:RadTextBox></td>  
                    </tr>                      
                    <tr>  
                        <td class="style1">  
                            <asp:Label ID="lblEtbCode" runat="server" Text="Établissement :"   
                                meta:resourcekey="lblEtbCodeResource1"></asp:Label>  
                        </td>  
                        <td class="style2">  
                            <telerik:RadTextBox ID="rtxtEtbCode" runat="server" Width="200px"   
                                InvalidStyleDuration="100" LabelCssClass=""   
                                meta:resourcekey="rtxtEtbCodeResource1">  
                            </telerik:RadTextBox></td>  
                        <td colspan="2" align="right">  
                            <asp:Button CssClass="bouton" ID="btnSoumettre" runat="server" Text="Soumettre" CausesValidation="false"   
                                meta:resourcekey="btnSoumettreResource1" />  
                        </td>  
                    </tr>                      
                </table>  
            </fieldset>  
          
        </div>  
          
        <div style="text-align:center; margin:auto; width: 650px;">  
          
            <fieldset>  
                <legend>Résultats</legend><br />  
                    <telerik:RadGrid ID="rgridSimCours" runat="server"  
                        AutoGenerateColumns="False" GridLines="None" Skin="Web20"   
                        Width="600px" ShowStatusBar="True" OnNeedDataSource="rgridSimCours_NeedDataSource"  
                        BorderColor="#4796FF" BorderStyle="Solid" BorderWidth="1px"  AllowPaging="true"  
                        AllowSorting="True" meta:resourcekey="rgridSimCoursResource1">  
                        <ValidationSettings CommandsToValidate="Enregistrer" EnableValidation="False" />  
                        <PagerStyle NextPagesToolTip="Pages suivantes" NextPageToolTip="Page suivante"   
                            PagerTextFormat="Changer de page: {4} &amp;nbsp;Page {0} de {1}, résultats {2} à {3} sur {5}."   
                            PrevPagesToolTip="Pages précédentes" PrevPageToolTip="Page précédente" />  
                        <MasterTableView BorderStyle="None" CellPadding="0" CommandItemDisplay="Top"  
                            NoDetailRecordsText="" NoMasterRecordsText="Aucun enregistrement.">  
                            <RowIndicatorColumn Visible="false" >  
                                <HeaderStyle Width="20px" />  
                            </RowIndicatorColumn>  
                            <ExpandCollapseColumn Resizable="False" Visible="False">  
                                <HeaderStyle Width="20px" />  
                            </ExpandCollapseColumn>  
                            <Columns>  
                                <telerik:GridBoundColumn DataField="Sigle" HeaderText="Sigle" SortAscImageUrl="images/sortasc.gif" SortDescImageUrl="images/sortdesc.gif"   
                                    meta:resourcekey="GridBoundColumnResource1" UniqueName="Sigle">  
                                    <HeaderStyle BorderStyle="None" CssClass="grid_header" HorizontalAlign="Left" ForeColor="White"    
                                        VerticalAlign="Bottom" />  
                                    <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="115px" />  
                                </telerik:GridBoundColumn>  
                                <telerik:GridBoundColumn DataField="EtbCode" HeaderText="Établissement" SortAscImageUrl="images/sortasc.gif" SortDescImageUrl="images/sortdesc.gif"  
                                    meta:resourcekey="GridBoundColumnResource2" UniqueName="EtbCode">  
                                    <HeaderStyle CssClass="grid_header" HorizontalAlign="Left" ForeColor="White"   
                                        VerticalAlign="Bottom" />  
                                    <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="115px" />  
                                </telerik:GridBoundColumn>  
                                <telerik:GridBoundColumn DataField="Titre" HeaderText="Titre" SortAscImageUrl="images/sortasc.gif" SortDescImageUrl="images/sortdesc.gif"  
                                    meta:resourcekey="GridBoundColumnResource3" UniqueName="Titre">  
                                    <HeaderStyle CssClass="grid_header" HorizontalAlign="Left" ForeColor="White"   
                                        VerticalAlign="Bottom" />  
                                    <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="320px" />  
                                </telerik:GridBoundColumn>  
                                <telerik:GridBoundColumn HeaderText="GDA" SortExpression="CrsID" SortAscImageUrl="images/sortasc.gif" SortDescImageUrl="images/sortdesc.gif"   
                                    meta:resourcekey="GridBoundColumnResource4" UniqueName="IndGda">  
                                    <HeaderStyle CssClass="grid_header" HorizontalAlign="Center" ForeColor="White"    
                                        VerticalAlign="Bottom" />  
                                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Top" Width="50px" />  
                                </telerik:GridBoundColumn>  
                                <telerik:GridEditCommandColumn ButtonType="ImageButton"   
                                    EditImageUrl="images/modifier.png" HeaderText="Détail">  
                                    <HeaderStyle BorderStyle="None" CssClass="grid_header" HorizontalAlign="Center" />  
                                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Top" Width="50px" />  
                                </telerik:GridEditCommandColumn>  
                                <telerik:GridBoundColumn DataField="NbCredit" UniqueName="NbCredit" Visible="False"></telerik:GridBoundColumn>  
                                <telerik:GridBoundColumn DataField="CrsID" UniqueName="CrsID" Visible="False"></telerik:GridBoundColumn>  
                                <telerik:GridBoundColumn DataField="NatureCours" UniqueName="NatureCours" Visible="False"></telerik:GridBoundColumn>  
                                <telerik:GridBoundColumn DataField="EchId" UniqueName="EchId" Visible="False"></telerik:GridBoundColumn>  
                                <telerik:GridBoundColumn DataField="EchDescription" UniqueName="EchDescription" Visible="False"></telerik:GridBoundColumn>  
                                <telerik:GridBoundColumn DataField="DateCreation" UniqueName="DateCreation" Visible="False"></telerik:GridBoundColumn>  
                                <telerik:GridBoundColumn DataField="CycCode" UniqueName="CycCode" Visible="False"></telerik:GridBoundColumn>  
                            </Columns>  
                            <EditFormSettings EditFormType="Template">  
                                <EditColumn UniqueName="EditColumn">  
                                </EditColumn>  
                                <FormTemplate>  
                                    <table bgcolor="#D1D1D1" style="width:100%;">  
                                        <tr>  
                                            <td align="left">  
                                                Identificateur :</td>  
                                            <td align="left">  
                                                <telerik:RadTextBox ID="rtxtCrsId" runat="server" BorderStyle="Solid"   
                                                    BorderWidth="1px" MaxLength="6" ReadOnly="True" Width="75px">  
                                                </telerik:RadTextBox>  
                                            </td>  
                                            <td align="right" colspan="2">  
                                                <asp:ImageButton ID="ibtEnregistrer" runat="server" CommandName="Enregistrer"   
                                                    CssClass="png" ImageUrl="~/images/enregistrer.png"   
                                                    meta:resourcekey="ibtEnregistrerResource1" ToolTip="Enregistrer" />  
                                                &nbsp;&nbsp;&nbsp;  
                                                <asp:ImageButton ID="ibtAnnuler" runat="server" CausesValidation="False"   
                                                    CommandName="Cancel" CssClass="png" ImageUrl="~/images/annuler.png"   
                                                    meta:resourcekey="ibtAnnulerResource1" ToolTip="Annuler" />  
                                                &nbsp;&nbsp;&nbsp;  
                                                <asp:ImageButton ID="ibtSupprimer" runat="server" CausesValidation="False"   
                                                    CommandName="Supprimer" CssClass="png" ImageUrl="~/images/supprimer.png"   
                                                    meta:resourcekey="ibtSupprimerResource1" ToolTip="Supprimer" />  
                                            </td>  
                                        </tr>  
                                        <tr>  
                                            <td align="left">  
                                                Sigle :</td>  
                                            <td align="left" valign="top">  
                                                <telerik:RadTextBox ID="rtxtSigle2" MaxLength="11" runat="server">  
                                                </telerik:RadTextBox>  
                                                <asp:RequiredFieldValidator ID="rfvSigle" runat="server" ErrorMessage="*"   
                                                    ControlToValidate="rtxtSigle2"></asp:RequiredFieldValidator>  
                                            </td>  
                                            <td align="left" >  
                                                Établissement :</td>  
                                            <td align="left" valign="top">  
                                                <telerik:RadTextBox  ID="rtxtEtbCode2" MaxLength="6" runat="server">  
                                                </telerik:RadTextBox>  
                                                <asp:RequiredFieldValidator ID="rfvEtbCode" runat="server" ErrorMessage="*"   
                                                    ControlToValidate="rtxtEtbCode2"></asp:RequiredFieldValidator>  
                                            </td>  
                                        </tr>  
                                        <tr valign="top">  
                                            <td align="left" valign="middle">  
                                                Titre :</td>  
                                            <td align="left" colspan="3" valign="top">  
                                                <telerik:RadTextBox ID="rtxtTitre2" runat="server" MaxLength="125" Rows="1" Width="400px">  
                                                </telerik:RadTextBox>  
                                                <asp:RequiredFieldValidator ID="rfvTitre" runat="server" ErrorMessage="*"   
                                                    ControlToValidate="rtxtTitre2"></asp:RequiredFieldValidator>  
                                            </td>  
                                        </tr>  
                                        <tr>  
                                            <td align="left">  
                                                Nb crédit :</td>  
                                            <td align="left" valign="top">  
                                                <telerik:RadTextBox ID="rtxtNbCredit" MaxLength="3" runat="server" Width="25px">  
                                                </telerik:RadTextBox>  
                                                <asp:RequiredFieldValidator ID="rfvNbCredit" runat="server" ErrorMessage="*"   
                                                    ControlToValidate="rtxtNbCredit"></asp:RequiredFieldValidator>  
                                            </td>  
                                            <td align="left">  
                                                Nature du cours :</td>  
                                            <td align="left">  
                                                <asp:DropDownList ID="cboNaturecours" runat="server"   
                                                    meta:resourcekey="DropDownList1Resource1">  
                                                </asp:DropDownList>  
                                            </td>  
                                        </tr>  
                                        <tr>  
                                            <td align="left">  
                                                Cycle :</td>  
                                            <td align="left" valign="top" colspan="3">  
                                                <asp:DropDownList ID="cboCycles" runat="server"   
                                                    meta:resourcekey="DropDownList1Resource1">  
                                                </asp:DropDownList>  
                                            </td>  
                                        </tr>  
                                        <tr>  
                                            <td align="left">  
                                                Échelle de notation :</td>  
                                            <td align="left" colspan="2" valign="top">  
                                                <telerik:RadTextBox ID="rtxtEchelle" ReadOnly="true" runat="server"   
                                                    Width="250px">  
                                                </telerik:RadTextBox>  
                                                <asp:RequiredFieldValidator ID="rfvEchId" runat="server" ErrorMessage="*"   
                                                    ControlToValidate="rtxtEchId"></asp:RequiredFieldValidator>  
                                            </td>  
                                            <td align="left">  
                                                <asp:LinkButton ID="lbtEchelle" runat="server"   
                                                    onclientclick="showetb();return false;"  
                                                    meta:resourcekey="LinkButton1Resource1" CausesValidation="False"   
                                                    onclick="lbtEchelle_Click">Sélectionner</asp:LinkButton>  
                                                <telerik:RadTextBox ID="rtxtEchId" Runat="server" Visible="False" Width="10px">  
                                                </telerik:RadTextBox>  
                                            </td>  
                                        </tr>  
                                        <tr>  
                                            <td align="left">  
                                                Date de création :</td>  
                                            <td align="left" valign="top">  
                                                <telerik:RadTextBox ID="rtxtDateCreation" runat="server" Width="70px">  
                                                </telerik:RadTextBox>  
                                            </td>  
                                            <td align="right">  
                                                &nbsp;</td>  
                                            <td align="left">  
                                                <asp:LinkButton ID="lbtMigrer" runat="server"   
                                                    meta:resourcekey="LinkButton2Resource1" Visible="False">Migrer au GDA</asp:LinkButton>  
                                            </td>  
                                        </tr>  
                                    </table>  
                                </FormTemplate>  
                                <PopUpSettings ScrollBars="None" />  
                            </EditFormSettings>  
                            <ItemStyle BorderStyle="None" CssClass="grid_item" />  
                            <AlternatingItemStyle BorderStyle="None" CssClass="grid_item_alt" />  
                            <HeaderStyle BorderStyle="None" />  
                            <CommandItemTemplate>  
                                <table class="grid_command">  
                                    <tr>  
                                        <td>  
                                            <asp:LinkButton ID="lbtAjouter" runat="server" CommandName="Ajouter"   
                                                Font-Underline="False" ForeColor="White" meta:resourcekey="lbtAjouterResource1"><img   
                                                border="0" class="png" src="images/ajouter.png" />&nbsp;&nbsp;Ajouter un cours</asp:LinkButton>  
                                        </td>  
                                    </tr>  
                                </table>  
                            </CommandItemTemplate>  
                        </MasterTableView>  
                        <EditItemStyle BackColor="#9F9F9F" />  
                        <ItemStyle BorderStyle="None" />  
                          
                        <SelectedItemStyle BackColor="#9F9F9F" BorderStyle="None" />  
                        <SortingSettings SortedAscToolTip="Tri ascendant"   
                            SortedDescToolTip="Tri descendant" SortToolTip="Cliquez ici pour trier" />  
                        <StatusBarSettings ReadyText="Attente d'opération" LoadingText="Opération en cours <img src='images/chargement.gif' border='0' />"  />  
                    </telerik:RadGrid>  
                <br />  
 
            </fieldset>          
        </div>  
        </telerik:RadAjaxPanel>  
          
        <br />  
        <telerik:RadWindowManager ID="rwm" runat="server" Skin="Web20">  
            <Windows>  
                <telerik:RadWindow ID="Dialog_Echelle"   
                        Behaviors="Close"   
                        ReloadOnShow = "true"  
                        OnClientclose = "OnClientclose"  
                        Left="250px"  
                        Modal = "true"  
                        Runat="server"   
                        Width="270px"                           
                        Height="250px"   
                        Title="Échelle de notation"   
                        NavigateUrl="dialog_echelle_notation.aspx">  
                </telerik:RadWindow>  
            </Windows>  
        </telerik:RadWindowManager>  
 
          
    </form>  
</body>  
</html>  
 

1 Answer, 1 is accepted

Sort by
0
François
Top achievements
Rank 1
answered on 18 Jul 2008, 03:00 PM

Ok I've found a way to do this.  I've replaced the 'new literal' line with the following and it seems to work.

ScriptManager.RegisterStartupScript(Page, GetType(Page), "test""window['rtxt'] = '" & rtxt.ClientID & "';"True

Problem seems to be solved.

Tags
Grid
Asked by
François
Top achievements
Rank 1
Answers by
François
Top achievements
Rank 1
Share this question
or