2015-08-26 46 views
0

我想訪問GridView的EditItemTemplate中的dropdownlist的id。我可以通過使用如何使用Javascript在EditItemTemplate中訪問dropdownlist的ID?

var ddlpresentday = document.getElementById("<%=((DropDownList)gridEarning.FooterRow. 
FindControl("ddlFPresentDay")).ClientID%>"); 

但在GridView處於編輯模式時遇到問題。 請幫助我。

GridView控件:

<asp:GridView ID="gridEarning" runat="server"> 
    <asp:TemplateField HeaderText="Present Days to be considerd on" 
    SortExpression="TAXABLE" meta:resourcekey="TemplateField19Resource"> 
    <EditItemTemplate> 
     <asp:DropDownList ID="ddlEditPresentDay" CssClass="ddlEditPresentDay" 
     runat="server" Enabled="false" Height="20px" Width="110px"  
     meta:resourcekey="ddlPresentDayResource2"> 
      <asp:ListItem Value="0" meta:resourcekey="ddlPreDaysListItemResource1">All Days</asp:ListItem> 
      <asp:ListItem Value="1" meta:resourcekey="ddlPreDaysListItemResource2">Business Days</asp:ListItem> 
      <asp:ListItem Value="2" meta:resourcekey="ddlPreDaysListItemResource3">Off Days and Holidays</asp:ListItem> 
     </asp:DropDownList> 
    </EditItemTemplate> 
    <FooterTemplate> 
     <asp:DropDownList ID="ddlFPresentDay" runat="server" Height="20px" Enabled="false" Width="110px" meta:resourcekey="ddlPresentDayResource2"> 
     <asp:ListItem Value="0" meta:resourcekey="ddlPreDaysListItemResource1">All Days</asp:ListItem> 
     <asp:ListItem Value="1" meta:resourcekey="ddlPreDaysListItemResource2">Business Days</asp:ListItem> 
     <asp:ListItem Value="2" meta:resourcekey="ddlPreDaysListItemResource3">Off Days and Holidays</asp:ListItem> 
     </asp:DropDownList> 
    </FooterTemplate> 
    <ItemTemplate> 
     <asp:Label ID="lblPresentDays" runat="server" Text="Helllo" 
     meta:resourcekey="lblPresentDaysResource1"></asp:Label> 
    </ItemTemplate> 
    </asp:TemplateField> 
</GridView> 
+0

也許廣告d Gridview的標記可以輕鬆地複製您的場景。 –

+0

添加你的gridview標記 – shreesha

+0

我已經添加了Gridview的標記,請審查它。 – hasanbaluch

回答

0

jQuery是在這種情況下,巨大的幫助(特別是CSS類選擇)。無論如何,即使沒有jQuery的你可以用唯一的ID定義自定義包裝元素,並依靠該元素上,而不是 - 樣:

<FooterTemplate> 
    <span id="gridFooter"> 
    <asp:DropDownList ... ></asp:DropDownList> 
    </span> 
</FooterTemplate> 

然後你就可以選擇它只是想:

var ddlpresentday = document.getElementById("gridFooter").firstElementChild; 

編輯

添加jQuery解決方案以及:

<FooterTemplate> 
    <asp:DropDownList CssClass="unique-footer-select" ... ></asp:DropDownList> 
</FooterTemplate> 

var ddlpresentday = $(".unique-footer-select"); 
+0

非常感謝恩德瑞傑Svedar爵士。有用。 :) – hasanbaluch

+0

再次感謝。 :) – hasanbaluch

相關問題