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:
C#
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;
namespaceStarTrack
{
publicpartialclassContractManagement :
System.Web.UI.Page
{
private vrm_database vrmdb
= new vrm_database();
private String
viewStateGVName = "gvContract";
privateconstint
GVContractID = 4;//columns to reference//set the index for the columns of the gridview in the aspx that required formatting of
text
privateconstint
GVCHKBOX = 0;
privateconstint
GVEDITBTN = 1;
privateconstint
GVVENDORBRN = 2;
privateconstint
GVMATERIALGRP = 4;
privateconstint
GVINSAP = 8;
privateconstint
GVSTARHUBCONTACTPERSON = 9;
privateconstint
GVDELETEFLAG = 16;
privateconstint
GVBLOCKED = 17;
//set the const for the ID of the GV Checkbox column
privateconststring GVCHECKBOXCOLID = "selected";
protectedvoidPage_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Set the
sortExpression
ViewState[this.ToString() + "_SortExpression"]
= "TemplateName";
ViewState[this.ToString() + "_SortDirection"] =
"ASC";
}
}
protectedvoidbtnClear_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 = "";
}
protectedvoidbtnSearch_Click(object sender, EventArgs e)
{
BindGrid(true);
gvContract.Visible = true;
}
protectedvoidchkSelectAll_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
privatevoidBindGrid(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;
}
}
protectedvoidgvContract_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);
}
}
}
protectedvoidgvContract_Sorting(object sender, GridViewSortEventArgs e)
{
GetSortDirection(e.SortExpression);
BindGrid(false);
}
privatevoidGetSortDirection(string sColumn)
{
//set sort
direction to asc
string sSortDirection = "ASC";
string sSortExpression =
ViewState[this.ToString() +
"_SortExpression"] asstring;
if (sSortExpression != null)
{
//check same column is being sorted
if (sSortExpression == sColumn)
{
string sLastDirection = ViewState[this.ToString() +
"_SortDirection"] asstring;
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:
Know the answer? Post it. Somebody with the same question will find it here.
Amit ChoudharyRank #145 · 15.8K reputationPosted Feb 9, 2011, 9:13 PM EST
0
Hi friend,
you don't have post all your code every time you ask a question just be specific and give the specific region of the code. so that the helper can understand it clearly and quickly. What i understood with your problem is: You want a link in your first grid and then clicking on that link wanted to show the related data for that particular row in the second page. Here is the workaround for it: 1. Create a custom column in either you datasource or in gridview itself. For datasource you can simply add a new column iterate through all rows and fill the values in the column e.g., a link to the second page and the parameters in the url you want on the second page e.g, Contract ID For gridview approach you have to do the same bt in the Row_Created or Row_Bound event of gridview.
2. Use the params from the url in the second page. and fire the query or whatever source you have to get the data on the basis of the params. and bind your grid.
Becky Bloomwood110 reputationPosted Feb 9, 2011, 9:29 PM EST
0
Thanks. One of the column in the grid view is being converted to template and I bind it to the ContractID in the database.Is this the way to do it? cause the contract id is being shown. how do we make use of params in the url from the second page and bind to grid. Oh ya i am using 3-tier programming to do it out. Thanks!
0
Amit ChoudharyRank #145 · 15.8K reputationPosted Feb 10, 2011, 12:36 AM EST
0
Hi friend, just don't bind it with contract ID make it little more custom... you can use Hyperlink in that column and can create the Text='<%#Eval("ContractID")%>' NavigateLink='~\Search2.aspx?ContractId=<%#Eval("ContractID")%>' and you will have the dynamic url different for each row.
now on the second page you can use Request.QueryString["ContractId"] to fetch the value from URL in page_load event. and then from your Business logic call a function to load the data based on this ContractID.
Hope this make sense.
Please mark "Do you like this post" if it helps you.
Becky Bloomwood110 reputationPosted Feb 10, 2011, 4:03 AM EST
0
Okay but how do we declare it in the second page. And also, how do we declare the business logic for ir? Sorry i do not know how to do it cause I am still new to c#. Thanks!
0
Amit ChoudharyRank #145 · 15.8K reputationPosted Feb 10, 2011, 6:46 PM EST
0
you can create a helper or manager class to separate your business logic from presentation. Write all methods here which are used to interact with data e.g., creating connection firing query or Update operations. you can create your function let say public DataTable GetDetails(string ContratId) in the helper class. Create a connection to you db and fire a query to get the details of bases on the ContractId and fill the data in DataSet or Datatable what ever you like. and return it. Now at your presentation call the function and bind the grid with the returned Datatable. ' Thanks.
Please mark "Do you like this post" if it helps you.
Amit ChoudharyRank #145 · 15.8K reputationPosted Feb 9, 2011, 9:13 PM EST
you don't have post all your code every time you ask a question just be specific and give the specific region of the code. so that the helper can understand it clearly and quickly.
What i understood with your problem is: You want a link in your first grid and then clicking on that link wanted to show the related data for that particular row in the second page.
Here is the workaround for it:
1. Create a custom column in either you datasource or in gridview itself.
For datasource you can simply add a new column iterate through all rows and fill the values in the column e.g., a link to the second page and the parameters in the url you want on the second page e.g, Contract ID
For gridview approach you have to do the same bt in the Row_Created or Row_Bound event of gridview.
2. Use the params from the url in the second page. and fire the query or whatever source you have to get the data on the basis of the params. and bind your grid.
Hope you got idea from this.
Thanks.
Becky Bloomwood110 reputationPosted Feb 9, 2011, 9:29 PM EST
Amit ChoudharyRank #145 · 15.8K reputationPosted Feb 10, 2011, 12:36 AM EST
just don't bind it with contract ID make it little more custom...
you can use Hyperlink in that column and can create the Text='<%#Eval("ContractID")%>' NavigateLink='~\Search2.aspx?ContractId=<%#Eval("ContractID")%>'
and you will have the dynamic url different for each row.
now on the second page you can use Request.QueryString["ContractId"] to fetch the value from URL in page_load event.
and then from your Business logic call a function to load the data based on this ContractID.
Hope this make sense.
Please mark "Do you like this post" if it helps you.
Thanks.
Becky Bloomwood110 reputationPosted Feb 10, 2011, 4:03 AM EST
Amit ChoudharyRank #145 · 15.8K reputationPosted Feb 10, 2011, 6:46 PM EST
you can create your function let say public DataTable GetDetails(string ContratId) in the helper class. Create a connection to you db and fire a query to get the details of bases on the ContractId and fill the data in DataSet or Datatable what ever you like. and return it.
Now at your presentation call the function and bind the grid with the returned Datatable.
'
Thanks.
Please mark "Do you like this post" if it helps you.