Click here to Skip to main content
15,905,322 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello,

I am using the following code below, which aims to open a new window whenever the user clicks on column Name rows in the gridview. However, I can not get the code to work and on the client-side, the click functionality is inactive.

JavaScript
<script type="text/javascript">

    function popItUp(querystring) {
        window.open('About.aspx' + querystring);
    }
</script>


ASP.NET
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="False"
       DataSourceID="SqlDataSource2"  OnRowDataBound="gv_RowDataBound">
       <Columns>
           <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
           <asp:BoundField DataField="column1" HeaderText="column1"
               SortExpression="column1" />
           <asp:BoundField DataField="priceTalk" HeaderText="priceTalk"
               SortExpression="priceTalk" />
           <asp:BoundField DataField="Decimal_price" HeaderText="Decimal_price"
               SortExpression="Decimal_price" />
           <asp:BoundField DataField="Cover" HeaderText="Cover" SortExpression="Cover" />
           <asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
           <asp:BoundField DataField="UploadDate" HeaderText="UploadDate"
               SortExpression="UploadDate" />
       </Columns>
   </asp:GridView>


Updated working solution:
ASP.NET
<asp:TemplateField HeaderText="Deal_Name">
                           <ItemTemplate>
                           <a href="java<!-- no -->script:popup('About.aspx?id=<%#Eval("Deal_name")%>&designation=<%#Eval("Deal_name")%>&a=d')"><%#Eval("Deal_name")%></a>
                           </ItemTemplate>
                           </asp:TemplateField>


JavaScript
function popup(url) {

        popupWindow = window.open(url, 'popupWindow', 'heigh=700,width=900,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,direction=no,status=yes')
    }


Any help would be appreciated.
Many thanks for your time and help.
Posted
Updated 23-Dec-13 1:27am
v2

instead of using the on RowDataBound you could change the Bound field to a templated field like below.

XML
<asp:TemplateField HeaderText="Start Date" SortExpression="startdate">

<ItemTemplate>

<asp:hyperlink runat="server" id="HyperLink1" navigateurl="<%# "Events.aspx?myDate=" + Eval("startdate")%>" text="<%# Eval("startdate","{0:d}")%>" xmlns:asp="#unknown"></asp:hyperlink>

</ItemTemplate>

</asp:TemplateField>
 
Share this answer
 
Comments
miss786 20-Dec-13 11:21am    
Thank you so much for your response and your suggestion. I am sorry to sound ungrateful but I am unaware of "asp:TemplateField" and I am not sure how to integrate this function into the code behind.
Karthik_Mahalingam 20-Dec-13 11:29am    
try my solution.
bowlturner 20-Dec-13 11:32am    
That's just it, you wouldn't need to integrate with the code behind, the link and the pop-up can be done in the mark up.
miss786 23-Dec-13 7:29am    
Dear bowlturner, I manage to use your framework to solve my gridview pop issue. Thank you for your time and help. Happy Holidays!
bowlturner 26-Dec-13 8:54am    
Glad I could help! Happy Holidays to you too!
hi
use this line..


C#
e.Row.Attributes["ondblclick"] = string.Format("popItUp('{0}')", queryString);


add single quotes to the popItUp function parameter.
 
Share this answer
 
Comments
miss786 20-Dec-13 11:33am    
Hi, Thank you for time and suggestion. Sadly, i tired your suggestion and I still can not click on the gridview row.
Karthik_Mahalingam 20-Dec-13 11:37am    
what error u r getting
miss786 20-Dec-13 11:49am    
I am not getting any error, I cannnot click on the gridview rows to open new window pop-up. thank you for your help.
Karthik_Mahalingam 20-Dec-13 11:57am    
function popItUp(querystring) {
alert('About.aspx' + querystring);
window.open('About.aspx' + querystring);
}

check whether alert displays ???
miss786 20-Dec-13 12:16pm    
Thank you for your help. There seems to be issue with the javascript code and the alert function does not work. I shall try to debug this and get back to you. I really appreciate your help and time

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900