将信息从一个父表单转移到一个子表单 [英] transfer information from one parent form to a child form

查看:73
本文介绍了将信息从一个父表单转移到一个子表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.

我在页面viewProject.asp.x中有一个gridView"Gd_SearchResult",向我显示了表"PROJECT"的所有数据,

一旦我单击选定的一行,对应的表单NewProject.aspx将被打开.

这是对应的代码:

Hi.

I have one gridView "Gd_SearchResult" in a page viewProject.asp.x which show me all the data of table "PROJECT",

once i click on one selected row, the correspendant form NewProject.aspx will be opened.

this is the correspendant code:

string str = "SELECT IdProject,Name,Description,Category,CreatedBy,CreatedOn,Manager,StartDate,EndDate,Completion FROM PROJECT";
SqlDataAdapter daSearchFill = new SqlDataAdapter(str, SqlConn);
DataTable DtSearch = new DataTable();
daSearchFill.Fill(DtSearch);
Gd_SearchResult.DataSource = DtSearch.DefaultView;
Gd_SearchResult.DataBind();
foreach (GridViewRow Dgrid in Gd_SearchResult.Rows)
{
      TableCell tc = Dgrid.Cells[0];
      sProjid = tc.Text.ToString();
      HyperLink hl1 = new HyperLink();
      hl1 = (HyperLink)Dgrid.FindControl("HyperlinkProject");
      hl1.NavigateUrl = "~/NewProject.aspx?ID=" + sProjid;
               
      Dgrid.Cells[0].Visible = false;
}

Gd_SearchResult.Columns[0].Visible = false;
int Cnt = DtSearch.Rows.Count;
if (Cnt == 0) { Cnt_records.Text = "NO RECORDS FOUND"; } 
else { Cnt_records.Text = Cnt.ToString() + " Project(s)"; Gd_SearchResult.Visible = true; }




现在我的问题是NewProject.aspx没有显示任何信息.如何传输这些信息??






Now my problem is that NewProject.aspx doesn''t show any information. how can these information be transfered???



thanks for your help.

推荐答案

首先,很高兴了解表单之间没有父子关系.即使正式可以将属性继承的Control.Parent属性用于表单,它也已终止,因此在尝试将表单插入另一个表单时会抛出异常.您仍然可以通过将Form.TopLevel属性值分配为false来做到这一点,但是结果很丑陋:一种形式,其中所有非客户区域都在另一种形式内.这不是有用的技术.没有可以使用的情况.

在普通的System.Windows.Forms应用程序中,所有形式都是相同的,但是主要形式是由传递给Application.Run的参数定义的.另一方面,使用表单之间的另一种关系非常重要:所有者/所有者表单,请参见:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.ownedforms.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.owner.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.addownedform.aspx [ ^ ].

我了解您的问题只是术语,但这是您需要了解的内容.

现在,您要问的是有关表单协作的常见问题.最健壮的解决方案是在Form类中实现适当的接口,并传递接口引用而不是对Form的整个实例"的引用.请查看我过去的解决方案以获取更多详细信息:如何以两种形式在列表框之间复制所有项目 [
First of all, it''s good to understand that there is no functional relationship parent-child between forms. Even though formally one can use the property inherited Control.Parent property for a form, it is done defunct, so an exception will be thrown on attempt to insert on form into another. You still can do it by assigning Form.TopLevel property value to false, but the result is ugly: one form with all non-client area inside another one. This is not a useful technique. There are no situation where it can be used.

In a normal System.Windows.Forms application all forms are equal, but the main form, which is defined by the parameter passed to Application.Run. From the other hand, it is very important to use another relationship between the form: owner/owned form, please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.ownedforms.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.owner.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.addownedform.aspx[^].

I understand that the problem of your question is just terminology, but this is something you need to understand.

Now, what you are asking about, is the popular question about form collaboration. The most robust solution is implementation of an appropriate interface in form class and passing the interface reference instead of reference to a "whole instance" of a Form. Please see my past solution for more detail: How to copy all the items between listboxes in two forms[^].

—SA


将您的数据填充到会话变量中,也许像这样:

Stuff your data into a session variable, perhaps like this:

this.Session["UniqueKey"] = yourdata;



这是您可能会发现有趣的文章
管理ASP.NET会话变量使用外观设计模式 [ ^ ]


最好的问候
Espen Harlinn



Here is an article you might find interesting Manage ASP.NET Session Variables using the Facade Design Pattern[^]


Best regards
Espen Harlinn


这篇关于将信息从一个父表单转移到一个子表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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