Becky Bloomwood

Becky Bloomwood

  • NA
  • 119
  • 285.5k

Click on the ContractID(hyperlink) after search and view records tied to it by click on it

Feb 10 2011 12:04 AM

Hi, currently I am doing a web application such that after user search for all the contracts,the contract id is a hyperlink in which user can click on it to view the results tied to it. There is 2 pages. One is for the search page and after searching results is populated below. The contract id in the grid view is a hyperlink so that when user clicks on it, they will go to another page and view the specific records tied to it. How shld I do this as I am creating this web application in 3-tier formatting.
This is the search.aspx:
 

using
System;
using
System.Collections.Generic;
using
System.Data;
using
System.Data.SqlTypes;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
com.vrm.database;
using
com.vrm.com;
namespace
StarTrack
{
public partial class ContractManagement : System.Web.UI.Page
{
private vrm_database vrmdb = new vrm_database();
private String viewStateGVName = "gvContract";
private const int GVContractID = 4;//columns to reference
//set the index for the columns of the gridview in the aspx that required formatting of text
private const int GVCHKBOX = 0;
private const int GVEDITBTN = 1;
private const int GVVENDORBRN = 2;
private const int GVMATERIALGRP = 4;
private const int GVINSAP = 8;
private const int GVSTARHUBCONTACTPERSON = 9;
private const int GVDELETEFLAG = 16;
private const int GVBLOCKED = 17;
//set the const for the ID of the GV Checkbox column
private const string GVCHECKBOXCOLID = "selected";

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Set the sortExpression
ViewState[
this.ToString() + "_SortExpression"] = "TemplateName";
ViewState[
this.ToString() + "_SortDirection"] = "ASC";


}
}
protected void btnClear_Click(object sender, EventArgs e)
{
gvContract.Visible =
false;
tbSearchCID.Text =
"";
tbSearchCOwner.Text =
"";
tbSearchCSD.Text =
"";
tbSearchCED.Text =
"";
tbSearchVBRN.Text =
"";
tbSearchVName.Text =
"";
tbSearchVProd.Text =
"";
tbSearchRFPRef.Text =
"";
tbSearchRFPProjTitle.Text =
"";
SDL.Text =
"";

}
protected void btnSearch_Click(object sender, EventArgs e)
{
BindGrid(
true);
gvContract.Visible =
true;
}
protected void chkSelectAll_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk;
foreach (GridViewRow rowItem in gvContract.Rows)
{
chk = (
CheckBox)(rowItem.Cells[0].FindControl("selected"));
chk.Checked = ((
CheckBox)sender).Checked;
}
}
//Bind the GridView to with the Database returned records

private void BindGrid(bool Reload)
{
DataTable dtContract = null;
if (Reload)
//get from database and bind to GV
{
string startDate1 = "=";
if (SDL.SelectedValue == "Select One" || tbSearchCSD == null)
{
startDate1 =
"=";
}
else
{
startDate1 = SDL.SelectedValue;
}
SqlDateTime startDate = SqlDateTime.Null;
SqlDateTime endDate = SqlDateTime.Null;
dtContract = vrmdb.Get_ContractRecords(tbSearchCID.Text, tbSearchCOwner.Text, startDate, endDate, tbSearchVBRN.Text, tbSearchVName.Text, tbSearchVProd.Text, tbSearchRFPRef.Text, tbSearchRFPProjTitle.Text, SDL.Text).Tables[0];
ViewState[viewStateGVName] = dtContract;
}
else
{
//vrmdb.Get_TemplateRecords(tbSearchTName.Text)
//retrive the view state object data table from previous retrival
dtContract = ViewState[viewStateGVName]
as DataTable;
}
if (dtContract != null)
{
gvContract.Columns[GVCHKBOX].Visible =
true;
gvContract.DataSource = ViewState[viewStateGVName];
gvContract.AllowSorting =
true;
gvContract.DataBind();
}
else
{
dtContract.Rows.Add(dtContract.NewRow());
ViewState[viewStateGVName] = dtContract;
gvContract.AllowSorting =
false;
gvContract.DataSource = ViewState[viewStateGVName];
gvContract.DataBind();
//hide the checkbox and edit columns
gvContract.Columns[GVCHKBOX].Visible =
false;
gvContract.Columns[GVEDITBTN].Visible =
false;

int TotalColumns = gvContract.Rows[0].Cells.Count;
gvContract.Rows[0].Cells.Clear();
gvContract.Rows[0].Cells.Add(
new TableCell());
gvContract.Rows[0].Cells[0].ColumnSpan = TotalColumns;
gvContract.Rows[0].Cells[0].Text =
"No Record Found";
SearchBtn.Visible =
true;
}


}





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);
}
}

}
protected void gvContract_Sorting(object sender, GridViewSortEventArgs e)
{
GetSortDirection(e.SortExpression);
BindGrid(
false);
}
private void GetSortDirection(string sColumn)
{
//set sort direction to asc
string sSortDirection = "ASC";
string sSortExpression = ViewState[this.ToString() +
"_SortExpression"] as string;
if (sSortExpression != null)
{
//check same column is being sorted
if (sSortExpression == sColumn)
{
string sLastDirection = ViewState[this.ToString() +
"_SortDirection"] as string;
if ((sLastDirection != null) && (sLastDirection == "ASC"))
{
sSortDirection =
"DESC";
}
}
}
//save new values in view
ViewState[
this.ToString() + "_SortDirection"] = sSortDirection;
ViewState[
this.ToString() + "_SortExpression"] = sColumn;
}










}
}

This is the next page that will display the results tied to this particular ID:
 

using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
com.vrm.database;
using
System.Data;
using
com.vrm.com;
using
System.Collections.Specialized;
using
System.Text;
namespace
StarTrack
{
public partial class ContractThreeGridView : System.Web.UI.Page
{
private vrm_database vrmdb = new vrm_database();
private String viewStateGVName = "gvCriticalTerms";
private const int GVContractID = 10;//columns to reference

protected void Page_Load(object sender, EventArgs e)
{
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";
//populate the criticalterms datatable
DataTable tmpdt = vrmdb.Get_CriticalTerms().Tables[0];
//tmpdt.PrimaryKey = new DataColumn[] { tmpdt.Columns[0] };
ViewState[viewStateGVName] = tmpdt;


BindGrid();

}
}
private void BindGrid()
{
DataTable dtgvCriticalTerms = null;

//retrieve the ViewState object datatable
dtgvCriticalTerms = ViewState[viewStateGVName]
as DataTable;
dtgvCriticalTerms.DefaultView.Sort = ViewState[
this.ToString() +
"_SortExpression1"].ToString() + " " +
ViewState[
this.ToString() + "_SortDirection1"].ToString();

if (dtgvCriticalTerms != null)
{
if (dtgvCriticalTerms.Rows.Count > 0)
{
ViewState[viewStateGVName] = dtgvCriticalTerms;
gvCriticalTerms.DataSource = ViewState[viewStateGVName];
gvCriticalTerms.DataBind();
}
else
{
dtgvCriticalTerms.Rows.Add(dtgvCriticalTerms.NewRow());
ViewState[viewStateGVName] = dtgvCriticalTerms;
gvCriticalTerms.DataSource = ViewState[viewStateGVName];
gvCriticalTerms.DataBind();
int TotalColumns = gvCriticalTerms.Rows[0].Cells.Count;
gvCriticalTerms.Rows[0].Cells.Clear();
gvCriticalTerms.Rows[0].Cells.Add(
new TableCell());
gvCriticalTerms.Rows[0].Cells[0].ColumnSpan = TotalColumns;
gvCriticalTerms.Rows[0].Cells[0].Text =
"No Record Found";
}
}

}


protected void gvCriticalTerms_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gvCriticalTerms.EditIndex = -1;
BindGrid();
}
protected void gvCriticalTerms_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("AddNew"))
{
TextBox txtTermsID = (TextBox)gvCriticalTerms.FooterRow.FindControl("txtTermsID");
TextBox txtTerms = (TextBox)gvCriticalTerms.FooterRow.FindControl("txtTerms");
TextBox txtDefaultValue = (TextBox)gvCriticalTerms.FooterRow.FindControl("txtDefaultValue");
TextBox txtActualValue = (TextBox)gvCriticalTerms.FooterRow.FindControl("txtActualValue");
TextBox txtReasonForDeviation = (TextBox)gvCriticalTerms.FooterRow.FindControl("txtReasonForDeviation");
TextBox txtAlert = (TextBox)gvCriticalTerms.FooterRow.FindControl("txtAlert");
TextBox txtContractID = (TextBox)gvCriticalTerms.FooterRow.FindControl("txtContractID");


vrmdb.Insert_CriticalTermsRecords(txtTermsID.Text,txtTerms.Text, txtDefaultValue.Text, txtActualValue.Text, txtReasonForDeviation.Text, txtAlert.Text, txtContractID.Text);
BindGrid();
Response.Redirect(
"ContractThreeGridView.aspx");

}
}




protected void gvCriticalTerms_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
vrmdb.Delete_CriticalTermsRecords(gvCriticalTerms.DataKeys[e.RowIndex].Values[0].ToString());
BindGrid();
}
protected void gvCriticalTerms_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox txtTermsID = (TextBox)gvCriticalTerms.Rows[e.RowIndex].FindControl("txtTermsID");
TextBox txtTerms = (TextBox)gvCriticalTerms.Rows[e.RowIndex].FindControl("txtTerms");
TextBox txtDefaultValue = (TextBox)gvCriticalTerms.Rows[e.RowIndex].FindControl("txtDefaultValue");
TextBox txtActualValue = (TextBox)gvCriticalTerms.Rows[e.RowIndex].FindControl("txtActualValue");
TextBox txtReasonForDeviation = (TextBox)gvCriticalTerms.Rows[e.RowIndex].FindControl("txtReasonForDeviation");
TextBox txtAlerts = (TextBox)gvCriticalTerms.Rows[e.RowIndex].FindControl("txtAlerts");
//Console.WriteLine(txtTerms.Text);
//Console.WriteLine(txtDefaultValue.Text);
//Console.WriteLine(txtActualValue.Text);
//Console.WriteLine(txtReasonForDeviation.Text);
//Console.WriteLine(txtAlerts.Text);
vrmdb.Update_CriticalTermsRecords(txtTermsID.Text,txtTerms.Text, txtDefaultValue.Text, txtActualValue.Text, txtReasonForDeviation.Text, txtAlerts.Text);
gvCriticalTerms.EditIndex = -1;
BindGrid();
Response.Redirect(
"ContractThreeGridView.aspx");

}
protected void gvCriticalTerms_RowEditing(object sender, GridViewEditEventArgs e)
{
gvCriticalTerms.EditIndex = e.NewEditIndex;
BindGrid();
}
protected void gvCriticalTerms_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvCriticalTerms.PageIndex = e.NewPageIndex;
BindGrid();
}
protected void gvCriticalTerms_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 =
"Critical Terms";
tCell.ColumnSpan = 10;
tCell.HorizontalAlign =
HorizontalAlign.Left;
tCell.CssClass =
"trWithBorder";
gvr.Cells.Add(tCell);


// Add the Merged TableCell to the GridView Header
Table tbl = gvCriticalTerms.Controls[0] as Table;
if (tbl != null)
{
tbl.Rows.AddAt(0, gvr);
}
}

}
protected void chkSelectAll_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk;
foreach (GridViewRow rowItem in gvCriticalTerms.Rows)
{
chk = (
CheckBox)(rowItem.Cells[0].FindControl("selected"));
chk.Checked = ((
CheckBox)sender).Checked;
}
}

}
}
Thanks for ur help all these while;)

Answers (5)