Here is the whole code. I hope this helps.
Thanks,
dave
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.Data.OleDb;
namespace Type3CTracking
{
/// <summary>
/// Summary description for MRDetailsForm.
/// </summary>
public class MRDetailsForm : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label
mrLabel;
protected System.Web.UI.WebControls.Panel
Panel1;
protected
System.Web.UI.WebControls.TextBox mrText;
protected DataGrid workorderGrid = new
DataGrid();
protected System.Web.UI.WebControls.Label
workorderLabel;
protected
System.Web.UI.WebControls.PlaceHolder workorderHolder;
protected
System.Data.OleDb.OleDbDataAdapter oda;
private void Page_Load(object sender,
System.EventArgs e)
{
string mr = Request["MR"];
mrText.Text = mr;
if (!IsPostBack)
{
workorderHolder.Controls.Add(MakeWorkorderGrid());
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required
by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support -
do not modify
/// the contents of this method with the
code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new
System.EventHandler(this.Page_Load);
}
#endregion
public DataView CreateWorkorderDataSource()
{
string workorderConnect
= "Provider=\"MSDAORA.1\";User ID=dave;Data
Source=demo;Password=xxxxxxxx";
string workorderSelect = "Select
MR.Mrnum, Mrline.Mrlinenum, Workorder.Wonum,
Workorder.Description from" +
" MR, Mrline, Workorder
where MR.Mrnum = Mrline.Mrnum and Mrline.Wonum =
Workorder.Wonum" +
" and MR.Mrnum = " + "'" +
mrText.Text + "'";
oda = new OleDbDataAdapter
(workorderSelect, workorderConnect);
DataSet ds = new DataSet();
oda.Fill(ds, "workorder");
DataView workorder = ds.Tables
["workorder"].DefaultView;
return workorder;
}
public DataGrid MakeWorkorderGrid()
{
//make the DataGrid
workorderGrid.CellPadding = 2;
workorderGrid.CellSpacing = 0;
workorderGrid.Width = 700;
workorderGrid.BorderWidth = 1;
workorderGrid.BorderColor =
Color.Black;
//turn off autogeneratecolumns
feature
workorderGrid.AutoGenerateColumns
= false;
workorderGrid.ForeColor =
Color.Blue;
workorderGrid.Font.Size = 10;
workorderGrid.Font.Name = "Arial";
//sets the HeaderStyle
workorderGrid.HeaderStyle.BackColor = Color.Gold;
workorderGrid.HeaderStyle.ForeColor = Color.Blue;
workorderGrid.HeaderStyle.Font.Name = "Arial";
workorderGrid.HeaderStyle.Font.Size = 10;
workorderGrid.HeaderStyle.Font.Bold = true;
workorderGrid.HeaderStyle.HorizontalAlign =
HorizontalAlign.Center;
//sets alternating style
workorderGrid.AlternatingItemStyle.BackColor =
Color.Silver;
workorderGrid.AlternatingItemStyle.ForeColor =
Color.Black;
//sets the itemstyle
workorderGrid.ItemStyle.HorizontalAlign =
HorizontalAlign.Center;
//create the bound columns
BoundColumn Wonum = new BoundColumn
();
BoundColumn Mrlinenum = new
BoundColumn();
BoundColumn Desc = new BoundColumn
();
Wonum.HeaderText = "Wonum";
Wonum.DataField = "Wonum";
Mrlinenum.HeaderText = "MR Line
Number";
Mrlinenum.DataField = "Mrlinenum";
Desc.HeaderText = "Description";
Desc.DataField = "Description";
//add bound columns to datagrid
workorderGrid.Columns.AddAt(0,
Wonum);
workorderGrid.Columns
[0].ItemStyle.Width = 20;
workorderGrid.Columns.AddAt(1,
Mrlinenum);
workorderGrid.Columns
[1].ItemStyle.Width = 100;
workorderGrid.Columns.AddAt(2,
Desc);
//add a LinkButton column
ButtonColumn bc = new ButtonColumn
();
bc.ButtonType =
ButtonColumnType.LinkButton;
bc.Text = "Click to View workorder
details";
bc.CommandName = "Details";
workorderGrid.Columns.Add(bc);
workorderGrid.Columns
[3].HeaderText = "View Details";
//bind the DataDrid
workorderGrid.DataSource =
CreateWorkorderDataSource();
workorderGrid.DataBind();
return workorderGrid;
}
public void Grid_ItemCommand (Object
sender, DataGridCommandEventArgs e)
{
if ( e.CommandName == "Details" )
{
string targetPage
= "workorderDetailsForm.aspx?Workorder=" + e.Item.Cells
[0].Text;
Response.Redirect(
targetPage, true );
}
}
}
}
-----Original Message-----
HI Dave,
That will be a good idea
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
When I click on the LinkButton the DataGrid disappears and
the page does not move. It is the same page with the
DataGrid gone. Any thoughts? I can send all teh code on
Monday when I get back to work if that helps.
Thanks,
Dave
-----Original Message-----
Hi Dave,
Well that code should works fine, what show the address bar of the browser?
does it stay in the same page?
Maybe if you post an example with the result of targetPage and the current
request ( Page.Request.RawUrl ) we can see where is the problem.
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Dave bailey" <
[email protected]>
wrote
in message
When I execute the following code when using a dynamicall
created LinkButton in a dynamically created dataGrid, the
DataGrid disappears and the page I am trying to get to
does not load. Can anyone see what is wrong here?
protected void Grid_ItemCommand (Object sender,
DataGridCommandEventArgs e)
{
if ( e.CommandName == "Details" )
{
string targetPage
= "workorderDetailsForm.aspx?Workorder=" + e.Item.Cells
[0].Text;
Response.Redirect (
targetPage, true );
}
}
Thanks,
Dave
.
.