2011-01-08 150 views
0

當我點擊在gridview的項目模板內的文本框,然後onclick事件應該觸發,然後調用javascript函數,但我的問題是沒有項目模板的文本框中的onclick事件選項 plz hel我。如何調用javascript函數

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView2_RowCommand" 
       Width="100%" GridLines="None" 
       style="font-family: Tahoma; font-size: xx-small" Font-Names="Tahoma" 
       Font-Size="XX-Small"> 
       <Columns>  
        <asp:BoundField HeaderText="Status" DataField="Status" HeaderStyle-HorizontalAlign="Left" 
         ItemStyle-HorizontalAlign="Left"> 
         <HeaderStyle HorizontalAlign="Left"></HeaderStyle> 
         <ItemStyle HorizontalAlign="Left"></ItemStyle> 
        </asp:BoundField> 
        <asp:TemplateField HeaderText="Order" > 
        <ItemTemplate> 
        <asp:TextBox ID="TextBox1" Text='<%#Eval("ArticleOrder")%>' ReadOnly="true" 
          runat="server" Height="18px" Width="16px" onclick="hello();" > 
          </asp:TextBox> 
        </ItemTemplate>       
         <HeaderStyle HorizontalAlign="Left" /> 
        </asp:TemplateField> 
        <%--<asp:BoundField HeaderText="Order" DataField="ArticleOrder" HeaderStyle-HorizontalAlign="Center" 
         ItemStyle-HorizontalAlign="Center"> 
         <HeaderStyle HorizontalAlign="Center"></HeaderStyle> 
         <ItemStyle HorizontalAlign="Center"></ItemStyle> 
        </asp:BoundField>--%> 
        <asp:BoundField HeaderText="Title" DataField="ArticleTitle" HeaderStyle-HorizontalAlign="Left" 
         ItemStyle-HorizontalAlign="Left"> 
         <HeaderStyle HorizontalAlign="Left"></HeaderStyle> 
         <ItemStyle HorizontalAlign="Left"></ItemStyle> 
        </asp:BoundField> 
        <asp:TemplateField HeaderText="Edit" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"> 
         <ItemTemplate> 
          <asp:ImageButton ID="ImageButtonedt" runat="server" ImageUrl="~/images/newspaper_go.png" 
           CommandName="edt" CommandArgument='<%#Eval("ArticleID")%>' /> 
         </ItemTemplate> 
         <HeaderStyle HorizontalAlign="Center"></HeaderStyle> 
         <ItemStyle HorizontalAlign="Center"></ItemStyle> 
        </asp:TemplateField> 
        <asp:TemplateField HeaderText="Delete" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"> 
         <ItemTemplate> 
          <asp:ImageButton ID="ImageButtondel" runat="server" ImageUrl="~/images/newspaper_delete.png" 
           CommandName="del" OnClientClick='return confirm("Are you sure you want to delete ?");' CommandArgument='<%#Eval("ArticleID")%>' /> 
         </ItemTemplate> 
         <HeaderStyle HorizontalAlign="Center"></HeaderStyle> 
         <ItemStyle HorizontalAlign="Center"></ItemStyle> 
        </asp:TemplateField> 
       </Columns> 
      </asp:GridView> 

javascript函數:

hello() 
{ 
var divName = document.getElementById('div1'); 
     var divFade = document.getElementById('fade'); 
     divName.style.display = 'block'; 
     divFade.style.display = 'block'; 
} 
+0

嘗試發佈一些代碼。 – jmort253 2011-01-08 06:23:21

+0

PLZ爲我提供解決方案 – 2011-01-08 06:27:24

回答

1

廣東話從你告訴代碼..但如果多數民衆贊成你有什麼,你需要定義你的JavaScript函數的函數:

function hello() { 
    var divName = document.getElementById('div1');   
    var divFade = document.getElementById('fade');   
    divName.style.display = 'block';   
    divFade.style.display = 'block'; 
} 

也,'div1'和'fade'未在您的代碼中定義