Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my application,I want to execute Sql Query on clicking link and display result in frame of that page.The code written by me as follow.

AdminHomePage.aspx
HTML
<a href="#" önclick="show('PendingStudList.aspx?AdminId')">Student Request</a>


PendingStudList.aspx
ASP.NET
<iframe id="Iframe1" frameborder="1" runat="server" scrolling="yes" title="Student Pending List">
        <%
            string FirstName, EndYear;
            SqlConnection objsqlconnection = new SqlConnection();
            objsqlconnection.ConnectionString = ("Data Source=.\\SQLEXPRESS;AttachDbFilename=G:\\Ujwala\\Project\\Student Community\\Student_Community\\Student_Community\\App_Data\\Stud_Community.mdf;Integrated Security=True;User Instance=True");
            SqlCommand objsqlcommand = objsqlconnection.CreateCommand();
            objsqlconnection.Open();
            string SelectStudInfo = "SELECT tblStudent_Registration.FirstName,tblStudent_Registration.EndYear FROM tblRequestApprove INNER JOIN tblStudent_Registration ON tblRequestApprove.StudId = tblStudent_Registration.StudId WHERE(tblRequestApprove.AdminId = 7)";
            objsqlcommand = objsqlconnection.CreateCommand();
            objsqlcommand.CommandText = SelectStudInfo;
            SqlDataAdapter sqldataadapter = new SqlDataAdapter(objsqlcommand);
            DataTable datatable = new DataTable();
            sqldataadapter.Fill(datatable);
            int i = 0;
            foreach (DataRow row in datatable.Rows)
            {
                FirstName = datatable.Rows[i]["FirstName"].ToString();
                EndYear = datatable.Rows[i]["EndYear"].ToString();
                Response.Write(FirstName);
                Response.Write(EndYear);
                i++;
            }
            objsqlconnection.Close();%>
           </iframe>

Clicking on Student Request link I want to display result in frame.
Please help me.
Thank You.
Posted
Updated 13-Sep-11 22:44pm
v2
Comments
Prerak Patel 14-Sep-11 4:44am    
Added code block.

1 solution

hi ,

I hope you know that we cannot show our data in iframes b'coz the main intend of iframe is to show another page output in same page.My suggestion is use DIV tag or
use another page like showresult.aspx

thn use that page into your iframe tag to display it like
HTML
<iframe id="frame1" runat ="server" src="showresult.aspx"  >

 </iframe>

finally the C# code for showing results in div is

C#
LocalDBDataClassesDataContext db = new LocalDBDataClassesDataContext();
        var g = from k in db.UserTabs
                where k.AdminID==7
                select k;
        StringBuilder sb = new StringBuilder("");
        foreach (var j in g)
        {
            sb.Append(" ID :  " + j.uname + "   ;   PWD  :    " + j.pwd + "<br />");
        }
        frame1.InnerHtml = sb.ToString();
        resdiv.InnerHtml = sb.ToString();

here I used Linq to retrieve data from database I hope you know linq.
If any doubts contact or rply.
 
Share this answer
 

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