6
Answers

Click on ID hyperlink and direct to another page to view records

Becky Bloomwood

Becky Bloomwood

14y
5.1k
1

Hi,

in my reqirement, I have 2 pages in which the first page is known as: Contract Management.aspx.

In Contract management.aspx, I have a search panel that allows user to input search criteria and click on the search btn. Once the search btn is activated, a grid view called gvContract will be populated with data. In the Contract ID, it contains a list of id that are hyperlinked.Example: 8.3.2.5,  8.3.2.6 -->Hyperlinked.

Once user clicks on the hyperlink, they will be naviagte to another page to view specific details tied to each individual contract id. This page is known as: ContractThreeGridView.aspx. In these page, it contains Critical terms grid view, uploaded documents grid view and checklist grid view. These 3 grid views allows user to insert,update or delete records.
This is my business logic for the gvContract:

 

protected void gvContract_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridView header = (GridView)sender;
GridViewRow gvr = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
TableCell tCell = new TableCell();
tCell.Text = "Contract Management";
tCell.ColumnSpan = 14;
tCell.HorizontalAlign = HorizontalAlign.Left;
tCell.CssClass = "trWithBorder";
gvr.Cells.Add(tCell);
// Add the Merged TableCell to the GridView Header









Table tbl = gvContract.Controls[0] as Table;
if (tbl != null)
{
tbl.Rows.AddAt(0, gvr);
}
}
if (e.Row.RowType.Equals(DataControlRowType.DataRow))
{
DataRowView objDRV = (DataRowView)e.Row.DataItem;
HyperLink objHlink = (HyperLink)e.Row.FindControl("hlContract");
string strPagePath = "";
 
 
 
 
strPagePath = "http://localhost:1973/VRM_WebSite/app/vrm/ContractThreeGridView.aspx?ContractId=" + objDRV["ContractId"].ToString();
 
objHlink.NavigateUrl = strPagePath;
objHlink.Target = "_self";
}

In my seond page, i have defined:

 

protected void Page_Load(object sender, EventArgs e)
{
//string strContractId = Request.QueryString["ContractId"].ToString();

//string cid = Convert.ToString(Request.QueryString["ContractId"]);

//if (cid != null)

//{

// Response.Write("Fetch Records on the basis of ContracID " + cid);

//}

 
 
if (!IsPostBack)
{
//Set the sortExpression

ViewState[this.ToString() + "_SortExpression1"] = "Terms";
ViewState[this.ToString() + "_SortDirection1"] = "ASC";
//Set the sortExpression

ViewState[this.ToString() + "_SortExpression2"] = "FileName";
ViewState[this.ToString() + "_SortDirection2"] = "ASC";
//Set the sortExpression

ViewState[this.ToString() + "_SortExpression3"] = "Item";
ViewState[this.ToString() + "_SortDirection3"] = "ASC";
 
 
 
//populate the criticalterms datatable

DataTable tmpdt = vrmdb.Get_CriticalTerms().Tables[0];
tmpdt.PrimaryKey = new DataColumn[] { tmpdt.Columns[0] };
ViewState[viewStateGVName] = tmpdt;
//populate the uploadeddocuments datatable

DataTable tmpdtt = vrmdb.Get_UploadedDocuments().Tables[0];
tmpdtt = new DataTable();
tmpdtt = vrmdb.Get_UploadedDocuments().Tables[0];
tmpdtt.PrimaryKey = new DataColumn[] { tmpdtt.Columns[0] };
ViewState[viewStateGVUDName] = tmpdtt;
//populate the uploadeddocuments datatable

DataTable tmpCdt = vrmdb.Get_Checklist().Tables[0];
tmpCdt = new DataTable();
tmpCdt = vrmdb.Get_Checklist().Tables[0];
tmpCdt.PrimaryKey = new DataColumn[] { tmpCdt.Columns[0] };
ViewState[viewStateGVCLName] = tmpCdt;
 
 
 
BindGrid();
BindGrid1();
BindGrid2();
string strContractId = Request.QueryString["ContractId"].ToString();  //This is one is to get the contract id parmater
 
}
}
When I perform an insert req for one of the grid view and click on the Add New link btn defined at the footer, there is an error indicating:
 

Server Error in '/VRM_WebSite' Application.

Object reference not set to an instance of an object.


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 83:                 BindGrid1();
Line 84:                 BindGrid2();
Line 85:                 string strContractId = Request.QueryString["ContractId"].ToString();
Line 86: 
Line 87: 

Source File: c:\Users\L31410\Desktop\Peggie\Peggie\Deployment Source\Phase 1\Deployment 25 Nov for StarHub\VS Projects Source\VRM_WebSite\app\vrm\ContractThreeGridView.aspx.cs    Line: 85

I am not sure of how to resolve it.Thanks!











































 
Answers (6)
0
Suthish Nair
NA 31.7k 4.6m 14y
If your query got resolved, then accept the post that helped you as Answer.
0
Suthish Nair
NA 31.7k 4.6m 14y
attach your both pages..
0
Madhu K
NA 2k 446k 14y
The name 'ContractId' does not exist in the current context

Clearly tells that ContractId isn't declared as string. and from your code I observed that you did not used the query string anywhere else. Anyhow just declare ContractId as string.


string ContractId = Request.QueryString["ContractId"].ToString();


0
Amit Choudhary
NA 27.7k 3m 14y
Hi becky,

Everything seems to be fine in Code ... Try Rebuild your solution to get the fresh assemblies of updated code.


0
Becky Bloomwood
NA 119 240.2k 14y

I added in he code thatyou gave me, but there is still error:

protected void Page_Load(object sender, EventArgs e)
{
//string strContractId = Request.QueryString["ContractId"].ToString();
//string cid = Convert.ToString(Request.QueryString["ContractId"]);
//if (cid != null)
//{
// Response.Write("Fetch Records on the basis of ContracID " + cid);
//}
if(Request.QueryString["ContractId"]!=null)
{
ContractId = Request.QueryString[
"ContractId"].ToString();
}



if (!IsPostBack)
{
//Set the sortExpression
ViewState[
this.ToString() + "_SortExpression1"] = "Terms";
ViewState[
this.ToString() + "_SortDirection1"] = "ASC";
//Set the sortExpression
ViewState[
this.ToString() + "_SortExpression2"] = "FileName";
ViewState[
this.ToString() + "_SortDirection2"] = "ASC";
//Set the sortExpression
ViewState[
this.ToString() + "_SortExpression3"] = "Item";
ViewState[
this.ToString() + "_SortDirection3"] = "ASC";



//populate the criticalterms datatable
DataTable tmpdt = vrmdb.Get_CriticalTerms().Tables[0];
//tmpdt = new DataTable();
tmpdt.PrimaryKey =
new DataColumn[] { tmpdt.Columns[0] };
ViewState[viewStateGVName] = tmpdt;

//populate the uploadeddocuments datatable
DataTable tmpdtt = vrmdb.Get_UploadedDocuments().Tables[0];
tmpdtt =
new DataTable();
tmpdtt = vrmdb.Get_UploadedDocuments().Tables[0];
tmpdtt.PrimaryKey =
new DataColumn[] { tmpdtt.Columns[0] };
ViewState[viewStateGVUDName] = tmpdtt;
//populate the uploadeddocuments datatable
DataTable tmpCdt = vrmdb.Get_Checklist().Tables[0];
tmpCdt =
new DataTable();
tmpCdt = vrmdb.Get_Checklist().Tables[0];
tmpCdt.PrimaryKey =
new DataColumn[] { tmpCdt.Columns[0] };
ViewState[viewStateGVCLName] = tmpCdt;



BindGrid();
BindGrid1();
BindGrid2();
//string strContractId = Request.QueryString["ContractId"].ToString();


}
}
This is the error:

Server Error in '/VRM_WebSite' Application.

Compilation Error


Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name 'ContractId' does not exist in the current context

Source Error:

Line 36:              if(Request.QueryString["ContractId"]!=null)
Line 37:                 {
Line 38:                     ContractId = Request.QueryString["ContractId"].ToString();
Line 39:                 }
Line 40: 

Source File: c:\Users\L31410\Desktop\Peggie\Peggie\Deployment Source\Phase 1\Deployment 25 Nov for StarHub\VS Projects Source\VRM_WebSite\app\vrm\ContractThreeGridView.aspx.cs    Line: 38




 




Version Information: Microsoft .NET Framework Version:2.0.50727.4952; ASP.NET Version:2.0.50727.4955
Thanks!
0
Madhu K
NA 2k 446k 14y
By using following code you can get rid of the error.
If(Request.QueryString["ContractId"]!=null)
{
strContractId = Request.QueryString["ContractId"].ToString();
}

Use the debugger place a breakpoint and check whether you are getting the value from
from the query string or not.