在gridview中配置选择链接 [英] Configuring a select link in a gridview

查看:66
本文介绍了在gridview中配置选择链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我能够在下一页上记录数据,这是有效的。我现在唯一想弄清楚的是如何在我的页面的aspx contentplaceholder1中显示数据。我正在使用母版页,数据显示在我的下一页的MasterPage和contentplaceholder之外。我不介意显示的格式。



页面背后的代码SearchGen.aspx.cs如下:



Hi There,

I am able to record the data on the next page, that is working. The only thing I am trying to figure out now is how to display the data within the aspx contentplaceholder1 of my page. I am using a masterpage and the data is being displayed outside the MasterPage and contentplaceholder of my next page. I do not mind the format shown.

The code behind the page, SearchGen.aspx.cs is as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
 
public partial class Members_SearchGen : System.Web.UI.Page
{
 
 
    protected void Page_Load(object sender, EventArgs e)
    {
    }
     protected void Button2_Click(object sender, EventArgs e)
    {
        if (GridView.SelectedRow != null)
        {
            GridViewRow selectedRow = GridView.SelectedRow;
 
            Session["FamilyName"] = selectedRow.Cells[1].Text;
            Session["FirstName"] = selectedRow.Cells[2].Text;
            Session["MiddleName1"] = selectedRow.Cells[3].Text;
            Session["MiddleName2"] = selectedRow.Cells[4].Text;
            Session["MiddleName3"] = selectedRow.Cells[5].Text;
            Session["Gender"] = selectedRow.Cells[6].Text;
            Session["DOB"] = selectedRow.Cells[7].Text;
            Session["COOB"] = selectedRow.Cells[8].Text;
            Session["SOB"] = selectedRow.Cells[9].Text;
            Session["COB"] = selectedRow.Cells[10].Text;
            Session["GenType"] = selectedRow.Cells[11].Text;
            Session["GenRank"] = selectedRow.Cells[12].Text;
            Session["GenTitles"] = selectedRow.Cells[13].Text;
            Session["GenTitles1"] = selectedRow.Cells[14].Text;
            Session["GenTitles2"] = selectedRow.Cells[15].Text;
            Session["DOD"] = selectedRow.Cells[16].Text;
            Session["COOD"] = selectedRow.Cells[17].Text;
            Session["SOD"] = selectedRow.Cells[18].Text;
            Session["COD"] = selectedRow.Cells[19].Text;
             
             
            Server.Transfer("SearchResults.aspx");
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Please select a row.')", true);
        }
    }
}







背后的代码下一页,SearchResults.aspx.cs如下:






The code behind the next page, SearchResults.aspx.cs is as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class Members_SearchResults : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
        if (this.Page.PreviousPage != null)
     {
         
 
         GridView GridView1 = (GridView)this.Page.PreviousPage.FindControl("GridView1");
         //GridViewRow selectedRow = GridView1.SelectedRow;
         Response.Write("Family: " + Session["FamilyName"].ToString() + "<br />");
         Response.Write("First: " + Session["FirstName"].ToString() + "<br />");
         Response.Write("Middle: " + Session["MiddleName1"].ToString() + "<br />");
         Response.Write("Middle: " + Session["MiddleName2"].ToString() + "<br />");
         Response.Write("Middle: " + Session["MiddleName3"].ToString() + "<br />");
         Response.Write("Gender: " + Session["Gender"].ToString() + "<br />");
         Response.Write("Birthday: " + Session["DOB"].ToString() + "<br />");
         Response.Write("Country: " + Session["COOB"].ToString() + "<br />");
         Response.Write("State: " + Session["SOB"].ToString() + "<br />");
         Response.Write("City: " + Session["COB"].ToString() + "<br />");
         Response.Write("Type: " + Session["GenType"].ToString() + "<br />");
         Response.Write("Rank: " + Session["GenRank"].ToString() + "<br />");
         Response.Write("Titles: " + Session["GenTitles"].ToString() + "<br />");
         Response.Write("Titles: " + Session["GenTitles1"].ToString() + "<br />");
         Response.Write("Titles: " + Session["GenTitles2"].ToString() + "<br />");
         Response.Write("Death: " + Session["DOD"].ToString() + "<br />");
         Response.Write("Country: " + Session["COOD"].ToString() + "<br />");
         Response.Write("State: " + Session["SOD"].ToString() + "<br />");
         Response.Write("City: " + Session["COD"].ToString() + "<br />");
    }
    }
}





以下是我的结果页面SearchResults上显示的内容。 aspx,见下图:



家庭:Whalen

第一名:Anthony

中间:斯图尔特

中间:

中间:

性别:男

生日:01/08/1962 / AD

国家:加拿大

州:新斯科舍省

城市:哈利法克斯

类型:

等级:

标题:

标题:

标题:

死亡:

国家:

状态:

城市:



如上所示,结果显示在母版页之外,我需要这将显示在folowowing主页的contentplaceholder1。我认为这是我想念的小事,我需要帮助。任何人都可以提供帮助,非常感谢并期待您的反馈。



谢谢



ASW



Here is what shows up on my result page, SearchResults.aspx, see below:

Family: Whalen
First: Anthony
Middle: Stewart
Middle:
Middle:
Gender: Male
Birthday: 01/08/1962/AD
Country: Canada
State: Nova Scotia
City: Halifax
Type:
Rank:
Titles:
Titles:
Titles:
Death:
Country:
State:
City:

As can been showned above the results are being shown outside the masterpage, I need this to show up with the contentplaceholder1 of the foloowing masterpage. I think it is something small that I am missing, I need help with this. Can anyone help, it would be much appreciated and look forward to your feed back.

Thanks

ASW

推荐答案

这是因为您正在使用Response.write,它在HTTP响应开始时写入值。



在这种情况下,您可以按照以下步骤操作。



1.在SearchResults.aspx.cs中在类级别声明受保护的字符串变量,如下所示



This happening because you are using Response.write which writes values at the start of HTTP response.

In this case you can follow below steps.

1. Declare protected string variable at class level in your SearchResults.aspx.cs like below

protected string OutPutString ="";





2。而不是使用Response.write,将您的字符串附加到OutPutString,如下所示



2. Instead of using Response.write, append your string to OutPutString like below

OutPutString += "Family: " + Session["FamilyName"].ToString() + "<br />";
 OutPutString +="First: " + Session["FirstName"].ToString() + "<br />";





3.在SearchResults.aspx中显示此字符串,您要使用ASP.NET内联表达式





3. In your SearchResults.aspx display this string where you want to using ASP.NET inline expressions

<%=OutPutString%>





希望这会有所帮助。



如果你有性能,还可以使用StringBuilder类附加字符串。



Hope this will help.

One more thing if you are performance concerned then you can use StringBuilder class for appending strings.


这篇关于在gridview中配置选择链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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