在另一页中显示结果可帮助我 [英] displaying result in another page assist me plz

查看:78
本文介绍了在另一页中显示结果可帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,如果我想知道这是一个简单还是愚蠢的问题,我会感到很抱歉
如何在另一页中显示结果

例如:

index.aspx将有一个文本框,我们可以在其中输入值并提交按钮
我们只要单击提交"按钮,它就会转到result.aspx页并显示结果.

我只想要我知道的有关SQL gridview和按钮事件触发的代码部分

所以请帮我解决这个问题,先谢谢


index.aspx(文本框和按钮)
result.aspx(在网格视图中显示)

在default.aspx中

dear friends i am sory if this is simple or silly question i wanted to know
how to display result in another page

for EX:

index.aspx will have textbox where we enter value and submit button
as soon we click on submit button it should goto result.aspx page and display result.

i want only that code part as i know about sql gridview and button event fire

so please help me with this problem thanks in advance


index.aspx (textbox and button)
result.aspx (result in grid view)

in default.aspx

<form id="form1"  runat="server">
 <div>
    <asp:Label ID="Label1" runat="server" Text="ENTER YOUR STUDENT ID: " 

        Font-Bold="True" Font-Names="Times New Roman" Font-Size="Small">
        
    <asp:TextBox ID="TextBox1" runat="server">
        
    <asp:Button ID="Button1" runat="server" Text="SUBMIT" 

       PostBackUrl="~/result.aspx"/><br /><br />
    <asp:Label ID="Label2" runat="server" Text="error label">
 </div>
</form>


在result.aspx


in result.aspx

<form id="form1" runat="server">
          <div>
          <tr>
  <td class="body" border="0" cellspacing="5" cellpadding="5">
  <br />
      <asp:Label ID="Label3" runat="server" Text="student id" Font-Size="Small">
  <br /><br />
      <asp:Label ID="Label4" runat="server" Text="student name" Font-Size="Small">
  <br /><br />
      <asp:Label ID="Label5" runat="server" Text="student class" Font-Size="Small">
  <br /><br />
      <asp:Label ID="Label6" runat="server" Text="student result" Font-Size="Small">
  <br /><br />
</td>
          </tr>
              <asp:GridView ID="GridView1" runat="server">
                        
          <br /><br />
              <asp:Label ID="Label2" runat="server" Text="error label">
          </div>
          </form>


在result.cs


in result.cs

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.PreviousPage != null)
        {
            TextBox txt1 = (TextBox)(Page.PreviousPage.FindControl("TextBox1.text"));
        }
        BindFiles();
    }
    private void BindFiles()
    {
        DataTable table = new DataTable();

        // get the connection
        SqlConnection _conn1 = new SqlConnection(@"conn string");
        {
            // write the sql statement to execute
            string sql = "select * from studsub where sid=TextBox1";
            
            // instantiate the command object to fire
            using (SqlCommand cmd = new SqlCommand(sql, _conn1))
            {
                // get the adapter object and attach the command object to it
                using (SqlDataAdapter ad = new SqlDataAdapter(cmd))
                {
                    // fire Fill method to fetch the data and fill into DataTable
                    ad.Fill(table);
                }
                // DataAdapter doesn't need open connection, it takes care of opening and closing the database connection
            }
        }
        GridView1.DataSource = table;
        GridView1.DataBind();
    }
}


请检查我的代码,并告诉我在哪里放置哪些代码以及必须放置哪些代码


please check my code and tell me where to put which code and what code has to put

推荐答案

您可以使用response.redirect转移到新页面并使用查询字符串,将结果值传递到下一页.
you can use response.redirect to transfer to new page & use a query string to pass resultant value to next page.




您可以使用Session将数据从index.aspx发送到result.aspx页面:

在index.aspx中,将结果保存在会话中:
Hi,

You can use Session to send data from index.aspx to result.aspx page :

In index.aspx save result in session:
Session["Result"] = txtResult.Text;



在result.aspx中从会话获取结果



In result.aspx get result from session

string Result = Session["Result"].ToString();


下面是从index.aspx传递查询字符串的示例

将以下代码放入index.aspx按钮单击事件中
Below is the sample to pass query string from index.aspx

put the below code in index.aspx button click event
Reponse.Redirect("result.aspx?Value=" + textbox.text)



从result.aspx页面加载事件中删除以下代码



remove your below code from result.aspx Page Load event

if(Page.PreviousPage != null)
{
TextBox txt1 = (TextBox)(Page.PreviousPage.FindControl("TextBox1"));
}




在result.aspx页面加载事件中使用我的以下代码






use my below code in result.aspx Page Load event



if (Request.QueryString.Get("Value") != null)
       string strValue = (Request.QueryString.Get("Value"))


这篇关于在另一页中显示结果可帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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