namespace HelpDeskApp.UserControls
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections;
/// <summary>
/// Summary description for Inbox.
/// </summary>
public class Inbox : System.Web.UI.UserControl
{
string connString =
"SERVER=JUNZHE;DATABASE=HelpDesk;trusted_connection=yes;UID=sa;PWD=sa";
protected System.Web.UI.HtmlControls.HtmlInputHidden hidvar;
protected System.Web.UI.WebControls.Image Image1;
protected System.Web.UI.WebControls.Button idBtnPostBack;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
string cmdText = "SELECT ImageId,RecDate,RecTime,Filename FROM
dtImageDetails";
public event GridItemClickEventHandler GridClick;
// An event is a special property bound to a delegate. A delegate is a
reference to a method signature.
// An instance of a delegate is actually a pointer to a function with
a well-known signature.
// The .NET Framework
// provides a general-purpose delegate for event handlers—the
EventHandler class.
// let's define a custom delegate and a custom event data structure.
public delegate void GridItemClickEventHandler(object sender,
DataGridCommandEventArgs e);
/*private void Page_Init(object sender, System.EventArgs e)
{
DataTable data = ExecuteQuery(cmdText, connString);
DataGrid1.DataSource = data;
DataGrid1.DataBind();
}
*/
private void Page_Load(object sender, System.EventArgs e)
{
hidvar.Attributes.Add("onpropertychange",
Page.GetPostBackEventReference(idBtnPostBack));
// wire the item data bound and button events
// this.DataGrid1.ItemDataBound +=
// new DataGridItemEventHandler(this.DataGrid1_ItemDataBound);
// Run the query and get some data to display
// Bind the data to the grid
DataTable data = ExecuteQuery(cmdText, connString);
DataGrid1.DataSource = data;
DataGrid1.DataBind();
// Put user code to initialize the page here
}
DataTable ExecuteQuery(string cmdText, string connString)
{
SqlDataAdapter adapter = new SqlDataAdapter(cmdText, connString);
DataTable data = new DataTable();
adapter.Fill(data);
return data;
}
private void idBtnPostBack_Click(object sender, System.EventArgs e)
{
Image1.Visible = true;
Image1.ImageUrl = "C:\\Documents and
Settings\\Ecompex\\Desktop\\imgout.jpg";
}
#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.idBtnPostBack.Click += new
System.EventHandler(this.idBtnPostBack_Click);
this.DataGrid1.ItemCreated += new
System.Web.UI.WebControls.DataGridItemEventHandler(this.itemcreated_hand
ler);
this.DataGrid1.ItemCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.ItemCommand);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void itemcreated_handler(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
TableCell dischargeCell = e.Item.Cells[2];
dischargeCell.Attributes["onmouseover"]="javascript:showImage();";
}
private void ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if (GridClick != null)
GridClick(this, e);
}
}
}
above is the code of the user control that contains the datagrid
DataGrid1,which has a button column with linkbuttons,i gave the command
name as select,what seems to happen is that when I click on the button
so as to fire itemcommand event the postback to the server seems to
suppress it,if i put datagrid databinding in !postback the datagrid will
not diplay,if i can fire itemcommand i have an event handler which gets
invoked and puts a new tab in the menu by doing arraylist.add and a new
different user control being loaded,I dont need the grid once the button
is clicked in the grid.