Solved

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

Posted on 2007-04-07
3
1,179 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
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…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

762 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

7 Experts available now in Live!

Get 1:1 Help Now