Solved

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

Posted on 2007-04-07
3
1,208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Web page design problem 3 42
PowerShell: ForEach-Object Export to CSV 4 92
Need help for captcha 2 42
asp.net mvc5 6 34
Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

752 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