如何在单击链接时执行Sql查询并在框架中显示结果 [英] How to execute Sql Query on clicking link and display result in frame

查看:55
本文介绍了如何在单击链接时执行Sql查询并在框架中显示结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我想在单击链接时执行Sql Query并将结果显示在该页面的框架中.我编写的代码如下.

AdminHomePage.aspx

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

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



PendingStudList.aspx



PendingStudList.aspx

<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.

推荐答案

hi,

希望您知道我们不能在iframe中显示数据,因为iframe的主要目的是在同一页中显示另一页输出.我的建议是使用DIV标签或
使用另一个页面,如showresult.aspx

然后将该页面用于您的iframe标记即可将其显示为
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
<iframe id="frame1" runat ="server" src="showresult.aspx"  >

 </iframe>


最后,用于在div中显示结果的C#代码是


finally the C# code for showing results in div is

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();


在这里,我使用Linq从数据库中检索数据,希望您知道linq.
如有任何疑问,请联系或联系.


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


这篇关于如何在单击链接时执行Sql查询并在框架中显示结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆