0

when i click on the textbox which is inside the item template of gridview then onclick event should fire and then call the javascript function but my problem is that there no onclick event option in item template's textbox plz hel p me.

<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 function:

hello()
{
var divName = document.getElementById('div1');
        var divFade = document.getElementById('fade');
        divName.style.display = 'block';
        divFade.style.display = 'block';
}  
4
  • 1
    @Manu - In order for someone to provide you a solution, you must first clearly and concisely describe what it is that you are trying to accomplish, as well as what you have tried. Commented Jan 8, 2011 at 6:28
  • sir i have gridview which contain 1 column of textbox.i want that when i running this page,and i click on the textbox then javascript function should call. so pls tell me how this will happen Commented Jan 8, 2011 at 6:32
  • @Manu - Update your question with code.. as of right now the only advice is write a javascript function! ? Beyond that we have no idea if you have one or not, or where the problem lies.. Commented Jan 8, 2011 at 6:34
  • I am not even going to justify putting this as an answer: From the sound if it you simply need to add an onclick to your element: <div onclick="YourJavaScriptFunctionHere();">Text Here</div> Commented Jan 8, 2011 at 6:36

1 Answer 1

1

Cant tell from you code.. but if thats exactly what you have you need to define your javascript function as a function:

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

also, 'div1' and 'fade' are not defined in your code

Sign up to request clarification or add additional context in comments.

2 Comments

Not really an answer - I understand what you're trying to demonstrate, but this would have been better as a comment.
I know.. I posted a few links for generic asp.net and javascript info.. Then immediatly edited it to just say the FAQ... Cleared that and redid now that we had 'some' code.. although as i pointed out div1 and fade are not valid in the gridview code.. so the script will (well.. may) fail either way

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.