Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
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; }



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



thanks for your help.
Posted
Updated 23-Jan-12 1:44am
v2
Comments
Syed Salman Raza Zaidi 23-Jan-12 7:54am    
Can you share the pageload event of newproject.aspx?
m_safaaaa 23-Jan-12 9:08am    
protected void Page_Load(object sender, EventArgs e)
{

String ConnectionString = @"Data Source=SAFA-PC\SQLEXPRESS;Initial Catalog=ProjectMgnmt;Integrated Security=True";
SqlConnection SqlConn = new SqlConnection(ConnectionString);
SqlConn.Open();

txt_Compl.Attributes.Add("onkeypress", "javascript:return CheckNumericsInKeyPress(this,event);");

/***** show grid view Task*******/
if (!IsPostBack)
{
if (Session["ShareHolderDetails"] != null)
{
gvTaskDetails.Enabled = true;
ShowGrid();
}
}
else
{
gvTaskDetails.Enabled = false;

//Request.QueryString["param1"]);
txt_Proj.Text= HttpContext.Current.Request.QueryString["ID"];
int ID_Proj = int.Parse(txt_Proj.Text.ToString());

SqlDataAdapter daTask = new SqlDataAdapter("SELECT Name AS NAME,Description AS DESCRIPTION,AssignedTo AS ASSIGNEDTO,StartDate AS STARTDATE, EndDate AS ENDDATE FROM TASK WHERE Project='" + ID_Proj + "'",SqlConn);
DataTable dtable = new DataTable("ROW");
dtable.Columns.Add(new DataColumn("NAME"));
dtable.Columns.Add(new DataColumn("DESCRIPTION"));
dtable.Columns.Add(new DataColumn("ASSIGNEDTO"));
dtable.Columns.Add(new DataColumn("STARTDATE"));
dtable.Columns.Add(new DataColumn("ENDDATE"));
daTask.Fill(dtable);
gvTaskDetails.DataSource = dtable;
gvTaskDetails.DataBind();

Session["ShareHolderDetails"] = dtable;

}
SqlConn.Close();
}

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
 
Share this answer
 
Comments
Espen Harlinn 23-Jan-12 16:19pm    
5'ed! - Good answer for windows forms applications. OP forgot to tag his question with asp.net
problem is that NewProject.aspx doesn't show any information
Sergey Alexandrovich Kryukov 23-Jan-12 17:56pm    
Oops! My bad. I thought "parent form" could only mean System.Windows.Forms.
Thank you, Espen.
Stuff your data into a session variable, perhaps like this:

this.Session["UniqueKey"] = yourdata;


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


Best regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 23-Jan-12 17:57pm    
Sure, a 5.
--SA
Espen Harlinn 24-Jan-12 4:26am    
Thank you, Sergey :)

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