Solved

Need help w/popup from GridView in ASP.Net 2.0

Posted on 2007-04-07
3
1,186 Views
Last Modified: 2013-11-07
I'm experienced in vb.net, but new to asp.net.  I'm trying to put together a webpage to run SQL '05 reports.  The page needs to be hosted in another existing web-app using the same style, or else I would just use the standard SQL '05 reports web-interface.  I'm trying to use a GridView listing report name, description, and a "Run" button to launch another page that hosts the ReportViewer control to display the report.  I have an asp:Button in a template column in the GridView.  I'm using the following to register a javascript function in the page load event:

        Dim sb As New System.Text.StringBuilder
        sb.Append("<script language='javascript'>")
        sb.Append("window.open('ReportRun.aspx', 'RepDialog',")
        sb.Append("'width=800, height=600, menubar=no, resizable=yes');<")
        sb.Append("/script>")
        Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "repScript", sb.ToString)

In the RowDataBound even I have the following:

        If (e.Row.RowType = DataControlRowType.DataRow) Then
            Dim oBtn As Button = DirectCast(e.Row.Cells(0).FindControl("RepBtn"), Button)
            oBtn.Attributes.Add("onClientClick", "repScript")
        End If

The problem is that the popup is being shown when I click any button in that row of the GridView.  I'm also trying to figure out how to pass an item from the clicked row (the report name in this case) to the popup window page (which hosts a ReportViewer control, so I need to tell it which report to run).  I'm guessing I could just use a session item for this, but I need to know how to get the row that was clicked.  Any input?
0
Comment
Question by:feezymac
3 Comments
 
LVL 14

Accepted Solution

by:
steveberzins earned 500 total points
ID: 18870999
it looks like the popup is running any time the page is loaded.

I'd create the client script as a function
<script>
function RunReport(reportName) {
 window.open('reportrun.aspx?name=" + reportName.... blah blah);
}
</script>

then, in your code that creates the 'clicker event', change it to look something like
oBtn.Attributes.Add("onclientclick", "RunReport('" + HttpUtility.HtmlEncode(Eval("REPORT_NAME")) + "');")

this isn't debugged at all, just enough to show you where I'm goin'

Steve
0
 
LVL 13

Expert Comment

by:jeebukarthikeyan
ID: 18875396
hi,

this is the html code

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=XYKAPC_21;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa;Password=sa"
            ProviderName="System.Data.SqlClient" SelectCommand="SELECT *  FROM Employees"></asp:SqlDataSource>
   
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataMember="DefaultView"   DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound">
            <Columns>
                <asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" />
                <asp:BoundField DataField="FirstName" HeaderText="FirstName" />
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:Button ID="Button1" runat="server" Text="Button" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

create a script like this in the head part of the aspx
<script language='javascript'>
  function Open(var1)
  {
  alert(var1);
        window.open('ReportRun.aspx', 'RepDialog','width=800, height=600, menubar=no, resizable=yes');
  }
        </script>

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Button btn = new Button();
            btn = (Button)e.Row.Cells[2].FindControl("Button1");

            btn.Attributes.Add("OnClick", "javascript:Open('" + e.Row.Cells[1].Text + "')");

        }

    }

b u d d h a

0
 

Author Comment

by:feezymac
ID: 18895128
I feel so dumb now, that seems so obvious :)  I'm not a big fan of web apps, so this project is a struggle for me, but that short snippet cleared up a few misconceptions I've had so far and really put me on the right track.  I was able to finish up the basic layout so I moved to a more involved UI, next I'll AJAX the edit pages :)  Thanks again.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now