Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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.
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…
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.

770 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