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;
}
}
}
}
|
Amit ChoudharyPosted Feb 10, 2011, 11:46 PM
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.
Becky BloomwoodPosted Feb 10, 2011, 9:03 AM
Amit ChoudharyPosted Feb 10, 2011, 5:36 AM
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 BloomwoodPosted Feb 10, 2011, 2:29 AM
Amit ChoudharyPosted Feb 10, 2011, 2:13 AM
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.